Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f2649c2

Browse files
authored
Merge pull request swiftlang#9080 from al45tair/eng/PR-133473673-6.0
[RuntimeDyld][Windows] Allocate space for dllimport things.
2 parents 6f66b44 + 3271621 commit f2649c2

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

+4-1
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

+10
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,14 @@ bool RuntimeDyldCOFF::isCompatibleFile(const object::ObjectFile &Obj) const {
118118
return Obj.isCOFF();
119119
}
120120

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

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h

+7
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

+10
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,16 @@ class RuntimeDyldImpl {
449449
return true; // Conservative answer
450450
}
451451

452+
// Return true if the relocation R may require allocating a DLL import stub.
453+
virtual bool relocationNeedsDLLImportStub(const RelocationRef &R) const {
454+
return false;
455+
}
456+
457+
// Add the size of a DLL import stub to the buffer size
458+
virtual unsigned sizeAfterAddingDLLImportStub(unsigned Size) const {
459+
return Size;
460+
}
461+
452462
public:
453463
RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr,
454464
JITSymbolResolver &Resolver)

0 commit comments

Comments
 (0)