mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 07:30:43 +03:00
Map export
visibility to LLVM DLL storage classes
Compatible with DMD, but restricted to Windows and functions only. `export` functions with bodies get the dllexport attribute and will be exported if the containing object is pulled in when linking. Body-less `export` functions get the dllimport attribute and will be accessed via an import table indirection, set up at runtime by the OS. This is a temporary solution, the proper fix is a pending DMD PR, after which LDC will need to be adapted.
This commit is contained in:
parent
8a2a6c1e7f
commit
67d5fe5624
6 changed files with 60 additions and 1 deletions
|
@ -538,6 +538,12 @@ void DtoDeclareFunction(FuncDeclaration *fdecl) {
|
|||
|
||||
func->setCallingConv(gABI->callingConv(func->getFunctionType(), link, fdecl));
|
||||
|
||||
if (global.params.isWindows && fdecl->isExport()) {
|
||||
func->setDLLStorageClass(fdecl->isImportedSymbol()
|
||||
? LLGlobalValue::DLLImportStorageClass
|
||||
: LLGlobalValue::DLLExportStorageClass);
|
||||
}
|
||||
|
||||
IF_LOG Logger::cout() << "func = " << *func << std::endl;
|
||||
|
||||
// add func to IRFunc
|
||||
|
@ -906,11 +912,12 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
|
|||
|
||||
const auto f = static_cast<TypeFunction *>(fd->type->toBasetype());
|
||||
IrFuncTy &irFty = irFunc->irFty;
|
||||
llvm::Function *func = irFunc->func;;
|
||||
llvm::Function *func = irFunc->func;
|
||||
|
||||
const auto lwc = lowerFuncLinkage(fd);
|
||||
if (linkageAvailableExternally) {
|
||||
func->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
|
||||
func->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
|
||||
// Assert that we are not overriding a linkage type that disallows inlining
|
||||
assert(lwc.first != llvm::GlobalValue::WeakAnyLinkage &&
|
||||
lwc.first != llvm::GlobalValue::ExternalWeakLinkage &&
|
||||
|
@ -919,6 +926,8 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
|
|||
setLinkage(lwc, func);
|
||||
}
|
||||
|
||||
assert(!func->hasDLLImportStorageClass());
|
||||
|
||||
// On x86_64, always set 'uwtable' for System V ABI compatibility.
|
||||
// TODO: Find a better place for this.
|
||||
// TODO: Is this required for Win64 as well?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue