Skip to content

Commit

Permalink
[LLD][COFF] Prepare both load configs on ARM64X (#120326)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjacek authored Dec 29, 2024
1 parent b34ed25 commit 7144325
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
34 changes: 19 additions & 15 deletions lld/COFF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ class Writer {
uint32_t getSizeOfInitializedData();

void prepareLoadConfig();
template <typename T> void prepareLoadConfig(T *loadConfig);
template <typename T>
void prepareLoadConfig(SymbolTable &symtab, T *loadConfig);

std::unique_ptr<FileOutputBuffer> &buffer;
std::map<PartialSectionKey, PartialSection *> partialSections;
Expand Down Expand Up @@ -2637,22 +2638,25 @@ void Writer::fixTlsAlignment() {
}

void Writer::prepareLoadConfig() {
if (!ctx.symtab.loadConfigSym)
return;
ctx.forEachSymtab([&](SymbolTable &symtab) {
if (!symtab.loadConfigSym)
return;

OutputSection *sec =
ctx.getOutputSection(ctx.symtab.loadConfigSym->getChunk());
uint8_t *secBuf = buffer->getBufferStart() + sec->getFileOff();
uint8_t *symBuf =
secBuf + (ctx.symtab.loadConfigSym->getRVA() - sec->getRVA());
OutputSection *sec = ctx.getOutputSection(symtab.loadConfigSym->getChunk());
uint8_t *secBuf = buffer->getBufferStart() + sec->getFileOff();
uint8_t *symBuf = secBuf + (symtab.loadConfigSym->getRVA() - sec->getRVA());

if (ctx.config.is64())
prepareLoadConfig(reinterpret_cast<coff_load_configuration64 *>(symBuf));
else
prepareLoadConfig(reinterpret_cast<coff_load_configuration32 *>(symBuf));
if (ctx.config.is64())
prepareLoadConfig(symtab,
reinterpret_cast<coff_load_configuration64 *>(symBuf));
else
prepareLoadConfig(symtab,
reinterpret_cast<coff_load_configuration32 *>(symBuf));
});
}

template <typename T> void Writer::prepareLoadConfig(T *loadConfig) {
template <typename T>
void Writer::prepareLoadConfig(SymbolTable &symtab, T *loadConfig) {
size_t loadConfigSize = loadConfig->Size;

#define RETURN_IF_NOT_CONTAINS(field) \
Expand All @@ -2665,12 +2669,12 @@ template <typename T> void Writer::prepareLoadConfig(T *loadConfig) {
if (loadConfigSize >= offsetof(T, field) + sizeof(T::field))

#define CHECK_VA(field, sym) \
if (auto *s = dyn_cast<DefinedSynthetic>(ctx.symtab.findUnderscore(sym))) \
if (auto *s = dyn_cast<DefinedSynthetic>(symtab.findUnderscore(sym))) \
if (loadConfig->field != ctx.config.imageBase + s->getRVA()) \
Warn(ctx) << #field " not set correctly in '_load_config_used'";

#define CHECK_ABSOLUTE(field, sym) \
if (auto *s = dyn_cast<DefinedAbsolute>(ctx.symtab.findUnderscore(sym))) \
if (auto *s = dyn_cast<DefinedAbsolute>(symtab.findUnderscore(sym))) \
if (loadConfig->field != s->getVA()) \
Warn(ctx) << #field " not set correctly in '_load_config_used'";

Expand Down
2 changes: 2 additions & 0 deletions lld/test/COFF/arm64x-loadconfig.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: llvm-mc -filetype=obj -triple=aarch64-windows test.s -o test.obj
// RUN: llvm-mc -filetype=obj -triple=aarch64-windows loadconfig.s -o loadconfig.obj
// RUN: llvm-mc -filetype=obj -triple=aarch64-windows loadconfig-short.s -o loadconfig-short.obj
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows loadconfig-short.s -o loadconfig-short-arm64ec.obj

// RUN: lld-link -machine:arm64x -out:out.dll -dll -noentry loadconfig.obj test.obj

Expand Down Expand Up @@ -43,6 +44,7 @@
// HEADERS-NEXT: VirtualSize: 0x38

// RUN: lld-link -machine:arm64x -out:out-short.dll -dll -noentry loadconfig-short.obj 2>&1 | FileCheck --check-prefix=WARN-RELOC-SIZE %s
// RUN: lld-link -machine:arm64x -out:out-short.dll -dll -noentry loadconfig-short-arm64ec.obj 2>&1 | FileCheck --check-prefix=WARN-RELOC-SIZE %s
// WARN-RELOC-SIZE: lld-link: warning: '_load_config_used' structure too small to include dynamic relocations

#--- test.s
Expand Down

0 comments on commit 7144325

Please sign in to comment.