mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 17:43:35 +03:00
Let TargetABI fix up LLVM mangles for more special symbols
For ModuleInfos, ModuleRefs, InterfaceInfos, interface vtables & thunks.
This commit is contained in:
parent
0b28925e9a
commit
c9a3be1295
12 changed files with 134 additions and 79 deletions
|
@ -522,16 +522,16 @@ void DtoDeclareFunction(FuncDeclaration *fdecl) {
|
||||||
const auto link = forceC ? LINKc : f->linkage;
|
const auto link = forceC ? LINKc : f->linkage;
|
||||||
|
|
||||||
// mangled name
|
// mangled name
|
||||||
std::string mangledName = getMangledName(fdecl, link);
|
const auto llMangle = DtoMangledName(fdecl, link);
|
||||||
|
|
||||||
// construct function
|
// construct function
|
||||||
LLFunctionType *functype = DtoFunctionType(fdecl);
|
LLFunctionType *functype = DtoFunctionType(fdecl);
|
||||||
LLFunction *func = vafunc ? vafunc : gIR->module.getFunction(mangledName);
|
LLFunction *func = vafunc ? vafunc : gIR->module.getFunction(llMangle);
|
||||||
if (!func) {
|
if (!func) {
|
||||||
// All function declarations are "external" - any other linkage type
|
// All function declarations are "external" - any other linkage type
|
||||||
// is set when actually defining the function.
|
// is set when actually defining the function.
|
||||||
func = LLFunction::Create(functype, llvm::GlobalValue::ExternalLinkage,
|
func = LLFunction::Create(functype, llvm::GlobalValue::ExternalLinkage,
|
||||||
mangledName, &gIR->module);
|
llMangle, &gIR->module);
|
||||||
} else if (func->getFunctionType() != functype) {
|
} else if (func->getFunctionType() != functype) {
|
||||||
error(fdecl->loc,
|
error(fdecl->loc,
|
||||||
"Function type does not match previously declared "
|
"Function type does not match previously declared "
|
||||||
|
|
|
@ -834,7 +834,7 @@ void DtoResolveVariable(VarDeclaration *vd) {
|
||||||
if (gIR->dmodule) {
|
if (gIR->dmodule) {
|
||||||
vd->ir->setInitialized();
|
vd->ir->setInitialized();
|
||||||
}
|
}
|
||||||
std::string llName(getMangledName(vd));
|
const auto llMangle = DtoMangledName(vd);
|
||||||
|
|
||||||
// Since the type of a global must exactly match the type of its
|
// Since the type of a global must exactly match the type of its
|
||||||
// initializer, we cannot know the type until after we have emitted the
|
// initializer, we cannot know the type until after we have emitted the
|
||||||
|
@ -855,7 +855,7 @@ void DtoResolveVariable(VarDeclaration *vd) {
|
||||||
|
|
||||||
llvm::GlobalVariable *gvar =
|
llvm::GlobalVariable *gvar =
|
||||||
getOrCreateGlobal(vd->loc, gIR->module, DtoMemType(vd->type), isLLConst,
|
getOrCreateGlobal(vd->loc, gIR->module, DtoMemType(vd->type), isLLConst,
|
||||||
linkage, nullptr, llName, vd->isThreadlocal());
|
linkage, nullptr, llMangle, vd->isThreadlocal());
|
||||||
getIrGlobal(vd)->value = gvar;
|
getIrGlobal(vd)->value = gvar;
|
||||||
|
|
||||||
// Set the alignment (it is important not to use type->alignsize because
|
// Set the alignment (it is important not to use type->alignsize because
|
||||||
|
|
|
@ -97,8 +97,8 @@ std::string hashSymbolName(llvm::StringRef name, Dsymbol *symb) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getMangledName(FuncDeclaration *fdecl, LINK link) {
|
std::string DtoMangledName(FuncDeclaration *fdecl, LINK link) {
|
||||||
std::string mangledName(mangleExact(fdecl));
|
std::string mangledName = mangleExact(fdecl);
|
||||||
|
|
||||||
// Hash the name if necessary
|
// Hash the name if necessary
|
||||||
if (((link == LINKd) || (link == LINKdefault)) &&
|
if (((link == LINKd) || (link == LINKdefault)) &&
|
||||||
|
@ -111,22 +111,30 @@ std::string getMangledName(FuncDeclaration *fdecl, LINK link) {
|
||||||
|
|
||||||
// TODO: Cache the result?
|
// TODO: Cache the result?
|
||||||
|
|
||||||
return gABI->mangleFunctionForLLVM(std::move(mangledName), link);
|
return DtoMangledFuncName(std::move(mangledName), link);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getMangledName(VarDeclaration *vd) {
|
std::string DtoMangledName(VarDeclaration *vd) {
|
||||||
|
OutBuffer mangleBuf;
|
||||||
|
mangleToBuffer(vd, &mangleBuf);
|
||||||
|
|
||||||
// TODO: is hashing of variable names necessary?
|
// TODO: is hashing of variable names necessary?
|
||||||
|
|
||||||
// TODO: Cache the result?
|
// TODO: Cache the result?
|
||||||
|
|
||||||
OutBuffer mangleBuf;
|
return DtoMangledVarName(mangleBuf.peekString(), vd->linkage);
|
||||||
mangleToBuffer(vd, &mangleBuf);
|
}
|
||||||
|
|
||||||
return gABI->mangleVariableForLLVM(mangleBuf.peekString(), vd->linkage);
|
std::string DtoMangledFuncName(std::string baseMangle, LINK link) {
|
||||||
|
return gABI->mangleFunctionForLLVM(std::move(baseMangle), link);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DtoMangledVarName(std::string baseMangle, LINK link) {
|
||||||
|
return gABI->mangleVariableForLLVM(std::move(baseMangle), link);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::string getMangledAggregateName(AggregateDeclaration *ad,
|
std::string DtoMangledAggregateName(AggregateDeclaration *ad,
|
||||||
const char *suffix) {
|
const char *suffix) {
|
||||||
std::string ret = "_D";
|
std::string ret = "_D";
|
||||||
|
|
||||||
|
@ -143,20 +151,41 @@ std::string getMangledAggregateName(AggregateDeclaration *ad,
|
||||||
if (suffix)
|
if (suffix)
|
||||||
ret += suffix;
|
ret += suffix;
|
||||||
|
|
||||||
return gABI->mangleVariableForLLVM(std::move(ret), LINKd);
|
return DtoMangledVarName(std::move(ret), LINKd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getMangledInitSymbolName(AggregateDeclaration *aggrdecl) {
|
std::string DtoMangledInitSymbolName(AggregateDeclaration *aggrdecl) {
|
||||||
return getMangledAggregateName(aggrdecl, "6__initZ");
|
return DtoMangledAggregateName(aggrdecl, "6__initZ");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getMangledVTableSymbolName(AggregateDeclaration *aggrdecl) {
|
std::string DtoMangledVTableSymbolName(AggregateDeclaration *aggrdecl) {
|
||||||
return getMangledAggregateName(aggrdecl, "6__vtblZ");
|
return DtoMangledAggregateName(aggrdecl, "6__vtblZ");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getMangledClassInfoSymbolName(AggregateDeclaration *aggrdecl) {
|
std::string DtoMangledClassInfoSymbolName(AggregateDeclaration *aggrdecl) {
|
||||||
const char *suffix =
|
const char *suffix =
|
||||||
aggrdecl->isInterfaceDeclaration() ? "11__InterfaceZ" : "7__ClassZ";
|
aggrdecl->isInterfaceDeclaration() ? "11__InterfaceZ" : "7__ClassZ";
|
||||||
return getMangledAggregateName(aggrdecl, suffix);
|
return DtoMangledAggregateName(aggrdecl, suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DtoMangledInterfaceInfosSymbolName(ClassDeclaration *cd) {
|
||||||
|
OutBuffer mangledName;
|
||||||
|
mangledName.writestring("_D");
|
||||||
|
mangleToBuffer(cd, &mangledName);
|
||||||
|
mangledName.writestring("16__interfaceInfosZ");
|
||||||
|
return DtoMangledVarName(mangledName.peekString(), LINKd);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DtoMangledModuleInfoSymbolName(Module *module) {
|
||||||
|
OutBuffer mangledName;
|
||||||
|
mangledName.writestring("_D");
|
||||||
|
mangleToBuffer(module, &mangledName);
|
||||||
|
mangledName.writestring("12__ModuleInfoZ");
|
||||||
|
return DtoMangledVarName(mangledName.peekString(), LINKd);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DtoMangledModuleRefSymbolName(const char *moduleMangle) {
|
||||||
|
return DtoMangledVarName(
|
||||||
|
(llvm::Twine("_D") + moduleMangle + "11__moduleRefZ").str(), LINKd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,29 @@
|
||||||
#include "ddmd/globals.h"
|
#include "ddmd/globals.h"
|
||||||
|
|
||||||
class AggregateDeclaration;
|
class AggregateDeclaration;
|
||||||
|
class ClassDeclaration;
|
||||||
class FuncDeclaration;
|
class FuncDeclaration;
|
||||||
|
class Module;
|
||||||
class VarDeclaration;
|
class VarDeclaration;
|
||||||
|
|
||||||
std::string getMangledName(FuncDeclaration *fdecl, LINK link);
|
/*
|
||||||
std::string getMangledName(VarDeclaration *vd);
|
* These functions return a symbol's LLVM mangle.
|
||||||
|
* LLVM's codegen performs target-specific postprocessing of these LLVM mangles
|
||||||
|
* (for the final object file mangles) unless the LLVM mangle starts with a 0x1
|
||||||
|
* byte. The TargetABI gets a chance to tweak the LLVM mangle.
|
||||||
|
*/
|
||||||
|
|
||||||
std::string getMangledInitSymbolName(AggregateDeclaration *aggrdecl);
|
std::string DtoMangledName(FuncDeclaration *fdecl, LINK link);
|
||||||
std::string getMangledVTableSymbolName(AggregateDeclaration *aggrdecl);
|
std::string DtoMangledName(VarDeclaration *vd);
|
||||||
std::string getMangledClassInfoSymbolName(AggregateDeclaration *aggrdecl);
|
|
||||||
|
std::string DtoMangledFuncName(std::string baseMangle, LINK link);
|
||||||
|
std::string DtoMangledVarName(std::string baseMangle, LINK link);
|
||||||
|
|
||||||
|
std::string DtoMangledInitSymbolName(AggregateDeclaration *aggrdecl);
|
||||||
|
std::string DtoMangledVTableSymbolName(AggregateDeclaration *aggrdecl);
|
||||||
|
std::string DtoMangledClassInfoSymbolName(AggregateDeclaration *aggrdecl);
|
||||||
|
std::string DtoMangledInterfaceInfosSymbolName(ClassDeclaration *cd);
|
||||||
|
std::string DtoMangledModuleInfoSymbolName(Module *module);
|
||||||
|
std::string DtoMangledModuleRefSymbolName(const char *moduleMangle);
|
||||||
|
|
||||||
#endif // LDC_GEN_MANGLING_H
|
#endif // LDC_GEN_MANGLING_H
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "gen/irstate.h"
|
#include "gen/irstate.h"
|
||||||
#include "gen/llvmhelpers.h"
|
#include "gen/llvmhelpers.h"
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
|
#include "gen/mangling.h"
|
||||||
#include "gen/objcgen.h"
|
#include "gen/objcgen.h"
|
||||||
#include "gen/rttibuilder.h"
|
#include "gen/rttibuilder.h"
|
||||||
#include "ir/irfunction.h"
|
#include "ir/irfunction.h"
|
||||||
|
@ -56,10 +57,10 @@ llvm::Function *buildForwarderFunction(
|
||||||
const auto fnTy =
|
const auto fnTy =
|
||||||
LLFunctionType::get(LLType::getVoidTy(gIR->context()), {}, false);
|
LLFunctionType::get(LLType::getVoidTy(gIR->context()), {}, false);
|
||||||
|
|
||||||
std::string const symbolName = gABI->mangleFunctionForLLVM(name, LINKd);
|
const auto llMangle = DtoMangledFuncName(name, LINKd);
|
||||||
assert(gIR->module.getFunction(symbolName) == NULL);
|
assert(gIR->module.getFunction(llMangle) == NULL);
|
||||||
llvm::Function *fn = llvm::Function::Create(
|
llvm::Function *fn = llvm::Function::Create(
|
||||||
fnTy, llvm::GlobalValue::InternalLinkage, symbolName, &gIR->module);
|
fnTy, llvm::GlobalValue::InternalLinkage, llMangle, &gIR->module);
|
||||||
fn->setCallingConv(gABI->callingConv(LINKd));
|
fn->setCallingConv(gABI->callingConv(LINKd));
|
||||||
|
|
||||||
// Emit the body, consisting of...
|
// Emit the body, consisting of...
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
#include "gen/llvmhelpers.h"
|
#include "gen/llvmhelpers.h"
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
|
#include "gen/mangling.h"
|
||||||
#include "gen/moduleinfo.h"
|
#include "gen/moduleinfo.h"
|
||||||
#include "gen/optimizer.h"
|
#include "gen/optimizer.h"
|
||||||
#include "gen/runtime.h"
|
#include "gen/runtime.h"
|
||||||
|
@ -145,8 +146,9 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle,
|
||||||
|
|
||||||
// build a function that registers the moduleinfo in the global moduleinfo
|
// build a function that registers the moduleinfo in the global moduleinfo
|
||||||
// linked list
|
// linked list
|
||||||
LLFunction *ctor = LLFunction::Create(fty, LLGlobalValue::InternalLinkage,
|
LLFunction *ctor =
|
||||||
fname, &gIR->module);
|
LLFunction::Create(fty, LLGlobalValue::InternalLinkage,
|
||||||
|
DtoMangledFuncName(fname, LINKd), &gIR->module);
|
||||||
|
|
||||||
// provide the default initializer
|
// provide the default initializer
|
||||||
LLStructType *modulerefTy = DtoModuleReferenceType();
|
LLStructType *modulerefTy = DtoModuleReferenceType();
|
||||||
|
@ -158,20 +160,19 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle,
|
||||||
modulerefTy, llvm::ArrayRef<LLConstant *>(mrefvalues));
|
modulerefTy, llvm::ArrayRef<LLConstant *>(mrefvalues));
|
||||||
|
|
||||||
// create the ModuleReference node for this module
|
// create the ModuleReference node for this module
|
||||||
std::string thismrefname = "_D";
|
const auto thismrefLLMangle = DtoMangledModuleRefSymbolName(moduleMangle);
|
||||||
thismrefname += moduleMangle;
|
|
||||||
thismrefname += "11__moduleRefZ";
|
|
||||||
Loc loc;
|
Loc loc;
|
||||||
LLGlobalVariable *thismref = getOrCreateGlobal(
|
LLGlobalVariable *thismref = getOrCreateGlobal(
|
||||||
loc, gIR->module, modulerefTy, false, LLGlobalValue::InternalLinkage,
|
loc, gIR->module, modulerefTy, false, LLGlobalValue::InternalLinkage,
|
||||||
thismrefinit, thismrefname);
|
thismrefinit, thismrefLLMangle);
|
||||||
// make sure _Dmodule_ref is declared
|
// make sure _Dmodule_ref is declared
|
||||||
LLConstant *mref = gIR->module.getNamedGlobal("_Dmodule_ref");
|
const auto mrefLLMangle = DtoMangledVarName("_Dmodule_ref", LINKc);
|
||||||
|
LLConstant *mref = gIR->module.getNamedGlobal(mrefLLMangle);
|
||||||
LLType *modulerefPtrTy = getPtrToType(modulerefTy);
|
LLType *modulerefPtrTy = getPtrToType(modulerefTy);
|
||||||
if (!mref) {
|
if (!mref) {
|
||||||
mref = new LLGlobalVariable(gIR->module, modulerefPtrTy, false,
|
mref = new LLGlobalVariable(gIR->module, modulerefPtrTy, false,
|
||||||
LLGlobalValue::ExternalLinkage, nullptr,
|
LLGlobalValue::ExternalLinkage, nullptr,
|
||||||
"_Dmodule_ref");
|
mrefLLMangle);
|
||||||
}
|
}
|
||||||
mref = DtoBitCast(mref, getPtrToType(modulerefPtrTy));
|
mref = DtoBitCast(mref, getPtrToType(modulerefPtrTy));
|
||||||
|
|
||||||
|
@ -342,14 +343,13 @@ void emitModuleRefToSection(RegistryStyle style, std::string moduleMangle,
|
||||||
|
|
||||||
llvm::Type *const moduleInfoPtrTy = DtoPtrToType(Module::moduleinfo->type);
|
llvm::Type *const moduleInfoPtrTy = DtoPtrToType(Module::moduleinfo->type);
|
||||||
|
|
||||||
std::string thismrefname = "_D";
|
const auto thismrefLLMangle =
|
||||||
thismrefname += moduleMangle;
|
DtoMangledModuleRefSymbolName(moduleMangle.c_str());
|
||||||
thismrefname += "11__moduleRefZ";
|
|
||||||
auto thismref = new llvm::GlobalVariable(
|
auto thismref = new llvm::GlobalVariable(
|
||||||
gIR->module, moduleInfoPtrTy,
|
gIR->module, moduleInfoPtrTy,
|
||||||
false, // FIXME: mRelocModel != llvm::Reloc::PIC_
|
false, // FIXME: mRelocModel != llvm::Reloc::PIC_
|
||||||
llvm::GlobalValue::LinkOnceODRLinkage,
|
llvm::GlobalValue::LinkOnceODRLinkage,
|
||||||
DtoBitCast(thisModuleInfo, moduleInfoPtrTy), thismrefname);
|
DtoBitCast(thisModuleInfo, moduleInfoPtrTy), thismrefLLMangle);
|
||||||
thismref->setSection((style == RegistryStyle::sectionDarwin) ? "__DATA,.minfo"
|
thismref->setSection((style == RegistryStyle::sectionDarwin) ? "__DATA,.minfo"
|
||||||
: "__minfo");
|
: "__minfo");
|
||||||
gIR->usedArray.push_back(thismref);
|
gIR->usedArray.push_back(thismref);
|
||||||
|
@ -544,8 +544,9 @@ void addCoverageAnalysis(Module *m) {
|
||||||
|
|
||||||
LLFunctionType *ctorTy =
|
LLFunctionType *ctorTy =
|
||||||
LLFunctionType::get(LLType::getVoidTy(gIR->context()), {}, false);
|
LLFunctionType::get(LLType::getVoidTy(gIR->context()), {}, false);
|
||||||
ctor = LLFunction::Create(ctorTy, LLGlobalValue::InternalLinkage, ctorname,
|
ctor =
|
||||||
&gIR->module);
|
LLFunction::Create(ctorTy, LLGlobalValue::InternalLinkage,
|
||||||
|
DtoMangledFuncName(ctorname, LINKd), &gIR->module);
|
||||||
ctor->setCallingConv(gABI->callingConv(LINKd));
|
ctor->setCallingConv(gABI->callingConv(LINKd));
|
||||||
// Set function attributes. See functions.cpp:DtoDefineFunction()
|
// Set function attributes. See functions.cpp:DtoDefineFunction()
|
||||||
if (global.params.targetTriple->getArch() == llvm::Triple::x86_64) {
|
if (global.params.targetTriple->getArch() == llvm::Triple::x86_64) {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
#include "gen/llvmhelpers.h"
|
#include "gen/llvmhelpers.h"
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
|
#include "gen/mangling.h"
|
||||||
#include "gen/tollvm.h"
|
#include "gen/tollvm.h"
|
||||||
#include "ir/irfunction.h"
|
#include "ir/irfunction.h"
|
||||||
#include "ir/irtype.h"
|
#include "ir/irtype.h"
|
||||||
|
@ -707,9 +708,9 @@ static void buildRuntimeModule() {
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// void invariant._d_invariant(Object o)
|
// void invariant._d_invariant(Object o)
|
||||||
createFwdDecl(LINKd, voidTy,
|
createFwdDecl(
|
||||||
{gABI->mangleFunctionForLLVM(
|
LINKd, voidTy,
|
||||||
"_D9invariant12_d_invariantFC6ObjectZv", LINKd)},
|
{DtoMangledFuncName("_D9invariant12_d_invariantFC6ObjectZv", LINKd)},
|
||||||
{objectTy});
|
{objectTy});
|
||||||
|
|
||||||
// void _d_dso_registry(void* data)
|
// void _d_dso_registry(void* data)
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
#include "gen/llvmhelpers.h"
|
#include "gen/llvmhelpers.h"
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
|
#include "gen/mangling.h"
|
||||||
#include "gen/nested.h"
|
#include "gen/nested.h"
|
||||||
#include "gen/optimizer.h"
|
#include "gen/optimizer.h"
|
||||||
#include "gen/pragma.h"
|
#include "gen/pragma.h"
|
||||||
|
@ -1687,8 +1688,8 @@ public:
|
||||||
|
|
||||||
Logger::println("calling class invariant");
|
Logger::println("calling class invariant");
|
||||||
|
|
||||||
const auto fnMangle = gABI->mangleFunctionForLLVM(
|
const auto fnMangle =
|
||||||
"_D9invariant12_d_invariantFC6ObjectZv", LINKd);
|
DtoMangledFuncName("_D9invariant12_d_invariantFC6ObjectZv", LINKd);
|
||||||
const auto fn = getRuntimeFunction(e->loc, gIR->module, fnMangle.c_str());
|
const auto fn = getRuntimeFunction(e->loc, gIR->module, fnMangle.c_str());
|
||||||
|
|
||||||
const auto arg =
|
const auto arg =
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
#include "gen/llvmhelpers.h"
|
#include "gen/llvmhelpers.h"
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
|
#include "gen/mangling.h"
|
||||||
#include "gen/metadata.h"
|
#include "gen/metadata.h"
|
||||||
#include "gen/rttibuilder.h"
|
#include "gen/rttibuilder.h"
|
||||||
#include "gen/runtime.h"
|
#include "gen/runtime.h"
|
||||||
|
@ -592,10 +593,11 @@ void TypeInfoDeclaration_codegen(TypeInfoDeclaration *decl, IRState *p) {
|
||||||
Logger::println("typeinfo mangle: %s", mangled);
|
Logger::println("typeinfo mangle: %s", mangled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto llMangle = DtoMangledVarName(mangled, LINKd);
|
||||||
IrGlobal *irg = getIrGlobal(decl, true);
|
IrGlobal *irg = getIrGlobal(decl, true);
|
||||||
const LinkageWithCOMDAT lwc(LLGlobalValue::ExternalLinkage, false);
|
const LinkageWithCOMDAT lwc(LLGlobalValue::ExternalLinkage, false);
|
||||||
|
|
||||||
irg->value = gIR->module.getGlobalVariable(mangled);
|
irg->value = gIR->module.getGlobalVariable(llMangle);
|
||||||
if (irg->value) {
|
if (irg->value) {
|
||||||
assert(irg->getType()->isStructTy());
|
assert(irg->getType()->isStructTy());
|
||||||
} else {
|
} else {
|
||||||
|
@ -610,7 +612,7 @@ void TypeInfoDeclaration_codegen(TypeInfoDeclaration *decl, IRState *p) {
|
||||||
// as immutable on the D side, and e.g. synchronized() can be used on the
|
// as immutable on the D side, and e.g. synchronized() can be used on the
|
||||||
// implicit monitor.
|
// implicit monitor.
|
||||||
auto g = new LLGlobalVariable(gIR->module, type, false, lwc.first,
|
auto g = new LLGlobalVariable(gIR->module, type, false, lwc.first,
|
||||||
nullptr, mangled);
|
nullptr, llMangle);
|
||||||
setLinkage(lwc, g);
|
setLinkage(lwc, g);
|
||||||
irg->value = g;
|
irg->value = g;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,11 +47,11 @@ LLConstant *&IrAggr::getInitSymbol() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the initZ symbol
|
// create the initZ symbol
|
||||||
auto initname = getMangledInitSymbolName(aggrdecl);
|
const auto llMangle = DtoMangledInitSymbolName(aggrdecl);
|
||||||
|
|
||||||
auto initGlobal =
|
auto initGlobal =
|
||||||
getOrCreateGlobal(aggrdecl->loc, gIR->module, getLLStructType(), true,
|
getOrCreateGlobal(aggrdecl->loc, gIR->module, getLLStructType(), true,
|
||||||
llvm::GlobalValue::ExternalLinkage, nullptr, initname);
|
llvm::GlobalValue::ExternalLinkage, nullptr, llMangle);
|
||||||
initGlobal->setAlignment(DtoAlignment(type));
|
initGlobal->setAlignment(DtoAlignment(type));
|
||||||
|
|
||||||
init = initGlobal;
|
init = initGlobal;
|
||||||
|
|
|
@ -47,13 +47,13 @@ LLGlobalVariable *IrAggr::getVtblSymbol() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the vtblZ symbol
|
// create the vtblZ symbol
|
||||||
auto initname = getMangledVTableSymbolName(aggrdecl);
|
const auto llMangle = DtoMangledVTableSymbolName(aggrdecl);
|
||||||
|
|
||||||
LLType *vtblTy = stripModifiers(type)->ctype->isClass()->getVtblType();
|
LLType *vtblTy = stripModifiers(type)->ctype->isClass()->getVtblType();
|
||||||
|
|
||||||
vtbl =
|
vtbl =
|
||||||
getOrCreateGlobal(aggrdecl->loc, gIR->module, vtblTy, true,
|
getOrCreateGlobal(aggrdecl->loc, gIR->module, vtblTy, true,
|
||||||
llvm::GlobalValue::ExternalLinkage, nullptr, initname);
|
llvm::GlobalValue::ExternalLinkage, nullptr, llMangle);
|
||||||
|
|
||||||
return vtbl;
|
return vtbl;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ LLGlobalVariable *IrAggr::getClassInfoSymbol() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the ClassZ / InterfaceZ symbol
|
// create the ClassZ / InterfaceZ symbol
|
||||||
std::string initname = getMangledClassInfoSymbolName(aggrdecl);
|
const auto llMangle = DtoMangledClassInfoSymbolName(aggrdecl);
|
||||||
|
|
||||||
// The type is also ClassInfo for interfaces – the actual TypeInfo for them
|
// The type is also ClassInfo for interfaces – the actual TypeInfo for them
|
||||||
// is a TypeInfo_Interface instance that references __ClassZ in its "base"
|
// is a TypeInfo_Interface instance that references __ClassZ in its "base"
|
||||||
|
@ -79,7 +79,7 @@ LLGlobalVariable *IrAggr::getClassInfoSymbol() {
|
||||||
// classinfos cannot be constants since they're used as locks for synchronized
|
// classinfos cannot be constants since they're used as locks for synchronized
|
||||||
classInfo = getOrCreateGlobal(
|
classInfo = getOrCreateGlobal(
|
||||||
aggrdecl->loc, gIR->module, tc->getMemoryLLType(), false,
|
aggrdecl->loc, gIR->module, tc->getMemoryLLType(), false,
|
||||||
llvm::GlobalValue::ExternalLinkage, nullptr, initname);
|
llvm::GlobalValue::ExternalLinkage, nullptr, llMangle);
|
||||||
|
|
||||||
// Generate some metadata on this ClassInfo if it's for a class.
|
// Generate some metadata on this ClassInfo if it's for a class.
|
||||||
ClassDeclaration *classdecl = aggrdecl->isClassDeclaration();
|
ClassDeclaration *classdecl = aggrdecl->isClassDeclaration();
|
||||||
|
@ -98,9 +98,15 @@ LLGlobalVariable *IrAggr::getClassInfoSymbol() {
|
||||||
mdVals[CD_CustomDelete] = llvm::ConstantAsMetadata::get(
|
mdVals[CD_CustomDelete] = llvm::ConstantAsMetadata::get(
|
||||||
LLConstantInt::get(LLType::getInt1Ty(gIR->context()), hasCustomDelete));
|
LLConstantInt::get(LLType::getInt1Ty(gIR->context()), hasCustomDelete));
|
||||||
// Construct the metadata and insert it into the module.
|
// Construct the metadata and insert it into the module.
|
||||||
llvm::SmallString<64> name;
|
OutBuffer debugName;
|
||||||
llvm::NamedMDNode *node = gIR->module.getOrInsertNamedMetadata(
|
debugName.writestring(CD_PREFIX);
|
||||||
llvm::Twine(CD_PREFIX, initname).toStringRef(name));
|
if (llMangle[0] == '\1') {
|
||||||
|
debugName.write(llMangle.data() + 1, llMangle.length() - 1);
|
||||||
|
} else {
|
||||||
|
debugName.write(llMangle.data(), llMangle.length());
|
||||||
|
}
|
||||||
|
llvm::NamedMDNode *node =
|
||||||
|
gIR->module.getOrInsertNamedMetadata(debugName.peekString());
|
||||||
node->addOperand(llvm::MDNode::get(
|
node->addOperand(llvm::MDNode::get(
|
||||||
gIR->context(), llvm::makeArrayRef(mdVals, CD_NumFields)));
|
gIR->context(), llvm::makeArrayRef(mdVals, CD_NumFields)));
|
||||||
}
|
}
|
||||||
|
@ -124,19 +130,15 @@ LLGlobalVariable *IrAggr::getInterfaceArraySymbol() {
|
||||||
LLType *InterfaceTy = DtoType(Type::typeinfoclass->fields[3]->type->nextOf());
|
LLType *InterfaceTy = DtoType(Type::typeinfoclass->fields[3]->type->nextOf());
|
||||||
|
|
||||||
// create Interface[N]
|
// create Interface[N]
|
||||||
|
const auto llMangle = DtoMangledInterfaceInfosSymbolName(cd);
|
||||||
|
|
||||||
LLArrayType *array_type = llvm::ArrayType::get(InterfaceTy, n);
|
LLArrayType *array_type = llvm::ArrayType::get(InterfaceTy, n);
|
||||||
|
|
||||||
// put it in a global
|
// We keep the global as external for now and only consider template linkage
|
||||||
OutBuffer mangledName;
|
// if we emit the initializer later.
|
||||||
mangledName.writestring("_D");
|
classInterfacesArray =
|
||||||
mangleToBuffer(cd, &mangledName);
|
getOrCreateGlobal(cd->loc, gIR->module, array_type, true,
|
||||||
mangledName.writestring("16__interfaceInfosZ");
|
llvm::GlobalValue::ExternalLinkage, nullptr, llMangle);
|
||||||
|
|
||||||
// We keep this as external for now and only consider template linkage if
|
|
||||||
// we emit the initializer later.
|
|
||||||
classInterfacesArray = getOrCreateGlobal(
|
|
||||||
cd->loc, gIR->module, array_type, true,
|
|
||||||
llvm::GlobalValue::ExternalLinkage, nullptr, mangledName.peekString());
|
|
||||||
|
|
||||||
return classInterfacesArray;
|
return classInterfacesArray;
|
||||||
}
|
}
|
||||||
|
@ -329,15 +331,18 @@ llvm::GlobalVariable *IrAggr::getInterfaceVtbl(BaseClass *b, bool new_instance,
|
||||||
nameBuf.write(mangledTargetName, 2);
|
nameBuf.write(mangledTargetName, 2);
|
||||||
nameBuf.writestring(thunkPrefix);
|
nameBuf.writestring(thunkPrefix);
|
||||||
nameBuf.writestring(mangledTargetName + 2);
|
nameBuf.writestring(mangledTargetName + 2);
|
||||||
const char *thunkName = nameBuf.extractString();
|
|
||||||
llvm::Function *thunk = gIR->module.getFunction(thunkName);
|
const auto thunkLLMangle =
|
||||||
|
DtoMangledFuncName(nameBuf.peekString(), fd->linkage);
|
||||||
|
|
||||||
|
llvm::Function *thunk = gIR->module.getFunction(thunkLLMangle);
|
||||||
if (!thunk) {
|
if (!thunk) {
|
||||||
const LinkageWithCOMDAT lwc(LLGlobalValue::LinkOnceODRLinkage,
|
const LinkageWithCOMDAT lwc(LLGlobalValue::LinkOnceODRLinkage,
|
||||||
supportsCOMDAT());
|
supportsCOMDAT());
|
||||||
const auto callee = irFunc->getLLVMCallee();
|
const auto callee = irFunc->getLLVMCallee();
|
||||||
thunk = LLFunction::Create(
|
thunk = LLFunction::Create(
|
||||||
isaFunction(callee->getType()->getContainedType(0)), lwc.first,
|
isaFunction(callee->getType()->getContainedType(0)), lwc.first,
|
||||||
thunkName, &gIR->module);
|
thunkLLMangle, &gIR->module);
|
||||||
setLinkage(lwc, thunk);
|
setLinkage(lwc, thunk);
|
||||||
thunk->copyAttributesFrom(callee);
|
thunk->copyAttributesFrom(callee);
|
||||||
|
|
||||||
|
@ -440,10 +445,12 @@ llvm::GlobalVariable *IrAggr::getInterfaceVtbl(BaseClass *b, bool new_instance,
|
||||||
mangledName.writestring(thunkPrefix);
|
mangledName.writestring(thunkPrefix);
|
||||||
mangledName.writestring("6__vtblZ");
|
mangledName.writestring("6__vtblZ");
|
||||||
|
|
||||||
|
const auto llMangle = DtoMangledVarName(mangledName.peekString(), LINKd);
|
||||||
|
|
||||||
const auto lwc = DtoLinkage(cd);
|
const auto lwc = DtoLinkage(cd);
|
||||||
LLGlobalVariable *GV =
|
LLGlobalVariable *GV =
|
||||||
getOrCreateGlobal(cd->loc, gIR->module, vtbl_constant->getType(), true,
|
getOrCreateGlobal(cd->loc, gIR->module, vtbl_constant->getType(), true,
|
||||||
lwc.first, vtbl_constant, mangledName.peekString());
|
lwc.first, vtbl_constant, llMangle);
|
||||||
setLinkage(lwc, GV);
|
setLinkage(lwc, GV);
|
||||||
|
|
||||||
// insert into the vtbl map
|
// insert into the vtbl map
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
#include "gen/irstate.h"
|
#include "gen/irstate.h"
|
||||||
|
#include "gen/mangling.h"
|
||||||
#include "gen/tollvm.h"
|
#include "gen/tollvm.h"
|
||||||
#include "ir/irdsymbol.h"
|
#include "ir/irdsymbol.h"
|
||||||
#include "ir/irfunction.h"
|
#include "ir/irfunction.h"
|
||||||
|
@ -22,14 +23,11 @@ llvm::GlobalVariable *IrModule::moduleInfoSymbol() {
|
||||||
return moduleInfoVar;
|
return moduleInfoVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutBuffer mangledName;
|
const auto llMangle = DtoMangledModuleInfoSymbolName(M);
|
||||||
mangledName.writestring("_D");
|
|
||||||
mangleToBuffer(M, &mangledName);
|
|
||||||
mangledName.writestring("12__ModuleInfoZ");
|
|
||||||
|
|
||||||
moduleInfoVar = new llvm::GlobalVariable(
|
moduleInfoVar = new llvm::GlobalVariable(
|
||||||
gIR->module, llvm::StructType::create(gIR->context()), false,
|
gIR->module, llvm::StructType::create(gIR->context()), false,
|
||||||
llvm::GlobalValue::ExternalLinkage, nullptr, mangledName.peekString());
|
llvm::GlobalValue::ExternalLinkage, nullptr, llMangle);
|
||||||
return moduleInfoVar;
|
return moduleInfoVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue