This is an archive of the discontinued LLVM Phabricator instance.

[ELF2] - Implemented R_X86_64_PLT32 rellocation.
ClosedPublic

Authored by grimar on Oct 16 2015, 3:29 PM.

Details

Summary

Note: There is sometimes no need to generate rellocation via PLT.
Example - when symbol is not undefined and we are not creating shared library. Then we can create relative relocation instead of referencing and creating PLT records.
That is how ld behaves I believe.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 37649.Oct 16 2015, 3:29 PM
grimar retitled this revision from to [ELF2] - Implemented R_X86_64_PLT32 rellocation..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
ruiu added inline comments.Oct 16 2015, 4:05 PM
ELF/Target.cpp
314–316 ↗(On Diff #37649)

Your test does not seem to cover this code. (I just run your test without applying this code, and it didn't die with "unrecognized reloc" error defined below, so a relocation with R_x86_64_PLT32 did not reach this function.)

grimar added inline comments.Oct 16 2015, 4:15 PM
ELF/Target.cpp
314–316 ↗(On Diff #37649)

Without applying this code this relocations are handled in another branch and consumed by:

void InputSection<ELFT>::relocate(
....

if (Target->relocNeedsPlt(Type, Body)) {                <--- here
  SymVA = Out<ELFT>::Plt->getEntryAddr(Body);
  Type = Target->getPLTRefReloc(Type);
}

but since my case does not need plt then execution moves forward to relocateOne() and fails there without R_X86_64_PLT32 handler.

grimar added inline comments.Oct 16 2015, 4:23 PM
ELF/Target.cpp
314–316 ↗(On Diff #37649)

Does not need PLT for _start I mean.

ruiu accepted this revision.Oct 16 2015, 4:25 PM
ruiu edited edge metadata.

LGTM with a nit.

Please update the test by adding a PLT32 relocation referring a symbol which is resolved within the same file, like this.

.global _start, foo
_start:
  jmp bar@PLT
  jmp bar@PLT
  jmp zed@PLT
  jmp foo@PLT
  jmp _start@plt
foo:
This revision is now accepted and ready to land.Oct 16 2015, 4:25 PM
This revision was automatically updated to reflect the committed changes.

This looks to break self hosting for me. r250578 works fine, but this (r250584) leads to test fails during check-clang.

rafael edited edge metadata.Oct 18 2015, 5:29 PM
rafael added a subscriber: rafael.

The problem seems to be in the linking of lib64/libclang.so.3..

I think the bug is just that we produce unnecessary relocations:

callq atexit@PLT
atexit:

will create a dynamic relocation.

I will fix it early tomorrow.

r250682 might have fixed it.

r250682 might have fixed it.

Great, it works, thanks a lot ! That gives a chance for lazy relocations patch: http://reviews.llvm.org/D13856