This is an archive of the discontinued LLVM Phabricator instance.

[ELF][ARM][AARCH64][MIPS][PPC] Simplify the logic to create R_*_RELATIVE for absolute relocation types in writable sections
ClosedPublic

Authored by MaskRay on Jun 16 2019, 1:46 AM.

Details

Summary

Our rule to create R_*_RELATIVE for absolute relocation types were
loose. D63121 made it stricter but it failed to create R_*_RELATIVE for
R_ARM_TARGET1 and R_PPC64_TOC. The original behavior of ARM and PPC64 is
restored by rLLD363236.

This patch is an attempt to simplify the logic.

Note, in ld.bfd, R_ARM_TARGET2 --target2=abs also creates
R_ARM_RELATIVE. This seems a very uncommon scenario (moreover,
--target2=got-rel is the default), so I do not implement any logic
related to it.

Also, delete R_AARCH64_ABS32 from AArch64::getDynRel. We don't have
working ILP32 support yet. Allowing it would create an incorrect
R_AARCH64_RELATIVE.

For MIPS, the (if SymbolRel, then RelativeRel) code is to keep its
behavior unchanged.

Note, in ppc64-abs64-dyn.s, R_PPC64_TOC gets an incorrect addend because
computeAddend() doesn't compute the correct address. We seem to have the
wrong behavior for a long time. The important thing seems that we should
not create a dynamic relocation R_PPC64_TOC as that the dynamic loader
will error that relocation type is not supported.

Diff Detail

Event Timeline

MaskRay created this revision.Jun 16 2019, 1:46 AM
Herald added a project: Restricted Project. · View Herald Transcript
MaskRay updated this revision to Diff 204941.Jun 16 2019, 1:47 AM

Forgot to add aarch64-abs32-dyn.s

MaskRay updated this revision to Diff 204942.Jun 16 2019, 2:12 AM

Fix *-abs32-dyn.s

From the Arm and AArch64 side this looks good to me, probably best if the Mips and PPC experts confirm their parts.

test/ELF/arm-abs32-dyn.s
17 ↗(On Diff #204942)

R_ARM_32 should be R_ARM_ABS32.

The MIPS part of changes looks good.

PowerPC64 changes LGTM.

MaskRay updated this revision to Diff 205497.Jun 18 2019, 6:58 PM

Fix a comment in arm-abs32-dyn.s: R_ARM_32 -> R_ARM_ABS32

This looks good from Arm/AArch64/MIPS/PPC sides. @ruiu What's your opinion?

ruiu accepted this revision.Jun 20 2019, 6:18 AM

LGTM

This revision is now accepted and ready to land.Jun 20 2019, 6:18 AM
This revision was automatically updated to reflect the committed changes.
lld/test/ELF/ppc64-abs64-dyn.s