This is an archive of the discontinued LLVM Phabricator instance.

[ELF2] - fix for using PLT/GOT for X86TargetInfo
ClosedPublic

Authored by grimar on Oct 7 2015, 10:59 AM.

Details

Summary

I noticed that functions from DSO looks to be always called via PLT+GOT on elf32-i386 linked with modern ld. I think the same approach as was used in X86_64TargetInfo::relocNeedsPlt() should be applied here.

I took the object file and dso from relocation-i686.s test and linked them to executable:

ld --emit-relocs -melf_i386 tmain.o tshared.so -o tmain

And found that .dynamic_reloc section has calls to PLT.

Disassembly of section .dynamic_reloc:
08048199 <.dynamic_reloc>:
8048199: e8 d6 ff ff ff call 8048174 <bar@plt+0x4>

So this fix makes the behavior to be consistent with ld.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 36768.Oct 7 2015, 10:59 AM
grimar retitled this revision from to [ELF2] - fix for using PLT/GOT for X86TargetInfo.
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added a project: lld.
grimar added subscribers: llvm-commits, grimar.
ruiu accepted this revision.Oct 7 2015, 11:19 AM
ruiu edited edge metadata.

LGTM with a nit.

ELF/Target.cpp
59–66 ↗(On Diff #36768)
return Type == R_386_PLT32 || (Type == R_386_PC32 && S.isShared());
This revision is now accepted and ready to land.Oct 7 2015, 11:19 AM
This revision was automatically updated to reflect the committed changes.