-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[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
Changes from all commits
69ee9db
4c472d1
b8ebd15
b4c15df
b41cbf5
d63758d
c362247
c667ee7
8b11790
5a90073
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 |
---|---|---|
|
@@ -111,8 +111,7 @@ class GotSection final : public SyntheticSection { | |
void writeTo(uint8_t *buf) override; | ||
|
||
void addConstant(const Relocation &r); | ||
void addEntry(const Symbol &sym); | ||
void addAuthEntry(const Symbol &sym); | ||
void addEntry(const Symbol &sym, bool authEntry = false); | ||
bool addTlsDescEntry(const Symbol &sym); | ||
void addTlsDescAuthEntry(); | ||
bool addDynTlsEntry(const Symbol &sym); | ||
|
@@ -138,6 +137,14 @@ class GotSection final : public SyntheticSection { | |
bool isSymbolFunc; | ||
}; | ||
SmallVector<AuthEntryInfo, 0> authEntries; | ||
|
||
// Map of GOT entries keyed by section, offset, and type. The purpose is to | ||
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. How do you propose targets override this to require additional properties be the same? For CHERI targets (currently downstream, but eventually to be upstreamed) we would also need to ensure the symbol size was the same, since that determines the bounds for the GOT entry. 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. (along with additional complexity for handling "zero"-sized symbols to ensure that section start symbols get the bounds of the whole section, rather than be 0 bytes as they would otherwise be) 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. I imagine in that case the second element of this tuple would evolve into something more complex. Right now it's just the offset. For CHERI targets, it would include size and other things necessary -- first and third element would still be the same. 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. But how does that work when the type of the map needs to change? GotSection isn't templated on the target (and refactoring to do so would be a real pain I imagine). 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. I think we would be okay if you add another member to the tuple named |
||
// reuse GOT entries when multiple same-type, foldable symbols refer to the | ||
// image location. In general, this is a GOT-size optimization, but it is | ||
// also required for some cases involving multi-instruction GOT access | ||
// patterns and ICF. | ||
llvm::DenseMap<std::tuple<SectionBase *, uint64_t, unsigned char>, uint32_t> | ||
gotEntries; | ||
}; | ||
|
||
// .note.GNU-stack section. | ||
|
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 |
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.
we omit braces for single-line simple statements. the code style is concise. we don't add many blank lines.