mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-04 17:11:44 +03:00
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Changed -g switch to emit DW_LANG_D debug info, make demangling work with a patched GDB, still more work to do for full support of D's Dwarf extensions. Added getNullValue helper method.
This commit is contained in:
parent
8553fc9aa0
commit
e0972b0793
6 changed files with 51 additions and 35 deletions
|
@ -374,8 +374,10 @@ int main(int argc, char *argv[], char** envp)
|
|||
global.params.link = 0;
|
||||
else if (strcmp(p + 1, "fPIC") == 0)
|
||||
global.params.pic = 1;
|
||||
else if (strcmp(p + 1, "g") == 0 || strcmp(p + 1, "gc") == 0)
|
||||
else if (strcmp(p + 1, "g") == 0)
|
||||
global.params.symdebug = 1;
|
||||
else if (strcmp(p + 1, "gc") == 0)
|
||||
global.params.symdebug = 2;
|
||||
else if (strcmp(p + 1, "v") == 0)
|
||||
global.params.verbose = 1;
|
||||
else if (strcmp(p + 1, "vv") == 0) {
|
||||
|
|
|
@ -391,8 +391,10 @@ int main(int argc, char *argv[], char** envp)
|
|||
global.params.link = 0;
|
||||
else if (strcmp(p + 1, "fPIC") == 0)
|
||||
global.params.pic = 1;
|
||||
else if (strcmp(p + 1, "g") == 0 || strcmp(p + 1, "gc") == 0)
|
||||
else if (strcmp(p + 1, "g") == 0)
|
||||
global.params.symdebug = 1;
|
||||
else if (strcmp(p + 1, "gc") == 0)
|
||||
global.params.symdebug = 2;
|
||||
else if (strcmp(p + 1, "v") == 0)
|
||||
global.params.verbose = 1;
|
||||
else if (strcmp(p + 1, "vv") == 0) {
|
||||
|
|
|
@ -134,7 +134,10 @@ static LLGlobalVariable* dwarfCompileUnit(Module* m)
|
|||
vals[0] = DBG_TAG(DW_TAG_compile_unit);
|
||||
vals[1] = DBG_CAST(getDwarfAnchor(DW_TAG_compile_unit));
|
||||
|
||||
vals[2] = DtoConstUint(DW_LANG_C);// _D)); // doesn't seem to work
|
||||
if (global.params.symdebug == 2)
|
||||
vals[2] = DtoConstUint(DW_LANG_C);
|
||||
else
|
||||
vals[2] = DtoConstUint(DW_LANG_D);
|
||||
vals[3] = DtoConstStringPtr(FileName::name(m->srcfile->name->toChars()), "llvm.metadata");
|
||||
std::string srcpath(FileName::path(m->srcfile->name->toChars()));
|
||||
if (!FileName::absolute(srcpath.c_str())) {
|
||||
|
|
|
@ -673,6 +673,11 @@ llvm::ConstantPointerNull* getNullPtr(const LLType* t)
|
|||
return llvm::ConstantPointerNull::get(pt);
|
||||
}
|
||||
|
||||
LLConstant* getNullValue(const LLType* t)
|
||||
{
|
||||
return LLConstant::getNullValue(t);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
size_t getTypeBitSize(const LLType* t)
|
||||
|
|
|
@ -87,6 +87,7 @@ LLGlobalVariable* isaGlobalVar(LLValue* v);
|
|||
const LLPointerType* getPtrToType(const LLType* t);
|
||||
const LLPointerType* getVoidPtrType();
|
||||
llvm::ConstantPointerNull* getNullPtr(const LLType* t);
|
||||
LLConstant* getNullValue(const LLType* t);
|
||||
|
||||
// type sizes
|
||||
size_t getTypeBitSize(const LLType* t);
|
||||
|
|
|
@ -679,18 +679,20 @@ static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo)
|
|||
|
||||
void Module::genmoduleinfo()
|
||||
{
|
||||
// The layout is:
|
||||
// {
|
||||
// void **vptr;
|
||||
// monitor_t monitor;
|
||||
// char[] name; // class name
|
||||
// ModuleInfo importedModules[];
|
||||
// ClassInfo localClasses[];
|
||||
// uint flags; // initialization state
|
||||
// void *ctor;
|
||||
// void *dtor;
|
||||
// void *unitTest;
|
||||
// }
|
||||
// The layout is:
|
||||
// {
|
||||
// char[] name;
|
||||
// ModuleInfo[] importedModules;
|
||||
// ClassInfo[] localClasses;
|
||||
// uint flags;
|
||||
//
|
||||
// void function() ctor;
|
||||
// void function() dtor;
|
||||
// void function() unitTest;
|
||||
//
|
||||
// void* xgetMembers;
|
||||
// void function() ictor;
|
||||
// }
|
||||
|
||||
// resolve ModuleInfo
|
||||
assert(moduleinfo);
|
||||
|
@ -705,7 +707,6 @@ void Module::genmoduleinfo()
|
|||
|
||||
// moduleinfo llvm struct type
|
||||
const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->ir.type->get());
|
||||
|
||||
// classinfo llvm struct type
|
||||
const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get());
|
||||
|
||||
|
@ -733,16 +734,15 @@ void Module::genmoduleinfo()
|
|||
{
|
||||
Module *m = (Module *)aimports.data[i];
|
||||
if (!m->needModuleInfo())
|
||||
aimports_dim--;
|
||||
else { // declare
|
||||
// create name
|
||||
std::string m_name("_D");
|
||||
m_name.append(m->mangle());
|
||||
m_name.append("8__ModuleZ");
|
||||
llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
|
||||
if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module);
|
||||
importInits.push_back(m_gvar);
|
||||
}
|
||||
continue;
|
||||
|
||||
// declare the imported module info
|
||||
std::string m_name("_D");
|
||||
m_name.append(m->mangle());
|
||||
m_name.append("8__ModuleZ");
|
||||
llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
|
||||
if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module);
|
||||
importInits.push_back(m_gvar);
|
||||
}
|
||||
// has import array?
|
||||
if (!importInits.empty())
|
||||
|
@ -758,7 +758,7 @@ void Module::genmoduleinfo()
|
|||
c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
|
||||
}
|
||||
else
|
||||
c = moduleinfo->ir.irStruct->constInit->getOperand(3);
|
||||
c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)) );
|
||||
initVec.push_back(c);
|
||||
|
||||
// localClasses[]
|
||||
|
@ -789,7 +789,7 @@ void Module::genmoduleinfo()
|
|||
}
|
||||
Logger::println("class: %s", cd->toPrettyChars());
|
||||
assert(cd->ir.irStruct->classInfo);
|
||||
c = llvm::ConstantExpr::getBitCast(cd->ir.irStruct->classInfo, getPtrToType(classinfoTy));
|
||||
c = DtoBitCast(cd->ir.irStruct->classInfo, getPtrToType(classinfoTy));
|
||||
classInits.push_back(c);
|
||||
}
|
||||
// has class array?
|
||||
|
@ -802,11 +802,11 @@ void Module::genmoduleinfo()
|
|||
m_name.append("9__classesZ");
|
||||
assert(gIR->module->getGlobalVariable(m_name) == NULL);
|
||||
llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
|
||||
c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(classArrTy->getElementType()));
|
||||
c = DtoBitCast(m_gvar, getPtrToType(classinfoTy));
|
||||
c = DtoConstSlice(DtoConstSize_t(classInits.size()), c);
|
||||
}
|
||||
else
|
||||
c = moduleinfo->ir.irStruct->constInit->getOperand(4);
|
||||
c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(classinfoTy)) );
|
||||
initVec.push_back(c);
|
||||
|
||||
// flags
|
||||
|
@ -815,27 +815,30 @@ void Module::genmoduleinfo()
|
|||
c = DtoConstUint(4); // flags (4 means MIstandalone)
|
||||
initVec.push_back(c);
|
||||
|
||||
// function pointer type for next three fields
|
||||
const LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false));
|
||||
|
||||
// ctor
|
||||
llvm::Function* fctor = build_module_ctor();
|
||||
c = fctor ? fctor : moduleinfo->ir.irStruct->constInit->getOperand(6);
|
||||
c = fctor ? fctor : getNullValue(fnptrTy);
|
||||
initVec.push_back(c);
|
||||
|
||||
// dtor
|
||||
llvm::Function* fdtor = build_module_dtor();
|
||||
c = fdtor ? fdtor : moduleinfo->ir.irStruct->constInit->getOperand(7);
|
||||
c = fdtor ? fdtor : getNullValue(fnptrTy);
|
||||
initVec.push_back(c);
|
||||
|
||||
// unitTest
|
||||
llvm::Function* unittest = build_module_unittest();
|
||||
c = unittest ? unittest : moduleinfo->ir.irStruct->constInit->getOperand(8);
|
||||
c = unittest ? unittest : getNullValue(fnptrTy);
|
||||
initVec.push_back(c);
|
||||
|
||||
// xgetMembers
|
||||
c = moduleinfo->ir.irStruct->constInit->getOperand(9);
|
||||
c = getNullValue(getVoidPtrType());
|
||||
initVec.push_back(c);
|
||||
|
||||
// ictor
|
||||
c = moduleinfo->ir.irStruct->constInit->getOperand(10);
|
||||
c = getNullValue(fnptrTy);
|
||||
initVec.push_back(c);
|
||||
|
||||
/*Logger::println("MODULE INFO INITIALIZERS");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue