Handle global variables being declared in sections

This commit is contained in:
baldurk
2020-06-19 17:48:12 +01:00
parent f2ff54dcea
commit 31e58f681e
3 changed files with 16 additions and 0 deletions
@@ -74,6 +74,7 @@ enum class ModuleRecord : uint32_t
VERSION = 1,
TRIPLE = 2,
DATALAYOUT = 3,
SECTIONNAME = 5,
GLOBALVAR = 7,
FUNCTION = 8,
ALIAS = 14,
@@ -576,11 +577,14 @@ Program::Program(const byte *bytes, size_t length)
case 6:
case 7:
case 15: g.flags |= GlobalFlags::IsExternal; break;
case 2: g.flags |= GlobalFlags::IsAppending; break;
default: break;
}
g.align = (1U << rootchild.ops[4]) >> 1;
g.section = int32_t(rootchild.ops[5]) - 1;
// symbols refer into any of N types in declaration order
m_Symbols.push_back({SymbolType::GlobalVar, m_GlobalVars.size()});
@@ -659,6 +663,10 @@ Program::Program(const byte *bytes, size_t length)
m_Aliases.push_back(a);
}
else if(IS_KNOWN(rootchild.id, ModuleRecord::SECTIONNAME))
{
m_Sections.push_back(rootchild.getString(0));
}
else
{
RDCERR("Unknown record ID %u encountered at module scope", rootchild.id);
@@ -121,6 +121,7 @@ enum class GlobalFlags : uint32_t
IsExternal = 0x2,
LocalUnnamedAddr = 0x4,
GlobalUnnamedAddr = 0x8,
IsAppending = 0x10,
};
BITMASK_OPERATORS(GlobalFlags);
@@ -130,6 +131,7 @@ struct GlobalVar
rdcstr name;
const Type *type = NULL;
uint64_t align = 0;
int32_t section = -1;
GlobalFlags flags = GlobalFlags::NoFlags;
Symbol initialiser;
};
@@ -552,6 +554,7 @@ private:
rdcarray<Function> m_Functions;
rdcarray<Alias> m_Aliases;
rdcarray<Symbol> m_Symbols;
rdcarray<rdcstr> m_Sections;
rdcarray<rdcstr> m_Kinds;
@@ -448,6 +448,8 @@ void Program::MakeDisassemblyString()
}
if(!(g.flags & GlobalFlags::IsExternal))
m_Disassembly += "internal ";
if(g.flags & GlobalFlags::IsAppending)
m_Disassembly += "appending ";
if(g.type->addrSpace)
m_Disassembly += StringFormat::Fmt("addrspace(%d) ", g.type->addrSpace);
if(g.flags & GlobalFlags::LocalUnnamedAddr)
@@ -467,6 +469,9 @@ void Program::MakeDisassemblyString()
if(g.align > 0)
m_Disassembly += StringFormat::Fmt(", align %u", g.align);
if(g.section >= 0)
m_Disassembly += StringFormat::Fmt(", section %s", escapeString(m_Sections[g.section]).c_str());
m_Disassembly += "\n";
instructionLine++;
}