mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-28 09:31:03 +00:00
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
This commit is contained in:
parent
3b07b5214c
commit
df0b6503d6
@ -59,10 +59,10 @@ namespace llvm {
|
|||||||
|
|
||||||
// ELF symbols are related to llvm ones by being one of the two llvm
|
// ELF symbols are related to llvm ones by being one of the two llvm
|
||||||
// types, for the other ones (section, file, func) a null pointer is
|
// types, for the other ones (section, file, func) a null pointer is
|
||||||
// assumed.
|
// assumed by default.
|
||||||
union {
|
union {
|
||||||
const GlobalValue *GV; // If this is a pointer to a GV
|
const GlobalValue *GV; // If this is a pointer to a GV
|
||||||
const char *Ext; // If this is a pointer to a named symbol
|
const char *Ext; // If this is a pointer to a named symbol
|
||||||
} Source;
|
} Source;
|
||||||
|
|
||||||
// Describes from which source type this ELF symbol comes from,
|
// Describes from which source type this ELF symbol comes from,
|
||||||
@ -118,9 +118,20 @@ namespace llvm {
|
|||||||
// getSectionSym - Returns a elf symbol to represent an elf section
|
// getSectionSym - Returns a elf symbol to represent an elf section
|
||||||
static ELFSym *getSectionSym() {
|
static ELFSym *getSectionSym() {
|
||||||
ELFSym *Sym = new ELFSym();
|
ELFSym *Sym = new ELFSym();
|
||||||
Sym->setBind(ELFSym::STB_LOCAL);
|
Sym->setBind(STB_LOCAL);
|
||||||
Sym->setType(ELFSym::STT_SECTION);
|
Sym->setType(STT_SECTION);
|
||||||
Sym->setVisibility(ELFSym::STV_DEFAULT);
|
Sym->setVisibility(STV_DEFAULT);
|
||||||
|
Sym->SourceType = isOther;
|
||||||
|
return Sym;
|
||||||
|
}
|
||||||
|
|
||||||
|
// getSectionSym - Returns a elf symbol to represent an elf section
|
||||||
|
static ELFSym *getFileSym() {
|
||||||
|
ELFSym *Sym = new ELFSym();
|
||||||
|
Sym->setBind(STB_LOCAL);
|
||||||
|
Sym->setType(STT_FILE);
|
||||||
|
Sym->setVisibility(STV_DEFAULT);
|
||||||
|
Sym->SectionIdx = 0xfff1; // ELFSection::SHN_ABS;
|
||||||
Sym->SourceType = isOther;
|
Sym->SourceType = isOther;
|
||||||
return Sym;
|
return Sym;
|
||||||
}
|
}
|
||||||
@ -164,6 +175,7 @@ namespace llvm {
|
|||||||
unsigned getBind() const { return (Info >> 4) & 0xf; }
|
unsigned getBind() const { return (Info >> 4) & 0xf; }
|
||||||
unsigned getType() const { return Info & 0xf; }
|
unsigned getType() const { return Info & 0xf; }
|
||||||
bool isLocalBind() const { return getBind() == STB_LOCAL; }
|
bool isLocalBind() const { return getBind() == STB_LOCAL; }
|
||||||
|
bool isFileType() const { return getType() == STT_FILE; }
|
||||||
|
|
||||||
void setBind(unsigned X) {
|
void setBind(unsigned X) {
|
||||||
assert(X == (X & 0xF) && "Bind value out of range!");
|
assert(X == (X & 0xF) && "Bind value out of range!");
|
||||||
|
@ -514,6 +514,9 @@ bool ELFWriter::doFinalization(Module &M) {
|
|||||||
if (TAI->getNonexecutableStackDirective())
|
if (TAI->getNonexecutableStackDirective())
|
||||||
getNonExecStackSection();
|
getNonExecStackSection();
|
||||||
|
|
||||||
|
// Emit module name
|
||||||
|
SymbolList.push_back(ELFSym::getFileSym());
|
||||||
|
|
||||||
// Emit a symbol for each section created until now, skip null section
|
// Emit a symbol for each section created until now, skip null section
|
||||||
for (unsigned i = 1, e = SectionList.size(); i < e; ++i) {
|
for (unsigned i = 1, e = SectionList.size(); i < e; ++i) {
|
||||||
ELFSection &ES = *SectionList[i];
|
ELFSection &ES = *SectionList[i];
|
||||||
@ -524,7 +527,7 @@ bool ELFWriter::doFinalization(Module &M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Emit string table
|
// Emit string table
|
||||||
EmitStringTable();
|
EmitStringTable(M.getModuleIdentifier());
|
||||||
|
|
||||||
// Emit the symbol table now, if non-empty.
|
// Emit the symbol table now, if non-empty.
|
||||||
EmitSymbolTable();
|
EmitSymbolTable();
|
||||||
@ -709,7 +712,7 @@ void ELFWriter::EmitSectionHeader(BinaryObject &SHdrTab,
|
|||||||
|
|
||||||
/// EmitStringTable - If the current symbol table is non-empty, emit the string
|
/// EmitStringTable - If the current symbol table is non-empty, emit the string
|
||||||
/// table for it
|
/// table for it
|
||||||
void ELFWriter::EmitStringTable() {
|
void ELFWriter::EmitStringTable(const std::string &ModuleName) {
|
||||||
if (!SymbolList.size()) return; // Empty symbol table.
|
if (!SymbolList.size()) return; // Empty symbol table.
|
||||||
ELFSection &StrTab = getStringTableSection();
|
ELFSection &StrTab = getStringTableSection();
|
||||||
|
|
||||||
@ -721,12 +724,14 @@ void ELFWriter::EmitStringTable() {
|
|||||||
for (ELFSymIter I=SymbolList.begin(), E=SymbolList.end(); I != E; ++I) {
|
for (ELFSymIter I=SymbolList.begin(), E=SymbolList.end(); I != E; ++I) {
|
||||||
ELFSym &Sym = *(*I);
|
ELFSym &Sym = *(*I);
|
||||||
|
|
||||||
// Use the name mangler to uniquify the LLVM symbol.
|
|
||||||
std::string Name;
|
std::string Name;
|
||||||
if (Sym.isGlobalValue())
|
if (Sym.isGlobalValue())
|
||||||
|
// Use the name mangler to uniquify the LLVM symbol.
|
||||||
Name.append(Mang->getMangledName(Sym.getGlobalValue()));
|
Name.append(Mang->getMangledName(Sym.getGlobalValue()));
|
||||||
else if (Sym.isExternalSym())
|
else if (Sym.isExternalSym())
|
||||||
Name.append(Sym.getExternalSymbol());
|
Name.append(Sym.getExternalSymbol());
|
||||||
|
else if (Sym.isFileType())
|
||||||
|
Name.append(ModuleName);
|
||||||
|
|
||||||
if (Name.empty()) {
|
if (Name.empty()) {
|
||||||
Sym.NameIdx = 0;
|
Sym.NameIdx = 0;
|
||||||
|
@ -250,7 +250,7 @@ namespace llvm {
|
|||||||
void EmitSectionTableStringTable();
|
void EmitSectionTableStringTable();
|
||||||
void EmitSymbol(BinaryObject &SymbolTable, ELFSym &Sym);
|
void EmitSymbol(BinaryObject &SymbolTable, ELFSym &Sym);
|
||||||
void EmitSymbolTable();
|
void EmitSymbolTable();
|
||||||
void EmitStringTable();
|
void EmitStringTable(const std::string &ModuleName);
|
||||||
void OutputSectionsAndSectionTable();
|
void OutputSectionsAndSectionTable();
|
||||||
void RelocateField(BinaryObject &BO, uint32_t Offset, int64_t Value,
|
void RelocateField(BinaryObject &BO, uint32_t Offset, int64_t Value,
|
||||||
unsigned Size);
|
unsigned Size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user