This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ARM] Allow relative exceptions relocations in shared libraries
ClosedPublic

Authored by peter.smith on Oct 18 2016, 3:40 AM.

Details

Summary

The R_ARM_NONE and R_ARM_PREL31 relocations are currently faulted when used in a shared object with:
can't create dynamic relocation R_ARM_NONE against symbol aeabi_unwind_cpp_pr0
can't create dynamic relocation R_ARM_PREL31 against symbol
gxx_personality_v0

In the case of R_ARM_NONE this is because the R_ARM_NONE relocation is R_ABS when it should be relative, and it should be skipped in the same way that a R_HINT is handled as it should not affect any PLT-generation. Unfortunately R_ARM_NONE can't map to R_HINT as R_HINT has side-effects for TLS generation. I've introduced a R_NONE RelExpr to handle R_ARM_NONE in shared objects.

In the case of R_ARM_PREL31 this should map to R_PLT_PC as the personality routine can be imported so in a shared object the R_ARM_PREL31 has to resolve to the address of the PLT entry for the personality routine.

Diff Detail

Repository
rL LLVM

Event Timeline

peter.smith retitled this revision from to [LLD][ARM] Allow relative exceptions relocations in shared libraries.
peter.smith updated this object.
peter.smith added reviewers: ruiu, rafael.
peter.smith added a subscriber: llvm-commits.
ruiu edited edge metadata.Oct 18 2016, 11:44 AM

I wonder why we are mapping R_AARCH64_TLSDESC_CALL to R_HINT. The other relocation that is mapped to R_HINT is R_MIPS_JALR, but that relocation is purely a hint -- the linker is allowed to do a peephole optimization by rewriting the instructions pointed by the relocation, but it's allowed to not do. On the other hand, we need to do something for TLS generation for R_AARCH64_TLSDESC_CALL. It seems that two semantically different relocations are mapped to one relocation type.

Maybe you could create a new relocation type for R_AARCH64_TLSDESC_CALL and then map R_ARM_NONE to R_HINT?

peter.smith edited edge metadata.

Thank you for the review. I've implemented the suggestion to add a R_TLSDESC_CALL RelExpr and used R_HINT for R_ARM_NONE and R_MIPS_JALR.

It could be possible to get rid of R_TLSDESC_CALL by replacing "Expr == R_TLSDESC_CALL" by
"Expr == R_HINT && Target->isTlsDescCall(Type)"

However I think that R_TLSDESC_CALL is worth keeping individually as it is common to x86, ARM and AArch64 even if it is only implemented in AArch64 in lld.

ruiu accepted this revision.Oct 19 2016, 10:48 AM
ruiu edited edge metadata.

LGTM

ELF/Relocations.h
63–64 ↗(On Diff #75135)

Sort

This revision is now accepted and ready to land.Oct 19 2016, 10:48 AM
This revision was automatically updated to reflect the committed changes.