[PATCH] D66072: [MC][PowerPC] Emit R_PPC_UADDR32 and R_PPC64_UADDR64 if r_offset is misaligned
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 12 00:51:27 PDT 2019
MaskRay created this revision.
MaskRay added reviewers: hfinkel, jsji, sfertile, wuzish.
Herald added subscribers: llvm-commits, shchenz, kbarton, krytarowski, nemanjai, emaste.
Herald added a project: LLVM.
R_PPC_ADDR32 and R_PPC64_ADDR64 may be emitted at misaligned r_offset.
This does not conform to the ABIs.
32-bit psABI says:
> word32
> Specifies a 32-bit bit-field taking up 4 bytes maintaining 4-byte alignment unless otherwise indicated.
ELFv2 ABI says:
> doubleword64 specifies a 64-bit field occupying 8 bytes, the alignment of which is 8 bytes unless otherwise specified.
R_PPC_UADDR32 and R_PPC64_UADDR64 belong to the word32 and doubleword64 classes, respectively.
This patch fixes the problem by teaching ELFWriter::writeRelocations to
emit UADDR if an ADDR has a misaligned r_offset. This cannot be done in
the derived MCELFObjectTargetWriter::getRelocType because r_offset is
not known there.
When objects are linked into executable/DSO:
- If sh_addralign >= 8, an R_PPC64_ADDR64 whose r_offset%8!=0 is guaranteed to have a misaligned address.
- Otherwise, it may have an aligned address if the relocated section is combined with other sections, e.g.
.section .data,"aw", at progbits,unique,0; .align 8; .byte 0
.section .data,"aw", at progbits,unique,1; .space 7; .long a
UADDR are rare: they are caused by initialized data at misaligned
addresses (e.g. __attribute__((packed))). So we don't necessarily
optimize for them.
This change also simplifies the linker design. Since R_PPC64_ADDR64 will
be guaranteed to be aligned, we can safely emit dynamic R_PPC64_RELATIVE
for R_PPC64_ADDR64 to a non-preemptable symbol in a writable location.
(Currently lld ppc{32,64} and ld.bfd ppc32 can emit misaligned
R_PPC{,64}_RELATIVE. This is not a big problem - kernels (verified with Linux
and FreeBSD) trap handlers will fix misaligned accesses).)
Repository:
rL LLVM
https://reviews.llvm.org/D66072
Files:
include/llvm/BinaryFormat/ELFRelocs/PowerPC64.def
lib/MC/ELFObjectWriter.cpp
lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
test/MC/PowerPC/ppc32-uaddr.s
test/MC/PowerPC/ppc64-uaddr.s
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66072.214583.patch
Type: text/x-patch
Size: 4430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190812/a89f3170/attachment.bin>
More information about the llvm-commits
mailing list