#include "Chunks.h"
#include "COFFLinkerContext.h"
#include "InputFiles.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "Writer.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <iterator>
usingnamespacellvm;
usingnamespacellvm::object;
usingnamespacellvm::support::endian;
usingnamespacellvm::COFF;
ulittle32_t;
namespace lld::coff {
SectionChunk::SectionChunk(ObjFile *f, const coff_section *h, Kind k)
: … { … }
static_assert …;
static void add16(uint8_t *p, int16_t v) { … }
static void add32(uint8_t *p, int32_t v) { … }
static void add64(uint8_t *p, int64_t v) { … }
static void or16(uint8_t *p, uint16_t v) { … }
static void or32(uint8_t *p, uint32_t v) { … }
static bool checkSecRel(const SectionChunk *sec, OutputSection *os) { … }
static void applySecRel(const SectionChunk *sec, uint8_t *off,
OutputSection *os, uint64_t s) { … }
static void applySecIdx(uint8_t *off, OutputSection *os,
unsigned numOutputSections) { … }
void SectionChunk::applyRelX64(uint8_t *off, uint16_t type, OutputSection *os,
uint64_t s, uint64_t p,
uint64_t imageBase) const { … }
void SectionChunk::applyRelX86(uint8_t *off, uint16_t type, OutputSection *os,
uint64_t s, uint64_t p,
uint64_t imageBase) const { … }
static void applyMOV(uint8_t *off, uint16_t v) { … }
static uint16_t readMOV(uint8_t *off, bool movt) { … }
void applyMOV32T(uint8_t *off, uint32_t v) { … }
static void applyBranch20T(uint8_t *off, int32_t v) { … }
void applyBranch24T(uint8_t *off, int32_t v) { … }
void SectionChunk::applyRelARM(uint8_t *off, uint16_t type, OutputSection *os,
uint64_t s, uint64_t p,
uint64_t imageBase) const { … }
void applyArm64Addr(uint8_t *off, uint64_t s, uint64_t p, int shift) { … }
void applyArm64Imm(uint8_t *off, uint64_t imm, uint32_t rangeLimit) { … }
static void applyArm64Ldr(uint8_t *off, uint64_t imm) { … }
static void applySecRelLow12A(const SectionChunk *sec, uint8_t *off,
OutputSection *os, uint64_t s) { … }
static void applySecRelHigh12A(const SectionChunk *sec, uint8_t *off,
OutputSection *os, uint64_t s) { … }
static void applySecRelLdr(const SectionChunk *sec, uint8_t *off,
OutputSection *os, uint64_t s) { … }
void applyArm64Branch26(uint8_t *off, int64_t v) { … }
static void applyArm64Branch19(uint8_t *off, int64_t v) { … }
static void applyArm64Branch14(uint8_t *off, int64_t v) { … }
void SectionChunk::applyRelARM64(uint8_t *off, uint16_t type, OutputSection *os,
uint64_t s, uint64_t p,
uint64_t imageBase) const { … }
static void maybeReportRelocationToDiscarded(const SectionChunk *fromChunk,
Defined *sym,
const coff_relocation &rel,
bool isMinGW) { … }
void SectionChunk::writeTo(uint8_t *buf) const { … }
void SectionChunk::applyRelocation(uint8_t *off,
const coff_relocation &rel) const { … }
void SectionChunk::sortRelocations() { … }
void SectionChunk::writeAndRelocateSubsection(ArrayRef<uint8_t> sec,
ArrayRef<uint8_t> subsec,
uint32_t &nextRelocIndex,
uint8_t *buf) const { … }
void SectionChunk::addAssociative(SectionChunk *child) { … }
static uint8_t getBaserelType(const coff_relocation &rel,
Triple::ArchType arch) { … }
void SectionChunk::getBaserels(std::vector<Baserel> *res) { … }
static int getRuntimePseudoRelocSize(uint16_t type,
llvm::COFF::MachineTypes machine) { … }
void SectionChunk::getRuntimePseudoRelocs(
std::vector<RuntimePseudoReloc> &res) { … }
bool SectionChunk::isCOMDAT() const { … }
void SectionChunk::printDiscardedMessage() const { … }
StringRef SectionChunk::getDebugName() const { … }
ArrayRef<uint8_t> SectionChunk::getContents() const { … }
ArrayRef<uint8_t> SectionChunk::consumeDebugMagic() { … }
ArrayRef<uint8_t> SectionChunk::consumeDebugMagic(ArrayRef<uint8_t> data,
StringRef sectionName) { … }
SectionChunk *SectionChunk::findByName(ArrayRef<SectionChunk *> sections,
StringRef name) { … }
void SectionChunk::replace(SectionChunk *other) { … }
uint32_t SectionChunk::getSectionNumber() const { … }
CommonChunk::CommonChunk(const COFFSymbolRef s) : … { … }
uint32_t CommonChunk::getOutputCharacteristics() const { … }
void StringChunk::writeTo(uint8_t *buf) const { … }
ImportThunkChunkX64::ImportThunkChunkX64(COFFLinkerContext &ctx, Defined *s)
: … { … }
void ImportThunkChunkX64::writeTo(uint8_t *buf) const { … }
void ImportThunkChunkX86::getBaserels(std::vector<Baserel> *res) { … }
void ImportThunkChunkX86::writeTo(uint8_t *buf) const { … }
void ImportThunkChunkARM::getBaserels(std::vector<Baserel> *res) { … }
void ImportThunkChunkARM::writeTo(uint8_t *buf) const { … }
void ImportThunkChunkARM64::writeTo(uint8_t *buf) const { … }
const uint8_t armThunk[] = …;
size_t RangeExtensionThunkARM::getSize() const { … }
void RangeExtensionThunkARM::writeTo(uint8_t *buf) const { … }
const uint8_t arm64Thunk[] = …;
size_t RangeExtensionThunkARM64::getSize() const { … }
void RangeExtensionThunkARM64::writeTo(uint8_t *buf) const { … }
LocalImportChunk::LocalImportChunk(COFFLinkerContext &c, Defined *s)
: … { … }
void LocalImportChunk::getBaserels(std::vector<Baserel> *res) { … }
size_t LocalImportChunk::getSize() const { … }
void LocalImportChunk::writeTo(uint8_t *buf) const { … }
void RVATableChunk::writeTo(uint8_t *buf) const { … }
void RVAFlagTableChunk::writeTo(uint8_t *buf) const { … }
size_t ECCodeMapChunk::getSize() const { … }
void ECCodeMapChunk::writeTo(uint8_t *buf) const { … }
size_t PseudoRelocTableChunk::getSize() const { … }
void PseudoRelocTableChunk::writeTo(uint8_t *buf) const { … }
BaserelChunk::BaserelChunk(uint32_t page, Baserel *begin, Baserel *end) { … }
void BaserelChunk::writeTo(uint8_t *buf) const { … }
uint8_t Baserel::getDefaultType(llvm::COFF::MachineTypes machine) { … }
MergeChunk::MergeChunk(uint32_t alignment)
: … { … }
void MergeChunk::addSection(COFFLinkerContext &ctx, SectionChunk *c) { … }
void MergeChunk::finalizeContents() { … }
void MergeChunk::assignSubsectionRVAs() { … }
uint32_t MergeChunk::getOutputCharacteristics() const { … }
size_t MergeChunk::getSize() const { … }
void MergeChunk::writeTo(uint8_t *buf) const { … }
size_t AbsolutePointerChunk::getSize() const { … }
void AbsolutePointerChunk::writeTo(uint8_t *buf) const { … }
void ECExportThunkChunk::writeTo(uint8_t *buf) const { … }
size_t CHPECodeRangesChunk::getSize() const { … }
void CHPECodeRangesChunk::writeTo(uint8_t *buf) const { … }
size_t CHPERedirectionChunk::getSize() const { … }
void CHPERedirectionChunk::writeTo(uint8_t *buf) const { … }
}