Skip to content

Commit adf6422

Browse files
authored
Merge pull request #9084 from al45tair/eng/PR-133473673-20240723
[RuntimeDyld][Windows] Allocate space for dllimport things.
2 parents f64690c + 17eea8f commit adf6422

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,12 @@ unsigned RuntimeDyldImpl::computeSectionStubBufSize(const ObjectFile &Obj,
690690
if (!(RelSecI == Section))
691691
continue;
692692

693-
for (const RelocationRef &Reloc : SI->relocations())
693+
for (const RelocationRef &Reloc : SI->relocations()) {
694694
if (relocationNeedsStub(Reloc))
695695
StubBufSize += StubSize;
696+
if (relocationNeedsDLLImportStub(Reloc))
697+
StubBufSize = sizeAfterAddingDLLImportStub(StubBufSize);
698+
}
696699
}
697700

698701
// Get section data size and alignment

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,14 @@ bool RuntimeDyldCOFF::isCompatibleFile(const object::ObjectFile &Obj) const {
119119
return Obj.isCOFF();
120120
}
121121

122+
bool RuntimeDyldCOFF::relocationNeedsDLLImportStub(
123+
const RelocationRef &R) const {
124+
object::symbol_iterator Symbol = R.getSymbol();
125+
Expected<StringRef> TargetNameOrErr = Symbol->getName();
126+
if (!TargetNameOrErr)
127+
return false;
128+
129+
return TargetNameOrErr->startswith(getImportSymbolPrefix());
130+
}
131+
122132
} // namespace llvm

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_RUNTIME_DYLD_COFF_H
1515

1616
#include "RuntimeDyldImpl.h"
17+
#include "llvm/Support/MathExtras.h"
1718

1819
#define DEBUG_TYPE "dyld"
1920

@@ -49,6 +50,12 @@ class RuntimeDyldCOFF : public RuntimeDyldImpl {
4950

5051
static constexpr StringRef getImportSymbolPrefix() { return "__imp_"; }
5152

53+
bool relocationNeedsDLLImportStub(const RelocationRef &R) const;
54+
55+
unsigned sizeAfterAddingDLLImportStub(unsigned Size) const {
56+
return alignTo(Size, PointerSize) + PointerSize;
57+
}
58+
5259
private:
5360
unsigned PointerSize;
5461
uint32_t PointerReloc;

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,16 @@ class RuntimeDyldImpl {
455455
return true; // Conservative answer
456456
}
457457

458+
// Return true if the relocation R may require allocating a DLL import stub.
459+
virtual bool relocationNeedsDLLImportStub(const RelocationRef &R) const {
460+
return false;
461+
}
462+
463+
// Add the size of a DLL import stub to the buffer size
464+
virtual unsigned sizeAfterAddingDLLImportStub(unsigned Size) const {
465+
return Size;
466+
}
467+
458468
public:
459469
RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr,
460470
JITSymbolResolver &Resolver)

0 commit comments

Comments
 (0)