This is an archive of the discontinued LLVM Phabricator instance.

[lld] [ELF/AArch64] Fix R_AARCH64_ABS64 in Shared mode
ClosedPublic

Authored by zatrazz on Feb 15 2016, 5:18 AM.

Details

Reviewers
ruiu
rafael
Summary

This patch fixes the R_AARCH64_ABS64 relocation when used in shared mode,
where it requires a dynamic R_AARCH64_RELATIVE relocation. To correct set
the addend on the dynamic relocation (since it will be used by the dynamic
linker), a new TargetInfo specific hook was created (getDynRelativeAddend)
to get the correct addend based on relocation type.

It also lead to some cleanup on powerpc backend by moving the specific
TOC base addend on the target specific code.

The patch fixes the issues when creating shared library code against
{init,fini}_array, where it issues R_AARCH64_ABS64 relocation against
local symbols.

Diff Detail

Event Timeline

zatrazz updated this revision to Diff 47981.Feb 15 2016, 5:18 AM
zatrazz retitled this revision from to [lld] [ELF/AArch64] Fix R_AARCH64_ABS64 in Shared mode.
zatrazz updated this object.
zatrazz added reviewers: ruiu, rafael.
zatrazz set the repository for this revision to rL LLVM.
zatrazz added a project: lld.
zatrazz added a subscriber: llvm-commits.
ruiu added inline comments.Feb 16 2016, 11:39 AM
ELF/Writer.cpp
314–322

Instead of handling a local symbol as a special case, do you think you can create a new instance of SymbolBody here for local symbols and pass it to addReloc?

zatrazz added inline comments.Feb 17 2016, 5:02 AM
ELF/Writer.cpp
314–322

I tried to add a local symbol table in InputSectionBase, but it ended up begin disruptive in the sense it required a lot of code modification to handle it. However I think it is possible to create a local SymbolBody, although I see such modification to be an forward change.

ruiu added inline comments.Feb 17 2016, 10:14 AM
ELF/OutputSections.cpp
256–258

Can you add {} after if and else if?

264–265

Please use actual types instead of auto.

ELF/Target.cpp
1061–1066

I skimmed through the relocation handling of PPC, but I couldn't find the location for this particular code. Can you describe it for me? (And adding a comment would be appreciated.)

zatrazz added inline comments.Feb 18 2016, 5:35 AM
ELF/Target.cpp
1061–1066

I have added it on development phase, but seems ppc already handle that in elf2::getLocalRelTarget. I will remove it.

zatrazz updated this revision to Diff 48303.Feb 18 2016, 5:43 AM
zatrazz removed rL LLVM as the repository for this revision.

Fixed patch based on previous comments.

ruiu added inline comments.Feb 18 2016, 12:46 PM
ELF/Target.h
57 ↗(On Diff #48303)

You defined this function but this function is an identity function in all subclasses. If you no longer need it, please remove.

zatrazz updated this revision to Diff 48479.Feb 19 2016, 5:23 AM

Updated patch based on previous comment.

ruiu accepted this revision.Feb 22 2016, 3:10 PM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Feb 22 2016, 3:10 PM
zatrazz closed this revision.Feb 23 2016, 8:59 AM