Skip to content

Commit bdfd780

Browse files
authored
[RuntimeDyld][Windows] Allocate space for dllimport things. (#106958)
We weren't taking account of the space we require in the stubs for things that are dllimported, and as a result we could hit the assertion failure for running out of stub space. Fix that. Also add a couple of `override` specifiers that were missing last time (#102586). rdar://133473673
1 parent e90b219 commit bdfd780

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->starts_with(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
namespace llvm {
1920

@@ -45,6 +46,12 @@ class RuntimeDyldCOFF : public RuntimeDyldImpl {
4546

4647
static constexpr StringRef getImportSymbolPrefix() { return "__imp_"; }
4748

49+
bool relocationNeedsDLLImportStub(const RelocationRef &R) const override;
50+
51+
unsigned sizeAfterAddingDLLImportStub(unsigned Size) const override {
52+
return alignTo(Size, PointerSize) + PointerSize;
53+
}
54+
4855
private:
4956
unsigned PointerSize;
5057
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)