add module identifier to the elf object file
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77238 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp
index f2a9bf3..2679d98 100644
--- a/lib/CodeGen/ELFWriter.cpp
+++ b/lib/CodeGen/ELFWriter.cpp
@@ -514,6 +514,9 @@
if (TAI->getNonexecutableStackDirective())
getNonExecStackSection();
+ // Emit module name
+ SymbolList.push_back(ELFSym::getFileSym());
+
// Emit a symbol for each section created until now, skip null section
for (unsigned i = 1, e = SectionList.size(); i < e; ++i) {
ELFSection &ES = *SectionList[i];
@@ -524,7 +527,7 @@
}
// Emit string table
- EmitStringTable();
+ EmitStringTable(M.getModuleIdentifier());
// Emit the symbol table now, if non-empty.
EmitSymbolTable();
@@ -709,7 +712,7 @@
/// EmitStringTable - If the current symbol table is non-empty, emit the string
/// table for it
-void ELFWriter::EmitStringTable() {
+void ELFWriter::EmitStringTable(const std::string &ModuleName) {
if (!SymbolList.size()) return; // Empty symbol table.
ELFSection &StrTab = getStringTableSection();
@@ -721,12 +724,14 @@
for (ELFSymIter I=SymbolList.begin(), E=SymbolList.end(); I != E; ++I) {
ELFSym &Sym = *(*I);
- // Use the name mangler to uniquify the LLVM symbol.
std::string Name;
if (Sym.isGlobalValue())
+ // Use the name mangler to uniquify the LLVM symbol.
Name.append(Mang->getMangledName(Sym.getGlobalValue()));
else if (Sym.isExternalSym())
Name.append(Sym.getExternalSymbol());
+ else if (Sym.isFileType())
+ Name.append(ModuleName);
if (Name.empty()) {
Sym.NameIdx = 0;