mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-26 05:25:47 +00:00
Revert "Fix a nomenclature error in llvm-nm."
This reverts commit r205479. It turns out that nm does use addresses, it is just that every reasonable relocatable ELF object has sections with address 0. I have no idea if those exist in reality, but it at least it shows that llvm-nm should use the name address. The added test was includes an unusual .o file with non 0 section addresses. I created it by hacking ELFObjectWriter.cpp. Really sorry for the churn. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205493 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -417,15 +417,7 @@ template <class ELFT>
|
|||||||
error_code ELFObjectFile<ELFT>::getSymbolValue(DataRefImpl Symb,
|
error_code ELFObjectFile<ELFT>::getSymbolValue(DataRefImpl Symb,
|
||||||
uint64_t &Val) const {
|
uint64_t &Val) const {
|
||||||
const Elf_Sym *ESym = getSymbol(Symb);
|
const Elf_Sym *ESym = getSymbol(Symb);
|
||||||
switch (EF.getSymbolTableIndex(ESym)) {
|
Val = ESym->st_value;
|
||||||
default:
|
|
||||||
Val = ESym->st_value;
|
|
||||||
break;
|
|
||||||
case ELF::SHN_COMMON:
|
|
||||||
case ELF::SHN_UNDEF:
|
|
||||||
Val = UnknownAddressOrSize;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -253,15 +253,8 @@ error_code COFFObjectFile::getSymbolSection(DataRefImpl Ref,
|
|||||||
}
|
}
|
||||||
|
|
||||||
error_code COFFObjectFile::getSymbolValue(DataRefImpl Ref,
|
error_code COFFObjectFile::getSymbolValue(DataRefImpl Ref,
|
||||||
uint64_t &Result) const {
|
uint64_t &Val) const {
|
||||||
const coff_symbol *Symb = toSymb(Ref);
|
report_fatal_error("getSymbolValue unimplemented in COFFObjectFile");
|
||||||
|
|
||||||
if (Symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED)
|
|
||||||
Result = UnknownAddressOrSize;
|
|
||||||
else
|
|
||||||
Result = Symb->Value;
|
|
||||||
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const {
|
void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const {
|
||||||
|
@@ -633,8 +633,7 @@ MachOObjectFile::getSymbolSection(DataRefImpl Symb,
|
|||||||
|
|
||||||
error_code MachOObjectFile::getSymbolValue(DataRefImpl Symb,
|
error_code MachOObjectFile::getSymbolValue(DataRefImpl Symb,
|
||||||
uint64_t &Val) const {
|
uint64_t &Val) const {
|
||||||
// In MachO both relocatable and non-relocatable objects have addresses.
|
report_fatal_error("getSymbolValue unimplemented in MachOObjectFile");
|
||||||
return getSymbolAddress(Symb, Val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachOObjectFile::moveSectionNext(DataRefImpl &Sec) const {
|
void MachOObjectFile::moveSectionNext(DataRefImpl &Sec) const {
|
||||||
|
BIN
test/Object/Inputs/relocatable-with-section-address.elf-x86-64
Normal file
BIN
test/Object/Inputs/relocatable-with-section-address.elf-x86-64
Normal file
Binary file not shown.
@@ -16,6 +16,8 @@ RUN: llvm-nm %p/Inputs/trivial-object-test.macho-x86-64 \
|
|||||||
RUN: | FileCheck %s -check-prefix macho64
|
RUN: | FileCheck %s -check-prefix macho64
|
||||||
RUN: llvm-nm %p/Inputs/common.coff-i386 \
|
RUN: llvm-nm %p/Inputs/common.coff-i386 \
|
||||||
RUN: | FileCheck %s -check-prefix COFF-COMMON
|
RUN: | FileCheck %s -check-prefix COFF-COMMON
|
||||||
|
RUN: llvm-nm %p/Inputs/relocatable-with-section-address.elf-x86-64 \
|
||||||
|
RUN: | FileCheck %s -check-prefix ELF-SEC-ADDR
|
||||||
|
|
||||||
COFF: 00000000 d .data
|
COFF: 00000000 d .data
|
||||||
COFF: 00000000 t .text
|
COFF: 00000000 t .text
|
||||||
@@ -54,3 +56,11 @@ macho64: 00000028 s L_.str
|
|||||||
macho64: 00000000 U _SomeOtherFunction
|
macho64: 00000000 U _SomeOtherFunction
|
||||||
macho64: 00000000 T _main
|
macho64: 00000000 T _main
|
||||||
macho64: 00000000 U _puts
|
macho64: 00000000 U _puts
|
||||||
|
|
||||||
|
|
||||||
|
Test that nm uses addresses even with ELF .o files.
|
||||||
|
ELF-SEC-ADDR: 00000058 D a
|
||||||
|
ELF-SEC-ADDR-NEXT: 0000005c D b
|
||||||
|
ELF-SEC-ADDR-NEXT: 00000040 T f
|
||||||
|
ELF-SEC-ADDR-NEXT: 00000050 T g
|
||||||
|
ELF-SEC-ADDR-NEXT: 00000060 D p
|
||||||
|
@@ -95,7 +95,7 @@ cl::opt<bool> DebugSyms("debug-syms",
|
|||||||
cl::alias DebugSymsa("a", cl::desc("Alias for --debug-syms"),
|
cl::alias DebugSymsa("a", cl::desc("Alias for --debug-syms"),
|
||||||
cl::aliasopt(DebugSyms));
|
cl::aliasopt(DebugSyms));
|
||||||
|
|
||||||
cl::opt<bool> NumericSort("numeric-sort", cl::desc("Sort symbols by value"));
|
cl::opt<bool> NumericSort("numeric-sort", cl::desc("Sort symbols by address"));
|
||||||
cl::alias NumericSortn("n", cl::desc("Alias for --numeric-sort"),
|
cl::alias NumericSortn("n", cl::desc("Alias for --numeric-sort"),
|
||||||
cl::aliasopt(NumericSort));
|
cl::aliasopt(NumericSort));
|
||||||
cl::alias NumericSortv("v", cl::desc("Alias for --numeric-sort"),
|
cl::alias NumericSortv("v", cl::desc("Alias for --numeric-sort"),
|
||||||
@@ -105,7 +105,7 @@ cl::opt<bool> NoSort("no-sort", cl::desc("Show symbols in order encountered"));
|
|||||||
cl::alias NoSortp("p", cl::desc("Alias for --no-sort"), cl::aliasopt(NoSort));
|
cl::alias NoSortp("p", cl::desc("Alias for --no-sort"), cl::aliasopt(NoSort));
|
||||||
|
|
||||||
cl::opt<bool> PrintSize("print-size",
|
cl::opt<bool> PrintSize("print-size",
|
||||||
cl::desc("Show symbol size instead of value"));
|
cl::desc("Show symbol size instead of address"));
|
||||||
cl::alias PrintSizeS("S", cl::desc("Alias for --print-size"),
|
cl::alias PrintSizeS("S", cl::desc("Alias for --print-size"),
|
||||||
cl::aliasopt(PrintSize));
|
cl::aliasopt(PrintSize));
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ cl::opt<bool> WithoutAliases("without-aliases", cl::Hidden,
|
|||||||
cl::opt<bool> ArchiveMap("print-armap", cl::desc("Print the archive map"));
|
cl::opt<bool> ArchiveMap("print-armap", cl::desc("Print the archive map"));
|
||||||
cl::alias ArchiveMaps("s", cl::desc("Alias for --print-armap"),
|
cl::alias ArchiveMaps("s", cl::desc("Alias for --print-armap"),
|
||||||
cl::aliasopt(ArchiveMap));
|
cl::aliasopt(ArchiveMap));
|
||||||
bool PrintValue = true;
|
bool PrintAddress = true;
|
||||||
|
|
||||||
bool MultipleFiles = false;
|
bool MultipleFiles = false;
|
||||||
|
|
||||||
@@ -141,19 +141,19 @@ static bool error(error_code EC, Twine Path = Twine()) {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct NMSymbol {
|
struct NMSymbol {
|
||||||
uint64_t Value;
|
uint64_t Address;
|
||||||
uint64_t Size;
|
uint64_t Size;
|
||||||
char TypeChar;
|
char TypeChar;
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool compareSymbolValue(const NMSymbol &A, const NMSymbol &B) {
|
static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) {
|
||||||
if (A.Value < B.Value)
|
if (A.Address < B.Address)
|
||||||
return true;
|
return true;
|
||||||
else if (A.Value == B.Value && A.Name < B.Name)
|
else if (A.Address == B.Address && A.Name < B.Name)
|
||||||
return true;
|
return true;
|
||||||
else if (A.Value == B.Value && A.Name == B.Name && A.Size < B.Size)
|
else if (A.Address == B.Address && A.Name == B.Name && A.Size < B.Size)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@@ -164,7 +164,7 @@ static bool compareSymbolSize(const NMSymbol &A, const NMSymbol &B) {
|
|||||||
return true;
|
return true;
|
||||||
else if (A.Size == B.Size && A.Name < B.Name)
|
else if (A.Size == B.Size && A.Name < B.Name)
|
||||||
return true;
|
return true;
|
||||||
else if (A.Size == B.Size && A.Name == B.Name && A.Value < B.Value)
|
else if (A.Size == B.Size && A.Name == B.Name && A.Address < B.Address)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@@ -175,7 +175,7 @@ static bool compareSymbolName(const NMSymbol &A, const NMSymbol &B) {
|
|||||||
return true;
|
return true;
|
||||||
else if (A.Name == B.Name && A.Size < B.Size)
|
else if (A.Name == B.Name && A.Size < B.Size)
|
||||||
return true;
|
return true;
|
||||||
else if (A.Name == B.Name && A.Size == B.Size && A.Value < B.Value)
|
else if (A.Name == B.Name && A.Size == B.Size && A.Address < B.Address)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@@ -188,7 +188,7 @@ static SymbolListT SymbolList;
|
|||||||
static void sortAndPrintSymbolList() {
|
static void sortAndPrintSymbolList() {
|
||||||
if (!NoSort) {
|
if (!NoSort) {
|
||||||
if (NumericSort)
|
if (NumericSort)
|
||||||
std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolValue);
|
std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolAddress);
|
||||||
else if (SizeSort)
|
else if (SizeSort)
|
||||||
std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolSize);
|
std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolSize);
|
||||||
else
|
else
|
||||||
@@ -211,29 +211,29 @@ static void sortAndPrintSymbolList() {
|
|||||||
continue;
|
continue;
|
||||||
if ((I->TypeChar == 'U') && DefinedOnly)
|
if ((I->TypeChar == 'U') && DefinedOnly)
|
||||||
continue;
|
continue;
|
||||||
if (SizeSort && !PrintValue && I->Size == UnknownAddressOrSize)
|
if (SizeSort && !PrintAddress && I->Size == UnknownAddressOrSize)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
char SymbolValueStr[10] = "";
|
char SymbolAddrStr[10] = "";
|
||||||
char SymbolSizeStr[10] = "";
|
char SymbolSizeStr[10] = "";
|
||||||
|
|
||||||
if (OutputFormat == sysv || I->Value == UnknownAddressOrSize)
|
if (OutputFormat == sysv || I->Address == UnknownAddressOrSize)
|
||||||
strcpy(SymbolValueStr, " ");
|
strcpy(SymbolAddrStr, " ");
|
||||||
if (OutputFormat == sysv)
|
if (OutputFormat == sysv)
|
||||||
strcpy(SymbolSizeStr, " ");
|
strcpy(SymbolSizeStr, " ");
|
||||||
|
|
||||||
if (I->Value != UnknownAddressOrSize)
|
if (I->Address != UnknownAddressOrSize)
|
||||||
format("%08" PRIx64, I->Value)
|
format("%08" PRIx64, I->Address)
|
||||||
.print(SymbolValueStr, sizeof(SymbolValueStr));
|
.print(SymbolAddrStr, sizeof(SymbolAddrStr));
|
||||||
if (I->Size != UnknownAddressOrSize)
|
if (I->Size != UnknownAddressOrSize)
|
||||||
format("%08" PRIx64, I->Size).print(SymbolSizeStr, sizeof(SymbolSizeStr));
|
format("%08" PRIx64, I->Size).print(SymbolSizeStr, sizeof(SymbolSizeStr));
|
||||||
|
|
||||||
if (OutputFormat == posix) {
|
if (OutputFormat == posix) {
|
||||||
outs() << I->Name << " " << I->TypeChar << " " << SymbolValueStr
|
outs() << I->Name << " " << I->TypeChar << " " << SymbolAddrStr
|
||||||
<< SymbolSizeStr << "\n";
|
<< SymbolSizeStr << "\n";
|
||||||
} else if (OutputFormat == bsd) {
|
} else if (OutputFormat == bsd) {
|
||||||
if (PrintValue)
|
if (PrintAddress)
|
||||||
outs() << SymbolValueStr << ' ';
|
outs() << SymbolAddrStr << ' ';
|
||||||
if (PrintSize) {
|
if (PrintSize) {
|
||||||
outs() << SymbolSizeStr;
|
outs() << SymbolSizeStr;
|
||||||
if (I->Size != UnknownAddressOrSize)
|
if (I->Size != UnknownAddressOrSize)
|
||||||
@@ -244,7 +244,7 @@ static void sortAndPrintSymbolList() {
|
|||||||
std::string PaddedName(I->Name);
|
std::string PaddedName(I->Name);
|
||||||
while (PaddedName.length() < 20)
|
while (PaddedName.length() < 20)
|
||||||
PaddedName += " ";
|
PaddedName += " ";
|
||||||
outs() << PaddedName << "|" << SymbolValueStr << "| " << I->TypeChar
|
outs() << PaddedName << "|" << SymbolAddrStr << "| " << I->TypeChar
|
||||||
<< " | |" << SymbolSizeStr << "| |\n";
|
<< " | |" << SymbolSizeStr << "| |\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -490,14 +490,14 @@ static void dumpSymbolNamesFromObject(SymbolicFile *Obj) {
|
|||||||
}
|
}
|
||||||
NMSymbol S;
|
NMSymbol S;
|
||||||
S.Size = UnknownAddressOrSize;
|
S.Size = UnknownAddressOrSize;
|
||||||
S.Value = UnknownAddressOrSize;
|
S.Address = UnknownAddressOrSize;
|
||||||
if ((PrintSize || SizeSort) && isa<ObjectFile>(Obj)) {
|
if ((PrintSize || SizeSort) && isa<ObjectFile>(Obj)) {
|
||||||
symbol_iterator SymI = I;
|
symbol_iterator SymI = I;
|
||||||
if (error(SymI->getSize(S.Size)))
|
if (error(SymI->getSize(S.Size)))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (PrintValue && isa<ObjectFile>(Obj))
|
if (PrintAddress && isa<ObjectFile>(Obj))
|
||||||
if (error(symbol_iterator(I)->getValue(S.Value)))
|
if (error(symbol_iterator(I)->getAddress(S.Address)))
|
||||||
break;
|
break;
|
||||||
S.TypeChar = getNMTypeChar(Obj, I);
|
S.TypeChar = getNMTypeChar(Obj, I);
|
||||||
if (error(I->printName(OS)))
|
if (error(I->printName(OS)))
|
||||||
@@ -602,9 +602,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// The relative order of these is important. If you pass --size-sort it should
|
// The relative order of these is important. If you pass --size-sort it should
|
||||||
// only print out the size. However, if you pass -S --size-sort, it should
|
// only print out the size. However, if you pass -S --size-sort, it should
|
||||||
// print out both the size and values.
|
// print out both the size and address.
|
||||||
if (SizeSort && !PrintSize)
|
if (SizeSort && !PrintSize)
|
||||||
PrintValue = false;
|
PrintAddress = false;
|
||||||
if (OutputFormat == sysv || SizeSort)
|
if (OutputFormat == sysv || SizeSort)
|
||||||
PrintSize = true;
|
PrintSize = true;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user