Skip to content

Commit 3bbe7a6

Browse files
committed
[XCOFF][AIX] Support basic relocation type on AIX
Summary: This patch intends to support three most common relocation type on AIX: R_POS, R_TOC, R_RBR. These three relocation type will be needed for object file generation on AIX for small code model. We will have follow up patches to bring relocation support for large code model on AIX. Reviewers: hubert.reinterpretcast, daltenty, DiggerLin Differential Revision: https://reviews.llvm.org/D72027
1 parent af3d0d1 commit 3bbe7a6

File tree

9 files changed

+755
-36
lines changed

9 files changed

+755
-36
lines changed

llvm/include/llvm/BinaryFormat/XCOFF.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ namespace llvm {
2020
namespace XCOFF {
2121

2222
// Constants used in the XCOFF definition.
23-
enum { FileNamePadSize = 6, NameSize = 8, SymbolTableEntrySize = 18 };
23+
enum {
24+
FileNamePadSize = 6,
25+
NameSize = 8,
26+
SymbolTableEntrySize = 18,
27+
RelocationSerializationSize32 = 10
28+
};
2429

2530
enum ReservedSectionNum { N_DEBUG = -2, N_ABS = -1, N_UNDEF = 0 };
2631

llvm/include/llvm/MC/MCXCOFFObjectWriter.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class MCXCOFFObjectTargetWriter : public MCObjectTargetWriter {
2828
}
2929
bool is64Bit() const { return Is64Bit; }
3030

31+
// Returns relocation info such as type, sign and size.
32+
// First element of the pair contains type,
33+
// second element contains sign and size.
34+
virtual std::pair<uint8_t, uint8_t>
35+
getRelocTypeAndSignSize(const MCValue &Target, const MCFixup &Fixup,
36+
bool IsPCRel) const = 0;
37+
3138
private:
3239
bool Is64Bit;
3340
};

llvm/lib/MC/MCXCOFFStreamer.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,15 @@ void MCXCOFFStreamer::EmitInstToData(const MCInst &Inst,
6969
raw_svector_ostream VecOS(Code);
7070
Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
7171

72-
// TODO: Handle Fixups later
73-
72+
// Add the fixups and data.
7473
MCDataFragment *DF = getOrCreateDataFragment(&STI);
74+
const size_t ContentsSize = DF->getContents().size();
75+
auto &DataFragmentFixups = DF->getFixups();
76+
for (auto &Fixup : Fixups) {
77+
Fixup.setOffset(Fixup.getOffset() + ContentsSize);
78+
DataFragmentFixups.push_back(Fixup);
79+
}
80+
7581
DF->setHasInstructions(STI);
7682
DF->getContents().append(Code.begin(), Code.end());
7783
}

0 commit comments

Comments
 (0)