COFF: Split writeTo in preparation for supporting 32-bit x86.
llvm-svn: 241638
This commit is contained in:
parent
489abd7046
commit
661a4e7ab6
|
@ -48,20 +48,9 @@ static void add16(uint8_t *P, int16_t V) { write16le(P, read16le(P) + V); }
|
||||||
static void add32(uint8_t *P, int32_t V) { write32le(P, read32le(P) + V); }
|
static void add32(uint8_t *P, int32_t V) { write32le(P, read32le(P) + V); }
|
||||||
static void add64(uint8_t *P, int64_t V) { write64le(P, read64le(P) + V); }
|
static void add64(uint8_t *P, int64_t V) { write64le(P, read64le(P) + V); }
|
||||||
|
|
||||||
void SectionChunk::writeTo(uint8_t *Buf) {
|
void SectionChunk::applyRelX64(uint8_t *Off, uint16_t Type, uint64_t S,
|
||||||
if (!hasData())
|
uint64_t P) {
|
||||||
return;
|
switch (Type) {
|
||||||
// Copy section contents from source object file to output file.
|
|
||||||
ArrayRef<uint8_t> A = getContents();
|
|
||||||
memcpy(Buf + FileOff, A.data(), A.size());
|
|
||||||
|
|
||||||
// Apply relocations.
|
|
||||||
for (const coff_relocation &Rel : Relocs) {
|
|
||||||
uint8_t *Off = Buf + FileOff + Rel.VirtualAddress;
|
|
||||||
SymbolBody *Body = File->getSymbolBody(Rel.SymbolTableIndex)->repl();
|
|
||||||
uint64_t S = cast<Defined>(Body)->getRVA();
|
|
||||||
uint64_t P = RVA + Rel.VirtualAddress;
|
|
||||||
switch (Rel.Type) {
|
|
||||||
case IMAGE_REL_AMD64_ADDR32: add32(Off, S + Config->ImageBase); break;
|
case IMAGE_REL_AMD64_ADDR32: add32(Off, S + Config->ImageBase); break;
|
||||||
case IMAGE_REL_AMD64_ADDR64: add64(Off, S + Config->ImageBase); break;
|
case IMAGE_REL_AMD64_ADDR64: add64(Off, S + Config->ImageBase); break;
|
||||||
case IMAGE_REL_AMD64_ADDR32NB: add32(Off, S); break;
|
case IMAGE_REL_AMD64_ADDR32NB: add32(Off, S); break;
|
||||||
|
@ -77,6 +66,22 @@ void SectionChunk::writeTo(uint8_t *Buf) {
|
||||||
llvm::report_fatal_error("Unsupported relocation type");
|
llvm::report_fatal_error("Unsupported relocation type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SectionChunk::writeTo(uint8_t *Buf) {
|
||||||
|
if (!hasData())
|
||||||
|
return;
|
||||||
|
// Copy section contents from source object file to output file.
|
||||||
|
ArrayRef<uint8_t> A = getContents();
|
||||||
|
memcpy(Buf + FileOff, A.data(), A.size());
|
||||||
|
|
||||||
|
// Apply relocations.
|
||||||
|
for (const coff_relocation &Rel : Relocs) {
|
||||||
|
uint8_t *Off = Buf + FileOff + Rel.VirtualAddress;
|
||||||
|
SymbolBody *Body = File->getSymbolBody(Rel.SymbolTableIndex)->repl();
|
||||||
|
uint64_t S = cast<Defined>(Body)->getRVA();
|
||||||
|
uint64_t P = RVA + Rel.VirtualAddress;
|
||||||
|
applyRelX64(Off, Rel.Type, S, P);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SectionChunk::addAssociative(SectionChunk *Child) {
|
void SectionChunk::addAssociative(SectionChunk *Child) {
|
||||||
|
|
|
@ -136,6 +136,7 @@ public:
|
||||||
StringRef getSectionName() const override { return SectionName; }
|
StringRef getSectionName() const override { return SectionName; }
|
||||||
void getBaserels(std::vector<uint32_t> *Res, Defined *ImageBase) override;
|
void getBaserels(std::vector<uint32_t> *Res, Defined *ImageBase) override;
|
||||||
bool isCOMDAT() const;
|
bool isCOMDAT() const;
|
||||||
|
void applyRelX64(uint8_t *Off, uint16_t Type, uint64_t S, uint64_t P);
|
||||||
|
|
||||||
// Called if the garbage collector decides to not include this chunk
|
// Called if the garbage collector decides to not include this chunk
|
||||||
// in a final output. It's supposed to print out a log message to stdout.
|
// in a final output. It's supposed to print out a log message to stdout.
|
||||||
|
|
Loading…
Reference in New Issue