This is an archive of the discontinued LLVM Phabricator instance.

Make TLS work for PIE executables on x86-64.
ClosedPublic

Authored by ed on Apr 1 2016, 4:11 AM.

Details

Summary

Caution! http://i2.kym-cdn.com/photos/images/facebook/000/234/739/fa5.jpg

While trying to get PIE work on CloudABI for x86-64, I noticed that even
though GNU ld would generate functional binaries, LLD would not. It
turns out that we generate relocations for referencing TLS objects
inside of the text segment, which shouldn't happen.

This change extends the isRelRelative() function to list some additional
relocation types that should be treated as relative. This makes my C
library unit testing binary work on x86-64.

More details: https://llvm.org/bugs/show_bug.cgi?id=27174

Diff Detail

Event Timeline

ed updated this revision to Diff 52347.Apr 1 2016, 4:11 AM
ed retitled this revision from to Make TLS work for PIE executables on x86-64 and (somewhat) on aarch64..
ed updated this object.
ed added reviewers: rafael, grimar.
rengolin added a reviewer: ruiu.
grimar edited edge metadata.Apr 1 2016, 4:43 AM

I think this need split into 2: for x86_64 and aarch64 separatelly.
And also this needs a testcase.

grimar added inline comments.Apr 1 2016, 7:07 AM
ELF/Target.cpp
811

Change itself looks ok for me.

ruiu edited edge metadata.Apr 1 2016, 9:28 AM

The code looks good, so please add a test case.

ed updated this revision to Diff 52385.Apr 1 2016, 9:45 AM
ed edited edge metadata.

Remove the aarch64 changes. Also add a test case.

I've noticed that my change does make one of the existing tests fail.
I'm not entirely sure, but my suspicion is that this test is in fact
invalid. GNU ld seems to reject object files containing these
relocations when creating a shared object. Maybe we should extend LLD to
throw an error message as well?

ed retitled this revision from Make TLS work for PIE executables on x86-64 and (somewhat) on aarch64. to Make TLS work for PIE executables on x86-64..Apr 1 2016, 9:45 AM
ed updated this object.
ruiu added a comment.Apr 1 2016, 11:30 AM

It seems that this change affects how the dynamic relocations are created for TLS variables. Rafael is rewriting that part of the code, so you want to wait for him to finish it instead of trying to understand the current code (which is Writer::scanRelocs).

ed added a comment.EditedApr 3 2016, 2:16 PM

This is interesting. Together with http://reviews.llvm.org/D18739, test/ELF/tls-initial-exec-local.s passes again.

If you want, I can put it back in the source tree. I still guess the test looks a bit shady for using static TLS in a shared object.

ed updated this revision to Diff 52735.Apr 5 2016, 1:51 PM

Put tls-initial-exec-local.s back in now that the GOT works properly.

ed added a comment.Apr 5 2016, 1:52 PM

Okay. Now that my other change has landed, I think we can go ahead with this change as well. Any thoughts?

ruiu accepted this revision.Apr 5 2016, 1:54 PM
ruiu edited edge metadata.

Yes, LGTM. Thank you for all these patches!

This revision is now accepted and ready to land.Apr 5 2016, 1:54 PM
ed closed this revision.Apr 6 2016, 12:30 AM
ELF/Target.cpp