Skip to content

[RuntimeDyld][Windows] Allocate space for dllimport things. #102586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,12 @@ unsigned RuntimeDyldImpl::computeSectionStubBufSize(const ObjectFile &Obj,
if (!(RelSecI == Section))
continue;

for (const RelocationRef &Reloc : SI->relocations())
for (const RelocationRef &Reloc : SI->relocations()) {
if (relocationNeedsStub(Reloc))
StubBufSize += StubSize;
if (relocationNeedsDLLImportStub(Reloc))
StubBufSize = sizeAfterAddingDLLImportStub(StubBufSize);
}
}

// Get section data size and alignment
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,14 @@ bool RuntimeDyldCOFF::isCompatibleFile(const object::ObjectFile &Obj) const {
return Obj.isCOFF();
}

bool RuntimeDyldCOFF::relocationNeedsDLLImportStub(
const RelocationRef &R) const {
object::symbol_iterator Symbol = R.getSymbol();
Expected<StringRef> TargetNameOrErr = Symbol->getName();
if (!TargetNameOrErr)
return false;

return TargetNameOrErr->starts_with(getImportSymbolPrefix());
}

} // namespace llvm
7 changes: 7 additions & 0 deletions llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define LLVM_RUNTIME_DYLD_COFF_H

#include "RuntimeDyldImpl.h"
#include "llvm/Support/MathExtras.h"

#define DEBUG_TYPE "dyld"

Expand Down Expand Up @@ -49,6 +50,12 @@ class RuntimeDyldCOFF : public RuntimeDyldImpl {

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

bool relocationNeedsDLLImportStub(const RelocationRef &R) const;

unsigned sizeAfterAddingDLLImportStub(unsigned Size) const {
return alignTo(Size, PointerSize) + PointerSize;
}

private:
unsigned PointerSize;
uint32_t PointerReloc;
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,16 @@ class RuntimeDyldImpl {
return true; // Conservative answer
}

// Return true if the relocation R may require allocating a DLL import stub.
virtual bool relocationNeedsDLLImportStub(const RelocationRef &R) const {
return false;
}

// Add the size of a DLL import stub to the buffer size
virtual unsigned sizeAfterAddingDLLImportStub(unsigned Size) const {
return Size;
}

public:
RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr,
JITSymbolResolver &Resolver)
Expand Down
Loading