This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] - Set DF_STATIC_TLS flag for X64 target
ClosedPublic

Authored by grimar on Feb 6 2019, 7:33 AM.

Details

Summary

This is the same as D57749, but for x64 target.

"ELF Handling For Thread-Local Storage" p41 says (https://www.akkadia.org/drepper/tls.pdf):
R_X86_64_GOTTPOFF relocation is used for IE TLS models.
Hence if linker sees this relocation we should add DF_STATIC_TLS flag.
This is the relocation which FreeBSD was interested in initially I think (https://reviews.freebsd.org/D19072)

For LE model (p49), the R_X86_64_TPOFF32 is used.
But linkers do not allow to use it for DSO, for example, LLD would report:
"error: relocation R_X86_64_TPOFF32 cannot be used against symbol var; recompile with -fPIC"
So seems we only want to catch the R_X86_64_GOTTPOFF?

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Feb 6 2019, 7:33 AM
grimar planned changes to this revision.Feb 6 2019, 7:34 AM

Will update. Forgot about the other test cases. Sorry.

grimar updated this revision to Diff 185559.Feb 6 2019, 8:06 AM
  • Updated the tests.
ruiu accepted this revision.Feb 6 2019, 9:36 AM

LGTM

test/ELF/x86_64-static-tls-model.s
1 ↗(On Diff #185559)

We use x86-64 instead of x86_64 as a prefix for test files.

This revision is now accepted and ready to land.Feb 6 2019, 9:36 AM
pcc added a subscriber: pcc.Feb 6 2019, 11:07 AM
pcc added inline comments.
ELF/Arch/X86_64.cpp
84 ↗(On Diff #185559)

Should this be done in scanRelocs? Then I believe that HasStaticTlsModel would not need to be atomic.

grimar marked an inline comment as done.Feb 6 2019, 1:56 PM
grimar added inline comments.
ELF/Arch/X86_64.cpp
84 ↗(On Diff #185559)

I suggested this in comments for D57749:
https://reviews.llvm.org/D57749?id=185294#inline-511460

Rui seems to prefer to have atomic. I have no strong feeling about what is better.
Both approaches have own pros and cons.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2019, 11:59 PM