This is an archive of the discontinued LLVM Phabricator instance.

[lld][elf2] Local Dynamic TLS
AbandonedPublic

Authored by Bigcheese on Oct 9 2015, 5:41 PM.

Details

Summary

This patch isn't in a finished state, but I wanted some guidance on how to properly do the GOT parts. Right now it's hacked to just look for the TLSLD relocs. We're also going to run into an issue with GOT entries when we do global dynamic TLS. Each TLS symbol gets two entries, each with a different relocation.

I switched compareOutputSections to a numeric based compare because adding proper order for TLS to it over complicated the code.

Diff Detail

Event Timeline

Bigcheese updated this revision to Diff 37010.Oct 9 2015, 5:41 PM
Bigcheese retitled this revision from to [lld][elf2] Local Dynamic TLS.
Bigcheese updated this object.
Bigcheese added reviewers: ruiu, rafael.
Bigcheese added a subscriber: llvm-commits.
ruiu added inline comments.Oct 12 2015, 3:41 PM
ELF/OutputSections.cpp
58
continue;  // skip TLS empty second slot
128

I don't understand this. Is R_x86_64_TLSLD interpositioned? This function is really complicated and needs cleanup.

ELF/OutputSections.h
111

It seems that we don't really have to pass the number to this function because the symbol should know that. If it's STT_TLS, we need two slots. Otherwise one. Can you remove the second parameter?

ELF/Writer.cpp
143

Global uninitialized values should be initialized with zero, so no need to assign the same value again.

220

This is another use of canBePreempted(Body) || Type == R_X86_64_TLSLD

292–327

Can you move this function to top level? This doesn't have to be a lambda.

298
(Flags & SHF_ALLOC) && (Flags | SHF_TLS)
563
(Sec->getFlags() & SHF_ALLOC) && (Sec->getFalgs() & SHF_TLS)
563–586

Please try to reduce the amount of code to add this code, or completely split this function. This function is already too long.

emaste added a subscriber: emaste.Oct 12 2015, 4:06 PM
rafael edited edge metadata.Oct 13 2015, 1:40 PM

This also needs to be rebased.

ELF/Target.cpp
372

Please update this. Depending on false -> 0 is just bad.

You probably also want to rename the function.

ELF/Writer.cpp
294

Sorry, but why exactly does it need to be at the start of the PT_LOAD? We need to have a single PT_TLS ,but that would still be the case with us having

  • Some stuff
  • TLS stuff
  • Some other stuff
ruiu added inline comments.Oct 13 2015, 1:51 PM
ELF/Target.cpp
372

I don't think we need to return int in the first place as the number of got slots a symbol needs can be inferred from the symbol type, as I wrote in the review comment.

We had a chat "offline".

I asked Michael to split this in 3 patches for easier discussion:

  • Ordering the TLS sections.
  • Creating the TLS segment.
  • Handling the relocations.

For the first part, there a few properties of tls to keep in mind

  • There is only one segment, so the NOBITS part of TLS has to be just

after the non NOBITS part.

  • All actual TLS sections are RW, so we only need to put the tls logic

once we know we are in a single PT_LOAD.

  • If it is NOBITS TLS, it must come before non TLS. If it is a non

NOBITS TLS, it must come after.

Cheers,
Rafael

espindola edited reviewers, added: espindola; removed: rafael.Mar 15 2018, 10:58 AM
Bigcheese abandoned this revision.Nov 14 2019, 1:09 PM
Bigcheese marked 5 inline comments as done.
Bigcheese added inline comments.
ELF/OutputSections.cpp
128

R_X86_64_TLSLD can't be preempted, but this is the function that's used to determine if we should emit a dynamic relocation for it or not. As I said in the description, I wanted some guidance on how to restructure the GOT code to handle this.

ELF/Writer.cpp
143

This would make writeResult non-reentrant while it currently is reentrant.