-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[lld] Merge GOT entries for symbols #131630
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
69ee9db
[lld] Merge GOT entries for symbols that have been ICFed
pranavk 4c472d1
ICF conditional
pranavk b8ebd15
review
pranavk b4c15df
folded logic
pranavk b41cbf5
Revert "folded logic"
pranavk d63758d
test for preemptible & check sym types when adding gotEntries
pranavk c362247
formatting
pranavk c667ee7
address review comments
pranavk 8b11790
review: Update lld/ELF/ICF.cpp
pranavk 5a90073
review: address Reid's other review comments
pranavk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -665,13 +665,31 @@ GotSection::GotSection(Ctx &ctx) | |
| } | ||
|
|
||
| void GotSection::addConstant(const Relocation &r) { relocations.push_back(r); } | ||
| void GotSection::addEntry(const Symbol &sym) { | ||
| void GotSection::addEntry(const Symbol &sym, bool authEntry) { | ||
| assert(sym.auxIdx == ctx.symAux.size() - 1); | ||
| ctx.symAux.back().gotIdx = numEntries++; | ||
| } | ||
| auto *d = dyn_cast<Defined>(&sym); | ||
| std::optional<uint32_t> finalGotIdx; | ||
| if (d && d->isFoldable()) { | ||
| // Generate one GOT entry for all foldable symbols. This could be due to | ||
| // ICF where containing sections have now been folded into one, or aliases | ||
| // that all point to the same symbol. | ||
| auto [it, inserted] = gotEntries.insert(std::make_pair( | ||
| std::make_tuple(d->section, d->value, sym.type), numEntries)); | ||
| if (!inserted) { | ||
| finalGotIdx = it->getSecond(); | ||
| } | ||
| } | ||
|
|
||
| if (!finalGotIdx.has_value()) { | ||
|
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. we omit braces for single-line simple statements. the code style is concise. we don't add many blank lines. |
||
| finalGotIdx = numEntries++; | ||
| } | ||
|
|
||
| if (authEntry) { | ||
| authEntries.push_back( | ||
| {finalGotIdx.value() * ctx.arg.wordsize, sym.isFunc()}); | ||
| } | ||
|
|
||
| void GotSection::addAuthEntry(const Symbol &sym) { | ||
| authEntries.push_back({(numEntries - 1) * ctx.arg.wordsize, sym.isFunc()}); | ||
| ctx.symAux.back().gotIdx = finalGotIdx.value(); | ||
| } | ||
|
|
||
| bool GotSection::addTlsDescEntry(const Symbol &sym) { | ||
|
|
||
This file contains hidden or 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 hidden or 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,68 @@ | ||
| // REQUIRES: aarch64 | ||
|
|
||
| # RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t | ||
| # RUN: ld.lld %t -o %t2 --icf=all | ||
| # RUN: llvm-objdump --section-headers %t2 | FileCheck %s --check-prefix=EXE | ||
|
|
||
| # RUN: ld.lld -shared %t -o %t3 --icf=all | ||
| # RUN: llvm-objdump --section-headers %t3 | FileCheck %s --check-prefix=DSO | ||
|
|
||
| ## All .rodata.* sections should merge into a single GOT entry | ||
| # EXE: {{.*}}.got 00000008{{.*}} | ||
|
|
||
| ## When symbols are preemptible in DSO mode, GOT entries wouldn't be merged | ||
| # DSO: {{.*}}.got 00000020{{.*}} | ||
|
|
||
| .addrsig | ||
|
|
||
| callee: | ||
| ret | ||
|
|
||
| .section .rodata.dummy1,"a",@progbits | ||
| sym1: | ||
| .long 111 | ||
| .long 122 | ||
| .byte 123 | ||
|
|
||
| .section .rodata.dummy2,"a",@progbits | ||
| sym2: | ||
| .long 111 | ||
| .long 122 | ||
| sym3: | ||
| .byte 123 | ||
|
|
||
| .macro f, index | ||
|
|
||
| .section .text.f1_\index,"ax",@progbits | ||
| f1_\index: | ||
| adrp x0, :got:g\index | ||
| mov x1, #\index | ||
| b f2_\index | ||
|
|
||
| .section .text.f2_\index,"ax",@progbits | ||
| f2_\index: | ||
| ldr x0, [x0, :got_lo12:g\index] | ||
| b callee | ||
|
|
||
| .globl g\index | ||
| .section .rodata.g\index,"a",@progbits | ||
| g_\index: | ||
| .long 111 | ||
| .long 122 | ||
|
|
||
| g\index: | ||
| .byte 123 | ||
|
|
||
| .section .text._start,"ax",@progbits | ||
| bl f1_\index | ||
|
|
||
| .endm | ||
|
|
||
| .section .text._start,"ax",@progbits | ||
| .globl _start | ||
| _start: | ||
|
|
||
| f 0 | ||
| f 1 | ||
| f 2 | ||
| f 3 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.