Skip to content

Commit

Permalink
driver: Support code for shared library collision detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnadlinger committed Jul 9, 2014
1 parent fc7acc4 commit 4abdec7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 31 additions & 1 deletion driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,27 @@ void genCmain(Scope *sc)
rootHasMain = sc->module;
}

/// Emits a declaration for the given symbol, which is assumed to be of type
/// i8*, and defines a second globally visible i8* that contains the address
/// of the first symbol.
static void emitSymbolAddrGlobal(llvm::Module& lm, const char* symbolName,
const char* addrName)
{
llvm::Type* voidPtr = llvm::PointerType::get(
llvm::Type::getInt8Ty(lm.getContext()), 0);
llvm::GlobalVariable* targetSymbol = new llvm::GlobalVariable(
lm, voidPtr, false, llvm::GlobalValue::ExternalLinkage,
NULL, symbolName
);
new llvm::GlobalVariable(lm, voidPtr, false,
llvm::GlobalValue::ExternalLinkage,
llvm::ConstantExpr::getBitCast(targetSymbol, voidPtr),
addrName
);
}

/// Adds the __entrypoint module and related support code into the given LLVM
/// module. This assumes that genCmain() has already been called.
static void emitEntryPointInto(llvm::Module* lm)
{
assert(entrypoint && "Entry point Dmodule has not been generated.");
Expand All @@ -856,7 +877,16 @@ static void emitEntryPointInto(llvm::Module* lm)
llvm::Linker linker("ldc", lm);
#endif

llvm::Module* entryModule = entrypoint->genLLVMModule(lm->getContext());
llvm::LLVMContext& context = lm->getContext();
llvm::Module* entryModule = entrypoint->genLLVMModule(context);

// On Linux, strongly define the excecutabe BSS bracketing symbols in the
// main module for druntime use (see rt.sections_linux).
if (global.params.isLinux)
{
emitSymbolAddrGlobal(*entryModule, "__bss_start", "_d_execBssBegAddr");
emitSymbolAddrGlobal(*entryModule, "_end", "_d_execBssEndAddr");
}

std::string linkError;
#if LDC_LLVM_VER >= 303
Expand Down
2 changes: 1 addition & 1 deletion runtime/druntime
Submodule druntime updated 1 files
+35 −0 src/rt/sections_linux.d

0 comments on commit 4abdec7

Please sign in to comment.