mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-09-20 04:10:18 +02:00
Merge pull request #429 from redstar/moduleflags
Implement pragma(lib) on Windows using module metadata.
This commit is contained in:
+33
-7
@@ -24,6 +24,7 @@
|
|||||||
#include "gen/utils.h"
|
#include "gen/utils.h"
|
||||||
#include "ir/irtype.h"
|
#include "ir/irtype.h"
|
||||||
#include "ir/irvar.h"
|
#include "ir/irvar.h"
|
||||||
|
#include "llvm/ADT/SmallString.h"
|
||||||
|
|
||||||
/* ================================================================== */
|
/* ================================================================== */
|
||||||
|
|
||||||
@@ -384,13 +385,38 @@ void PragmaDeclaration::codegen(IRState *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t const n = nameLen + 3;
|
#if LDC_LLVM_VER >= 303
|
||||||
char *arg = static_cast<char *>(mem.malloc(n));
|
// With LLVM 3.3 or later we can place the library name in the object
|
||||||
arg[0] = '-';
|
// file. This seems to be supported only on Windows.
|
||||||
arg[1] = 'l';
|
if (global.params.targetTriple.getOS() == llvm::Triple::Win32)
|
||||||
memcpy(arg + 2, se->string, nameLen);
|
{
|
||||||
arg[n-1] = 0;
|
llvm::SmallString<24> LibName(llvm::StringRef(static_cast<const char *>(se->string), nameLen));
|
||||||
global.params.linkswitches->push(arg);
|
|
||||||
|
// Win32: /DEFAULTLIB:"curl"
|
||||||
|
if (LibName.endswith(".a"))
|
||||||
|
LibName = LibName.substr(0, LibName.size()-2);
|
||||||
|
if (LibName.endswith(".lib"))
|
||||||
|
LibName = LibName.substr(0, LibName.size()-4);
|
||||||
|
llvm::SmallString<24> tmp("/DEFAULTLIB:\"");
|
||||||
|
tmp.append(LibName);
|
||||||
|
tmp.append("\"");
|
||||||
|
LibName = tmp;
|
||||||
|
|
||||||
|
// Embedd library name as linker option in object file
|
||||||
|
llvm::Value *Value = llvm::MDString::get(gIR->context(), LibName);
|
||||||
|
gIR->LinkerMetadataArgs.push_back(llvm::MDNode::get(gIR->context(), Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
size_t const n = nameLen + 3;
|
||||||
|
char *arg = static_cast<char *>(mem.malloc(n));
|
||||||
|
arg[0] = '-';
|
||||||
|
arg[1] = 'l';
|
||||||
|
memcpy(arg + 2, se->string, nameLen);
|
||||||
|
arg[n-1] = 0;
|
||||||
|
global.params.linkswitches->push(arg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AttribDeclaration::codegen(p);
|
AttribDeclaration::codegen(p);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,6 +203,11 @@ struct IRState
|
|||||||
|
|
||||||
/// Whether to emit array bounds checking in the current function.
|
/// Whether to emit array bounds checking in the current function.
|
||||||
bool emitArrayBoundsChecks();
|
bool emitArrayBoundsChecks();
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 303
|
||||||
|
/// Vector of options passed to the linker as metadata in object file.
|
||||||
|
llvm::SmallVector<llvm::Value *, 5> LinkerMetadataArgs;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
@@ -414,6 +414,12 @@ llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context)
|
|||||||
// generate ModuleInfo
|
// generate ModuleInfo
|
||||||
genmoduleinfo();
|
genmoduleinfo();
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 303
|
||||||
|
// Add the linker options metadata flag.
|
||||||
|
ir.module->addModuleFlag(llvm::Module::AppendUnique, "Linker Options",
|
||||||
|
llvm::MDNode::get(ir.context(), ir.LinkerMetadataArgs));
|
||||||
|
#endif
|
||||||
|
|
||||||
// verify the llvm
|
// verify the llvm
|
||||||
verifyModule(*ir.module);
|
verifyModule(*ir.module);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user