Skip to content

[ELF][Mips] Fix addend for preemptible static TLS #150729

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

Open
wants to merge 4 commits into
base: users/jrtc27/spr/main.elfmips-fix-addend-for-preemptible-static-tls
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,8 @@ void MipsGotSection::build() {
// for the TP-relative offset as we don't know how much other data will
// be allocated before us in the static TLS block.
if (s->isPreemptible || ctx.arg.shared)
ctx.mainPart->relaDyn->addReloc(
{ctx.target->tlsGotRel, this, offset, true, *s, 0, R_ABS});
ctx.mainPart->relaDyn->addAddendOnlyRelocIfNonPreemptible(
ctx.target->tlsGotRel, *this, offset, *s, ctx.target->symbolicRel);
}
for (std::pair<Symbol *, size_t> &p : got.dynTlsSymbols) {
Symbol *s = p.first;
Expand Down Expand Up @@ -1156,6 +1156,7 @@ void MipsGotSection::writeTo(uint8_t *buf) {
// if we had to do this.
writeUint(ctx, buf + ctx.arg.wordsize,
(uint64_t)1 << (ctx.arg.wordsize * 8 - 1));
ctx.target->relocateAlloc(*this, buf);
for (const FileGot &g : gots) {
auto write = [&](size_t i, const Symbol *s, int64_t a) {
uint64_t va = a;
Expand Down Expand Up @@ -1185,9 +1186,10 @@ void MipsGotSection::writeTo(uint8_t *buf) {
write(p.second, p.first, 0);
for (const std::pair<Symbol *, size_t> &p : g.relocs)
write(p.second, p.first, 0);
for (const std::pair<Symbol *, size_t> &p : g.tls)
write(p.second, p.first,
p.first->isPreemptible || ctx.arg.shared ? 0 : -0x7000);
for (const std::pair<Symbol *, size_t> &p : g.tls) {
if (!p.first->isPreemptible && !ctx.arg.shared)
write(p.second, p.first, -0x7000);
}
for (const std::pair<Symbol *, size_t> &p : g.dynTlsSymbols) {
if (p.first == nullptr && !ctx.arg.shared)
write(p.second, nullptr, 1);
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/mips-mgot.s
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# CHECK: Contents of section .got:
# CHECK-NEXT: 70000 00000000 80000000 [[FOO0]] [[FOO2]]
# CHECK-NEXT: 70010 00000000 00000004 00010000 00020000
# CHECK-NEXT: 70010 00000000 00000000 00010000 00020000
# CHECK-NEXT: 70020 00030000 00040000 00050000 00060000
# CHECK-NEXT: 70030 00000000 00000000 00000000 00000000
# CHECK-NEXT: 70040 00000000 00000000 00000000
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/mips-tls-64.s
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
# DIS-SO: Contents of section .got:
# DIS-SO-NEXT: 30000 00000000 00000000 80000000 00000000
# DIS-SO-NEXT: 30010 00000000 00000000 00000000 00000000
# DIS-SO-NEXT: 30020 00000000 00000004 00000000 00000000
# DIS-SO-NEXT: 30020 00000000 00000000 00000000 00000000
# DIS-SO-NEXT: 30030 00000000 00000000 00000000 00000000
# DIS-SO-NEXT: 30040 00000000 00000000 00000000 00000000
# DIS-SO-NEXT: 30050 00000000 00000000
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/mips-tls.s
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

# DIS-SO: Contents of section .got:
# DIS-SO-NEXT: 30000 00000000 80000000 00000000 00000000
# DIS-SO-NEXT: 30010 00000004 00000000 00000000 00000000
# DIS-SO-NEXT: 30010 00000000 00000000 00000000 00000000
# DIS-SO-NEXT: 30020 00000000 00000000 00000000

# SO: Relocations [
Expand Down
Loading