llvm.org GIT mirror llvm / b1cf8de
[PowerPC] Correctly handle fixups of other than 4 byte size The PPCAsmBackend::applyFixup routine handles the case where a fixup can be resolved within the same object file. However, this routine is currently hard-coded to assume the size of any fixup is always exactly 4 bytes. This is sort-of correct for fixups on instruction text; even though it only works because several of what really would be 2-byte fixups are presented as 4-byte fixups instead (requiring another hack in PPCELFObjectWriter::adjustFixupOffset to clean it up). However, this assumption breaks down completely for fixups on data, which legitimately can be of any size (1, 2, 4, or 8). This patch makes applyFixup aware of fixups of varying sizes, introducing a new helper routine getFixupKindNumBytes (along the lines of what the ARM back end does). Note that in order to handle fixups of size 8, we also need to fix the return type of adjustFixupValue to uint64_t to avoid truncation. Tested on both 64-bit and 32-bit PowerPC, using external and integrated assembler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181891 91177308-0d34-0410-b5e6-96231b3b80d8 Ulrich Weigand 7 years ago
1 changed file(s) with 27 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
2121 #include "llvm/Support/TargetRegistry.h"
2222 using namespace llvm;
2323
24 static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
24 static uint64_t adjustFixupValue(unsigned Kind, uint64_t Value) {
2525 switch (Kind) {
2626 default:
2727 llvm_unreachable("Unknown fixup kind!");
4949 }
5050 }
5151
52 static unsigned getFixupKindNumBytes(unsigned Kind) {
53 switch (Kind) {
54 default:
55 llvm_unreachable("Unknown fixup kind!");
56 case FK_Data_1:
57 return 1;
58 case FK_Data_2:
59 return 2;
60 case FK_Data_4:
61 case PPC::fixup_ppc_brcond14:
62 case PPC::fixup_ppc_br24:
63 case PPC::fixup_ppc_ha16:
64 case PPC::fixup_ppc_lo16:
65 case PPC::fixup_ppc_lo16_ds:
66 return 4;
67 case FK_Data_8:
68 return 8;
69 case PPC::fixup_ppc_tlsreg:
70 case PPC::fixup_ppc_nofixup:
71 return 0;
72 }
73 }
74
5275 namespace {
5376 class PPCMachObjectWriter : public MCMachObjectTargetWriter {
5477 public:
97120 if (!Value) return; // Doesn't change encoding.
98121
99122 unsigned Offset = Fixup.getOffset();
123 unsigned NumBytes = getFixupKindNumBytes(Fixup.getKind());
100124
101125 // For each byte of the fragment that the fixup touches, mask in the bits
102126 // from the fixup value. The Value has been "split up" into the appropriate
103127 // bitfields above.
104 for (unsigned i = 0; i != 4; ++i)
105 Data[Offset + i] |= uint8_t((Value >> ((4 - i - 1)*8)) & 0xff);
128 for (unsigned i = 0; i != NumBytes; ++i)
129 Data[Offset + i] |= uint8_t((Value >> ((NumBytes - i - 1)*8)) & 0xff);
106130 }
107131
108132 bool mayNeedRelaxation(const MCInst &Inst) const {