mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 17:43:35 +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;
|
global.params.link = 0;
|
||||||
else if (strcmp(p + 1, "fPIC") == 0)
|
else if (strcmp(p + 1, "fPIC") == 0)
|
||||||
global.params.pic = 1;
|
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;
|
global.params.symdebug = 1;
|
||||||
|
else if (strcmp(p + 1, "gc") == 0)
|
||||||
|
global.params.symdebug = 2;
|
||||||
else if (strcmp(p + 1, "v") == 0)
|
else if (strcmp(p + 1, "v") == 0)
|
||||||
global.params.verbose = 1;
|
global.params.verbose = 1;
|
||||||
else if (strcmp(p + 1, "vv") == 0) {
|
else if (strcmp(p + 1, "vv") == 0) {
|
||||||
|
|
|
@ -391,8 +391,10 @@ int main(int argc, char *argv[], char** envp)
|
||||||
global.params.link = 0;
|
global.params.link = 0;
|
||||||
else if (strcmp(p + 1, "fPIC") == 0)
|
else if (strcmp(p + 1, "fPIC") == 0)
|
||||||
global.params.pic = 1;
|
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;
|
global.params.symdebug = 1;
|
||||||
|
else if (strcmp(p + 1, "gc") == 0)
|
||||||
|
global.params.symdebug = 2;
|
||||||
else if (strcmp(p + 1, "v") == 0)
|
else if (strcmp(p + 1, "v") == 0)
|
||||||
global.params.verbose = 1;
|
global.params.verbose = 1;
|
||||||
else if (strcmp(p + 1, "vv") == 0) {
|
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[0] = DBG_TAG(DW_TAG_compile_unit);
|
||||||
vals[1] = DBG_CAST(getDwarfAnchor(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");
|
vals[3] = DtoConstStringPtr(FileName::name(m->srcfile->name->toChars()), "llvm.metadata");
|
||||||
std::string srcpath(FileName::path(m->srcfile->name->toChars()));
|
std::string srcpath(FileName::path(m->srcfile->name->toChars()));
|
||||||
if (!FileName::absolute(srcpath.c_str())) {
|
if (!FileName::absolute(srcpath.c_str())) {
|
||||||
|
|
|
@ -673,6 +673,11 @@ llvm::ConstantPointerNull* getNullPtr(const LLType* t)
|
||||||
return llvm::ConstantPointerNull::get(pt);
|
return llvm::ConstantPointerNull::get(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LLConstant* getNullValue(const LLType* t)
|
||||||
|
{
|
||||||
|
return LLConstant::getNullValue(t);
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t getTypeBitSize(const LLType* t)
|
size_t getTypeBitSize(const LLType* t)
|
||||||
|
|
|
@ -87,6 +87,7 @@ LLGlobalVariable* isaGlobalVar(LLValue* v);
|
||||||
const LLPointerType* getPtrToType(const LLType* t);
|
const LLPointerType* getPtrToType(const LLType* t);
|
||||||
const LLPointerType* getVoidPtrType();
|
const LLPointerType* getVoidPtrType();
|
||||||
llvm::ConstantPointerNull* getNullPtr(const LLType* t);
|
llvm::ConstantPointerNull* getNullPtr(const LLType* t);
|
||||||
|
LLConstant* getNullValue(const LLType* t);
|
||||||
|
|
||||||
// type sizes
|
// type sizes
|
||||||
size_t getTypeBitSize(const LLType* t);
|
size_t getTypeBitSize(const LLType* t);
|
||||||
|
|
|
@ -681,15 +681,17 @@ void Module::genmoduleinfo()
|
||||||
{
|
{
|
||||||
// The layout is:
|
// The layout is:
|
||||||
// {
|
// {
|
||||||
// void **vptr;
|
// char[] name;
|
||||||
// monitor_t monitor;
|
// ModuleInfo[] importedModules;
|
||||||
// char[] name; // class name
|
// ClassInfo[] localClasses;
|
||||||
// ModuleInfo importedModules[];
|
// uint flags;
|
||||||
// ClassInfo localClasses[];
|
//
|
||||||
// uint flags; // initialization state
|
// void function() ctor;
|
||||||
// void *ctor;
|
// void function() dtor;
|
||||||
// void *dtor;
|
// void function() unitTest;
|
||||||
// void *unitTest;
|
//
|
||||||
|
// void* xgetMembers;
|
||||||
|
// void function() ictor;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// resolve ModuleInfo
|
// resolve ModuleInfo
|
||||||
|
@ -705,7 +707,6 @@ void Module::genmoduleinfo()
|
||||||
|
|
||||||
// moduleinfo llvm struct type
|
// moduleinfo llvm struct type
|
||||||
const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->ir.type->get());
|
const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->ir.type->get());
|
||||||
|
|
||||||
// classinfo llvm struct type
|
// classinfo llvm struct type
|
||||||
const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get());
|
const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get());
|
||||||
|
|
||||||
|
@ -733,9 +734,9 @@ void Module::genmoduleinfo()
|
||||||
{
|
{
|
||||||
Module *m = (Module *)aimports.data[i];
|
Module *m = (Module *)aimports.data[i];
|
||||||
if (!m->needModuleInfo())
|
if (!m->needModuleInfo())
|
||||||
aimports_dim--;
|
continue;
|
||||||
else { // declare
|
|
||||||
// create name
|
// declare the imported module info
|
||||||
std::string m_name("_D");
|
std::string m_name("_D");
|
||||||
m_name.append(m->mangle());
|
m_name.append(m->mangle());
|
||||||
m_name.append("8__ModuleZ");
|
m_name.append("8__ModuleZ");
|
||||||
|
@ -743,7 +744,6 @@ void Module::genmoduleinfo()
|
||||||
if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module);
|
if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module);
|
||||||
importInits.push_back(m_gvar);
|
importInits.push_back(m_gvar);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// has import array?
|
// has import array?
|
||||||
if (!importInits.empty())
|
if (!importInits.empty())
|
||||||
{
|
{
|
||||||
|
@ -758,7 +758,7 @@ void Module::genmoduleinfo()
|
||||||
c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
|
c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
c = moduleinfo->ir.irStruct->constInit->getOperand(3);
|
c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)) );
|
||||||
initVec.push_back(c);
|
initVec.push_back(c);
|
||||||
|
|
||||||
// localClasses[]
|
// localClasses[]
|
||||||
|
@ -789,7 +789,7 @@ void Module::genmoduleinfo()
|
||||||
}
|
}
|
||||||
Logger::println("class: %s", cd->toPrettyChars());
|
Logger::println("class: %s", cd->toPrettyChars());
|
||||||
assert(cd->ir.irStruct->classInfo);
|
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);
|
classInits.push_back(c);
|
||||||
}
|
}
|
||||||
// has class array?
|
// has class array?
|
||||||
|
@ -802,11 +802,11 @@ void Module::genmoduleinfo()
|
||||||
m_name.append("9__classesZ");
|
m_name.append("9__classesZ");
|
||||||
assert(gIR->module->getGlobalVariable(m_name) == NULL);
|
assert(gIR->module->getGlobalVariable(m_name) == NULL);
|
||||||
llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
|
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);
|
c = DtoConstSlice(DtoConstSize_t(classInits.size()), c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
c = moduleinfo->ir.irStruct->constInit->getOperand(4);
|
c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(classinfoTy)) );
|
||||||
initVec.push_back(c);
|
initVec.push_back(c);
|
||||||
|
|
||||||
// flags
|
// flags
|
||||||
|
@ -815,27 +815,30 @@ void Module::genmoduleinfo()
|
||||||
c = DtoConstUint(4); // flags (4 means MIstandalone)
|
c = DtoConstUint(4); // flags (4 means MIstandalone)
|
||||||
initVec.push_back(c);
|
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
|
// ctor
|
||||||
llvm::Function* fctor = build_module_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);
|
initVec.push_back(c);
|
||||||
|
|
||||||
// dtor
|
// dtor
|
||||||
llvm::Function* fdtor = build_module_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);
|
initVec.push_back(c);
|
||||||
|
|
||||||
// unitTest
|
// unitTest
|
||||||
llvm::Function* unittest = build_module_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);
|
initVec.push_back(c);
|
||||||
|
|
||||||
// xgetMembers
|
// xgetMembers
|
||||||
c = moduleinfo->ir.irStruct->constInit->getOperand(9);
|
c = getNullValue(getVoidPtrType());
|
||||||
initVec.push_back(c);
|
initVec.push_back(c);
|
||||||
|
|
||||||
// ictor
|
// ictor
|
||||||
c = moduleinfo->ir.irStruct->constInit->getOperand(10);
|
c = getNullValue(fnptrTy);
|
||||||
initVec.push_back(c);
|
initVec.push_back(c);
|
||||||
|
|
||||||
/*Logger::println("MODULE INFO INITIALIZERS");
|
/*Logger::println("MODULE INFO INITIALIZERS");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue