Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lld/COFF/Chunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,10 @@ uint32_t ImportThunkChunkARM64EC::extendRanges() {
return sizeof(arm64Thunk) - sizeof(uint32_t);
}

uint64_t Arm64XRelocVal::get() const {
return (sym ? sym->getRVA() : 0) + value;
}

size_t Arm64XDynamicRelocEntry::getSize() const {
switch (type) {
case IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE:
Expand All @@ -1186,13 +1190,13 @@ void Arm64XDynamicRelocEntry::writeTo(uint8_t *buf) const {
*out |= ((bit_width(size) - 1) << 14); // Encode the size.
switch (size) {
case 2:
out[1] = value;
out[1] = value.get();
break;
case 4:
*reinterpret_cast<ulittle32_t *>(out + 1) = value;
*reinterpret_cast<ulittle32_t *>(out + 1) = value.get();
break;
case 8:
*reinterpret_cast<ulittle64_t *>(out + 1) = value;
*reinterpret_cast<ulittle64_t *>(out + 1) = value.get();
break;
default:
llvm_unreachable("invalid size");
Expand Down
18 changes: 15 additions & 3 deletions lld/COFF/Chunks.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,18 +835,30 @@ class ECExportThunkChunk : public NonSectionCodeChunk {
Defined *target;
};

// ARM64X relocation value, potentially relative to a symbol.
class Arm64XRelocVal {
public:
Arm64XRelocVal(uint64_t value = 0) : value(value) {}
Arm64XRelocVal(Defined *sym, int32_t offset = 0) : sym(sym), value(offset) {}
uint64_t get() const;

private:
Defined *sym = nullptr;
uint64_t value;
};

// ARM64X entry for dynamic relocations.
class Arm64XDynamicRelocEntry {
public:
Arm64XDynamicRelocEntry(llvm::COFF::Arm64XFixupType type, uint8_t size,
uint32_t offset, uint64_t value)
uint32_t offset, Arm64XRelocVal value)
: offset(offset), value(value), type(type), size(size) {}

size_t getSize() const;
void writeTo(uint8_t *buf) const;

uint32_t offset;
uint64_t value;
Arm64XRelocVal value;

private:
llvm::COFF::Arm64XFixupType type;
Expand All @@ -862,7 +874,7 @@ class DynamicRelocsChunk : public NonSectionChunk {
void finalize();

void add(llvm::COFF::Arm64XFixupType type, uint8_t size, uint32_t offset,
uint64_t value) {
Arm64XRelocVal value) {
arm64xRelocs.emplace_back(type, size, offset, value);
}

Expand Down
7 changes: 3 additions & 4 deletions lld/COFF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2584,18 +2584,17 @@ void Writer::createDynamicRelocs() {
coffHeaderOffset + offsetof(coff_file_header, Machine),
AMD64);

// Clear the load config directory.
// FIXME: Use the hybrid load config value instead.
// Set the hybrid load config to the EC load config.
ctx.dynamicRelocs->add(IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE, sizeof(uint32_t),
dataDirOffset64 +
LOAD_CONFIG_TABLE * sizeof(data_directory) +
offsetof(data_directory, RelativeVirtualAddress),
0);
ctx.hybridSymtab->loadConfigSym);
ctx.dynamicRelocs->add(IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE, sizeof(uint32_t),
dataDirOffset64 +
LOAD_CONFIG_TABLE * sizeof(data_directory) +
offsetof(data_directory, Size),
0);
ctx.hybridSymtab->loadConfigSize);
}

PartialSection *Writer::createPartialSection(StringRef name,
Expand Down
37 changes: 33 additions & 4 deletions lld/test/COFF/arm64x-loadconfig.s
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,49 @@
// LOADCFG-NEXT: RVA: 0x150
// LOADCFG-NEXT: Type: VALUE
// LOADCFG-NEXT: Size: 0x4
// LOADCFG-NEXT: Value: 0x0
// LOADCFG-NEXT: Value: 0x1140
// LOADCFG-NEXT: ]
// LOADCFG-NEXT: Entry [
// LOADCFG-NEXT: RVA: 0x154
// LOADCFG-NEXT: Type: VALUE
// LOADCFG-NEXT: Size: 0x4
// LOADCFG-NEXT: Value: 0x0
// LOADCFG-NEXT: Value: 0x140
// LOADCFG-NEXT: ]
// LOADCFG-NEXT: ]
// LOADCFG-NEXT: ]
// LOADCFG-NEXT: HybridObject {
// LOADCFG-NEXT: Format: COFF-x86-64
// LOADCFG-NEXT: Arch: x86_64
// LOADCFG-NEXT: Format: COFF-ARM64EC
// LOADCFG-NEXT: Arch: aarch64
// LOADCFG-NEXT: AddressSize: 64bit
// LOADCFG-NEXT: LoadConfig [
// LOADCFG-NEXT: Size: 0x140
// LOADCFG: CHPEMetadata [
// LOADCFG-NEXT: Version: 0x2
// LOADCFG: ]
// LOADCFG-NEXT: DynamicRelocations [
// LOADCFG-NEXT: Version: 0x1
// LOADCFG-NEXT: Arm64X [
// LOADCFG-NEXT: Entry [
// LOADCFG-NEXT: RVA: 0x7C
// LOADCFG-NEXT: Type: VALUE
// LOADCFG-NEXT: Size: 0x2
// LOADCFG-NEXT: Value: 0x8664
// LOADCFG-NEXT: ]
// LOADCFG-NEXT: Entry [
// LOADCFG-NEXT: RVA: 0x150
// LOADCFG-NEXT: Type: VALUE
// LOADCFG-NEXT: Size: 0x4
// LOADCFG-NEXT: Value: 0x1140
// LOADCFG-NEXT: ]
// LOADCFG-NEXT: Entry [
// LOADCFG-NEXT: RVA: 0x154
// LOADCFG-NEXT: Type: VALUE
// LOADCFG-NEXT: Size: 0x4
// LOADCFG-NEXT: Value: 0x140
// LOADCFG-NEXT: ]
// LOADCFG-NEXT: ]
// LOADCFG-NEXT: ]
// LOADCFG-NEXT: }

// RUN: llvm-readobj --coff-basereloc out-hyb.dll | FileCheck --check-prefix=BASERELOC %s
// BASERELOC: BaseReloc [
Expand Down
Loading