-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLD][ELF] Don't spill to same memory region #129795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -450,3 +450,103 @@ SECTIONS { | |
|
||
# TO-DISCARD: error: section '.two_byte_section' cannot spill from/to /DISCARD/ | ||
# TO-DISCARD-WARN: warning: section '.two_byte_section' cannot spill from/to /DISCARD/ | ||
|
||
#--- same-mem-region.lds | ||
## Spills to the same memory region that overflowed do not consume address assignment passes. | ||
MEMORY { | ||
a : ORIGIN = 0, LENGTH = 0 | ||
b : ORIGIN = 0, LENGTH = 3 | ||
c : ORIGIN = 3, LENGTH = 3 | ||
d : ORIGIN = 6, LENGTH = 3 | ||
} | ||
SECTIONS { | ||
CLASS(class) { *(.one_byte_section .two_byte_section) } | ||
.a00 : { CLASS(class) } >a AT>c | ||
.a01 : { CLASS(class) } >a AT>d | ||
.a02 : { CLASS(class) } >a AT>d | ||
.a03 : { CLASS(class) } >a AT>d | ||
.a04 : { CLASS(class) } >a AT>d | ||
.a05 : { CLASS(class) } >a AT>d | ||
.a06 : { CLASS(class) } >a AT>d | ||
.a07 : { CLASS(class) } >a AT>d | ||
.a08 : { CLASS(class) } >a AT>d | ||
.a09 : { CLASS(class) } >a AT>d | ||
.a10 : { CLASS(class) } >a AT>d | ||
.a11 : { CLASS(class) } >a AT>d | ||
.a12 : { CLASS(class) } >a AT>d | ||
.a13 : { CLASS(class) } >a AT>d | ||
.a14 : { CLASS(class) } >a AT>d | ||
.a15 : { CLASS(class) } >a AT>d | ||
.a16 : { CLASS(class) } >a AT>d | ||
.a17 : { CLASS(class) } >a AT>d | ||
.a18 : { CLASS(class) } >a AT>d | ||
.a19 : { CLASS(class) } >a AT>d | ||
.a20 : { CLASS(class) } >a AT>d | ||
.a21 : { CLASS(class) } >a AT>d | ||
.a22 : { CLASS(class) } >a AT>d | ||
.a23 : { CLASS(class) } >a AT>d | ||
.a24 : { CLASS(class) } >a AT>d | ||
.a25 : { CLASS(class) } >a AT>d | ||
.a26 : { CLASS(class) } >a AT>d | ||
.a27 : { CLASS(class) } >a AT>d | ||
.a28 : { CLASS(class) } >a AT>d | ||
.a29 : { CLASS(class) } >a AT>d | ||
.a30 : { CLASS(class) } >a AT>d | ||
.b : { CLASS(class) } >b AT>d | ||
} | ||
|
||
# RUN: ld.lld -T same-mem-region.lds -o same-mem-region spill.o | ||
# RUN: llvm-readelf -S same-mem-region | FileCheck %s --check-prefix=SAME-MEM-REGION | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reasonable way to test the differences in mem region and lma region? For example an output section is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, and this uncovered a subtlety. We should only skip entries with the same mem region if it is currently overflowing; same with lma region. Added a test and fix. |
||
# SAME-MEM-REGION: Name Type Address Off Size | ||
# SAME-MEM-REGION: .b PROGBITS 0000000000000000 001000 000003 | ||
|
||
#--- same-lma-region.lds | ||
## Spills to the same load region that overflowed do not consume address assignment passes. | ||
MEMORY { | ||
a : ORIGIN = 0, LENGTH = 0 | ||
b : ORIGIN = 0, LENGTH = 3 | ||
c : ORIGIN = 3, LENGTH = 3 | ||
d : ORIGIN = 6, LENGTH = 3 | ||
} | ||
SECTIONS { | ||
CLASS(class) { *(.one_byte_section .two_byte_section) } | ||
.a00 : { CLASS(class) } >c AT>a | ||
.a01 : { CLASS(class) } >d AT>a | ||
.a02 : { CLASS(class) } >d AT>a | ||
.a03 : { CLASS(class) } >d AT>a | ||
.a04 : { CLASS(class) } >d AT>a | ||
.a05 : { CLASS(class) } >d AT>a | ||
.a06 : { CLASS(class) } >d AT>a | ||
.a07 : { CLASS(class) } >d AT>a | ||
.a08 : { CLASS(class) } >d AT>a | ||
.a09 : { CLASS(class) } >d AT>a | ||
.a10 : { CLASS(class) } >d AT>a | ||
.a11 : { CLASS(class) } >d AT>a | ||
.a12 : { CLASS(class) } >d AT>a | ||
.a13 : { CLASS(class) } >d AT>a | ||
.a14 : { CLASS(class) } >d AT>a | ||
.a15 : { CLASS(class) } >d AT>a | ||
.a16 : { CLASS(class) } >d AT>a | ||
.a17 : { CLASS(class) } >d AT>a | ||
.a18 : { CLASS(class) } >d AT>a | ||
.a19 : { CLASS(class) } >d AT>a | ||
.a20 : { CLASS(class) } >d AT>a | ||
.a21 : { CLASS(class) } >d AT>a | ||
.a22 : { CLASS(class) } >d AT>a | ||
.a23 : { CLASS(class) } >d AT>a | ||
.a24 : { CLASS(class) } >d AT>a | ||
.a25 : { CLASS(class) } >d AT>a | ||
.a26 : { CLASS(class) } >d AT>a | ||
.a27 : { CLASS(class) } >d AT>a | ||
.a28 : { CLASS(class) } >d AT>a | ||
.a29 : { CLASS(class) } >d AT>a | ||
.a30 : { CLASS(class) } >d AT>a | ||
.b : { CLASS(class) } >d AT>b | ||
} | ||
|
||
# RUN: ld.lld -T same-lma-region.lds -o same-lma-region spill.o | ||
# RUN: llvm-readelf -S same-lma-region | FileCheck %s --check-prefix=SAME-LMA-REGION | ||
|
||
# SAME-LMA-REGION: Name Type Address Off Size | ||
# SAME-LMA-REGION: .b PROGBITS 0000000000000006 001006 000003 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so I understand. These changes are not required for the fix, but they are no longer necessary because of the changes to
spillSections()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct. This was code added to prevent this roughly this issue, but it appears to have been neither necessary nor sufficient.
As-is, this shouldn't create any behavioral differences, since spilling to a different memory region implies spilling to a different output section. But this also does hint towards a future way to express very detailed address constraints within an output section, which is something that has been on my radar for a while.
For example:
The first pass would assign everything to the first CLASS reference, but this would cause dot to move backwards. The spiller could detect the amount dot moved backwards and spill that much from a preceding class, just like it does for memory region overages. The difference is that later references within the same output section may help to resolve this.
I don't think there's actually anything you could achieve with this that you couldn't achieve by splitting everything into fine-grained output sections, but to me it would just help to make spilling feel more orthogonal with linker features like dot assignment. Broadly, I'd tend to think that any address assignment failure should trigger spilling if that might have a chance to prevent the issue on the next pass.