Skip to content

Commit 7144325

Browse files
authored
[LLD][COFF] Prepare both load configs on ARM64X (#120326)
1 parent b34ed25 commit 7144325

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

lld/COFF/Writer.cpp

+19-15
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ class Writer {
282282
uint32_t getSizeOfInitializedData();
283283

284284
void prepareLoadConfig();
285-
template <typename T> void prepareLoadConfig(T *loadConfig);
285+
template <typename T>
286+
void prepareLoadConfig(SymbolTable &symtab, T *loadConfig);
286287

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

26392640
void Writer::prepareLoadConfig() {
2640-
if (!ctx.symtab.loadConfigSym)
2641-
return;
2641+
ctx.forEachSymtab([&](SymbolTable &symtab) {
2642+
if (!symtab.loadConfigSym)
2643+
return;
26422644

2643-
OutputSection *sec =
2644-
ctx.getOutputSection(ctx.symtab.loadConfigSym->getChunk());
2645-
uint8_t *secBuf = buffer->getBufferStart() + sec->getFileOff();
2646-
uint8_t *symBuf =
2647-
secBuf + (ctx.symtab.loadConfigSym->getRVA() - sec->getRVA());
2645+
OutputSection *sec = ctx.getOutputSection(symtab.loadConfigSym->getChunk());
2646+
uint8_t *secBuf = buffer->getBufferStart() + sec->getFileOff();
2647+
uint8_t *symBuf = secBuf + (symtab.loadConfigSym->getRVA() - sec->getRVA());
26482648

2649-
if (ctx.config.is64())
2650-
prepareLoadConfig(reinterpret_cast<coff_load_configuration64 *>(symBuf));
2651-
else
2652-
prepareLoadConfig(reinterpret_cast<coff_load_configuration32 *>(symBuf));
2649+
if (ctx.config.is64())
2650+
prepareLoadConfig(symtab,
2651+
reinterpret_cast<coff_load_configuration64 *>(symBuf));
2652+
else
2653+
prepareLoadConfig(symtab,
2654+
reinterpret_cast<coff_load_configuration32 *>(symBuf));
2655+
});
26532656
}
26542657

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

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

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

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

lld/test/COFF/arm64x-loadconfig.s

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// RUN: llvm-mc -filetype=obj -triple=aarch64-windows test.s -o test.obj
55
// RUN: llvm-mc -filetype=obj -triple=aarch64-windows loadconfig.s -o loadconfig.obj
66
// RUN: llvm-mc -filetype=obj -triple=aarch64-windows loadconfig-short.s -o loadconfig-short.obj
7+
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows loadconfig-short.s -o loadconfig-short-arm64ec.obj
78

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

@@ -43,6 +44,7 @@
4344
// HEADERS-NEXT: VirtualSize: 0x38
4445

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

4850
#--- test.s

0 commit comments

Comments
 (0)