-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELF] Do not ICF two sections with different output sections (by SECT…
…IONS commands) Fixes PR39418. Complements D47241 (the non-linker-script case). processSectionCommands() assigns input sections to output sections. ICF is called before it, so .text.foo and .text.bar may be folded even if their output sections are made different by SECTIONS commands. ``` markLive<ELFT>() doIcf<ELFT>() // During ICF, we don't know the output sections writeResult() combineEhSections<ELFT>() script->processSectionCommands() // InputSection -> OutputSection assignment ``` This patch splits processSectionCommands() into processSectionCommands() and processSymbolAssignments(), and moves processSectionCommands() before ICF: ``` markLive<ELFT>() combineEhSections<ELFT>() script->processSectionCommands() doIcf<ELFT>() // should remove folded input sections writeResult() script->processSymbolAssignments() ``` An alternative approach is to unfold a section `sec` in processSectionCommands() when we find `sec` and `sec->repl` belong to different output sections. I feel this patch is superior because this can fold more sections and the decouple of SectionCommand/SymbolAssignment gives flexibility: * An ExprValue can't be evaluated before its section is assigned to an output section -> we can delete getOutputSectionVA and simplify another place where we had to check if the output section is null. Moreover, a case in linkerscript/early-assign-symbol.s can be handled now. * processSectionCommands/processSymbolAssignments can be freely moved around. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D66717 llvm-svn: 370635
- Loading branch information
Showing
9 changed files
with
146 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# REQUIRES: x86 | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o | ||
# RUN: echo 'SECTIONS { .text : { *(.text*) } }' > %t1.script | ||
|
||
## Sections within the same output section can be freely folded. | ||
# RUN: ld.lld %t.o --script %t1.script --icf=all --print-icf-sections -o %t | FileCheck --check-prefix=ICF1 %s | ||
# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC1 %s --implicit-check-not=.text | ||
|
||
# ICF1: selected section {{.*}}.o:(.text.foo0) | ||
# ICF1-NEXT: removing identical section {{.*}}.o:(.text.foo1) | ||
# ICF1-NEXT: removing identical section {{.*}}.o:(.text.bar0) | ||
# ICF1-NEXT: removing identical section {{.*}}.o:(.text.bar1) | ||
|
||
# SEC1: .text PROGBITS 0000000000000000 001000 000001 | ||
|
||
## Sections with different output sections cannot be folded. Without the | ||
## linker script, .text.foo* and .text.bar* go to the same output section | ||
## .text and they will be folded. | ||
# RUN: echo 'SECTIONS { .text.foo : {*(.text.foo*)} .text.bar : {*(.text.bar*)} }' > %t2.script | ||
# RUN: ld.lld %t.o --script %t2.script --icf=all --print-icf-sections -o %t | FileCheck --check-prefix=ICF2 %s | ||
# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC2 %s | ||
|
||
# ICF2: selected section {{.*}}.o:(.text.foo0) | ||
# ICF2-NEXT: removing identical section {{.*}}.o:(.text.foo1) | ||
# ICF2-NEXT: selected section {{.*}}.o:(.text.bar0) | ||
# ICF2-NEXT: removing identical section {{.*}}.o:(.text.bar1) | ||
|
||
# SEC2: .text.foo PROGBITS 0000000000000000 001000 000001 | ||
# SEC2-NEXT: .text.bar PROGBITS 0000000000000001 001001 000001 | ||
|
||
## .text.bar* are orphans that get assigned to .text. | ||
# RUN: echo 'SECTIONS { .text.foo : {*(.text.foo*)} }' > %t3.script | ||
# RUN: ld.lld %t.o --script %t3.script --icf=all --print-icf-sections -o %t | FileCheck --check-prefix=ICF2 %s | ||
# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC3 %s | ||
|
||
# SEC3: .text.foo PROGBITS 0000000000000000 001000 000001 | ||
# SEC3-NEXT: .text PROGBITS 0000000000000004 001004 000001 | ||
|
||
.section .text.foo0,"ax" | ||
ret | ||
.section .text.foo1,"ax" | ||
ret | ||
.section .text.bar0,"ax" | ||
ret | ||
.section .text.bar1,"ax" | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters