mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-28 19:25:00 +00:00
Fix llvm-nm to print the full 64-bit address for symbols in 64-bit object files.
The implementation might be better to have a method is64Bit() in the class SymbolicFile instead of having the static routine isSymbolList64Bit() in llvm-nm.cpp . But this is very much in the sprit of isObject() and getNMTypeChar() in llvm-nm.cpp that has a series of if else statements based on the specific class of the SymbolicFile. I can update this if folks would like. Also the tests were updated to be explicit about checking the address for 64-bits or 32-bits from object files. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208463 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -181,11 +181,30 @@ static bool compareSymbolName(const NMSymbol &A, const NMSymbol &B) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static char isSymbolList64Bit(SymbolicFile *Obj) {
|
||||
if (dyn_cast<IRObjectFile>(Obj))
|
||||
return false;
|
||||
else if (dyn_cast<COFFObjectFile>(Obj))
|
||||
return false;
|
||||
else if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(Obj))
|
||||
return MachO->is64Bit();
|
||||
else if (dyn_cast<ELF32LEObjectFile>(Obj))
|
||||
return false;
|
||||
else if (dyn_cast<ELF64LEObjectFile>(Obj))
|
||||
return true;
|
||||
else if (dyn_cast<ELF32BEObjectFile>(Obj))
|
||||
return false;
|
||||
else if(dyn_cast<ELF64BEObjectFile>(Obj))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static StringRef CurrentFilename;
|
||||
typedef std::vector<NMSymbol> SymbolListT;
|
||||
static SymbolListT SymbolList;
|
||||
|
||||
static void sortAndPrintSymbolList() {
|
||||
static void sortAndPrintSymbolList(SymbolicFile *Obj) {
|
||||
if (!NoSort) {
|
||||
if (NumericSort)
|
||||
std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolAddress);
|
||||
@@ -205,6 +224,15 @@ static void sortAndPrintSymbolList() {
|
||||
<< " Size Line Section\n";
|
||||
}
|
||||
|
||||
const char *printBlanks, *printFormat;
|
||||
if (isSymbolList64Bit(Obj)) {
|
||||
printBlanks = " ";
|
||||
printFormat = "%016" PRIx64;
|
||||
} else {
|
||||
printBlanks = " ";
|
||||
printFormat = "%08" PRIx64;
|
||||
}
|
||||
|
||||
for (SymbolListT::iterator I = SymbolList.begin(), E = SymbolList.end();
|
||||
I != E; ++I) {
|
||||
if ((I->TypeChar != 'U') && UndefinedOnly)
|
||||
@@ -214,19 +242,19 @@ static void sortAndPrintSymbolList() {
|
||||
if (SizeSort && !PrintAddress && I->Size == UnknownAddressOrSize)
|
||||
continue;
|
||||
|
||||
char SymbolAddrStr[10] = "";
|
||||
char SymbolSizeStr[10] = "";
|
||||
char SymbolAddrStr[18] = "";
|
||||
char SymbolSizeStr[18] = "";
|
||||
|
||||
if (OutputFormat == sysv || I->Address == UnknownAddressOrSize)
|
||||
strcpy(SymbolAddrStr, " ");
|
||||
strcpy(SymbolAddrStr, printBlanks);
|
||||
if (OutputFormat == sysv)
|
||||
strcpy(SymbolSizeStr, " ");
|
||||
strcpy(SymbolSizeStr, printBlanks);
|
||||
|
||||
if (I->Address != UnknownAddressOrSize)
|
||||
format("%08" PRIx64, I->Address)
|
||||
format(printFormat, I->Address)
|
||||
.print(SymbolAddrStr, sizeof(SymbolAddrStr));
|
||||
if (I->Size != UnknownAddressOrSize)
|
||||
format("%08" PRIx64, I->Size).print(SymbolSizeStr, sizeof(SymbolSizeStr));
|
||||
format(printFormat, I->Size).print(SymbolSizeStr, sizeof(SymbolSizeStr));
|
||||
|
||||
if (OutputFormat == posix) {
|
||||
outs() << I->Name << " " << I->TypeChar << " " << SymbolAddrStr
|
||||
@@ -514,7 +542,7 @@ static void dumpSymbolNamesFromObject(SymbolicFile *Obj) {
|
||||
}
|
||||
|
||||
CurrentFilename = Obj->getFileName();
|
||||
sortAndPrintSymbolList();
|
||||
sortAndPrintSymbolList(Obj);
|
||||
}
|
||||
|
||||
static void dumpSymbolNamesFromFile(std::string &Filename) {
|
||||
|
Reference in New Issue
Block a user