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.

llvm-svn: 208463
This commit is contained in:
Kevin Enderby 2014-05-09 23:57:49 +00:00
parent 2039813d0e
commit e6f49d1bca
6 changed files with 100 additions and 68 deletions

View File

@ -17,24 +17,24 @@ CHECKIDX: b in abcdefghijklmnopqrstuvwxyz2.o
CHECKIDX: bda in abcdefghijklmnopqrstuvwxyz2.o
CHECKIDX: b in abcdefghijklmnopq.o
CHECKIDX: 1.o:
CHECKIDX: 00000000 D abcdefghijklmnopqrstuvwxyz12345678
CHECKIDX: U bda
CHECKIDX: 00000000 T main
CHECKIDX: 0000000000000000 D abcdefghijklmnopqrstuvwxyz12345678
CHECKIDX: U bda
CHECKIDX: 0000000000000000 T main
CHECKIDX: 2.o:
CHECKIDX: 00000000 T fn1
CHECKIDX: 0000000000000000 T fn1
CHECKIDX: 3.o:
CHECKIDX: 0000000b T fn1
CHECKIDX: 00000000 T fn3
CHECKIDX: 000000000000000b T fn1
CHECKIDX: 0000000000000000 T fn3
CHECKIDX: 4.o:
CHECKIDX: C shankar
CHECKIDX: C shankar
CHECKIDX: 5.o:
CHECKIDX: C a
CHECKIDX: C a
CHECKIDX: 6.o:
CHECKIDX: C b
CHECKIDX: C b
CHECKIDX: abcdefghijklmnopqrstuvwxyz1.o:
CHECKIDX: C a
CHECKIDX: C a
CHECKIDX: abcdefghijklmnopqrstuvwxyz2.o:
CHECKIDX: C b
CHECKIDX: 00000000 T bda
CHECKIDX: C b
CHECKIDX: 0000000000000000 T bda
CHECKIDX: abcdefghijklmnopq.o:
CHECKIDX: C b
CHECKIDX: C b

View File

@ -9,13 +9,13 @@ CHECK-NEXT: main in trivial-object-test2.elf-x86-64
CHECK-NOT: bar
CHECK: trivial-object-test.elf-x86-64:
CHECK-NEXT: U SomeOtherFunction
CHECK-NEXT: 00000000 T main
CHECK-NEXT: U puts
CHECK-NEXT: U SomeOtherFunction
CHECK-NEXT: 0000000000000000 T main
CHECK-NEXT: U puts
CHECK-NEXT: trivial-object-test2.elf-x86-64:
CHECK-NEXT: 00000000 t bar
CHECK-NEXT: 00000006 T foo
CHECK-NEXT: 00000016 T main
CHECK-NEXT: 0000000000000000 t bar
CHECK-NEXT: 0000000000000006 T foo
CHECK-NEXT: 0000000000000016 T main
RUN: rm -f %t.a
RUN: llvm-ar rcS %t.a %p/Inputs/trivial-object-test.elf-x86-64 %p/Inputs/trivial-object-test2.elf-x86-64
@ -37,13 +37,13 @@ CORRUPT-NEXT: foo in trivial-object-test2.elf-x86-64
CORRUPT-NEXT: main in trivial-object-test2.elf-x86-64
CORRUPT: trivial-object-test.elf-x86-64:
CORRUPT-NEXT: U SomeOtherFunction
CORRUPT-NEXT: 00000000 T main
CORRUPT-NEXT: U puts
CORRUPT-NEXT: U SomeOtherFunction
CORRUPT-NEXT: 0000000000000000 T main
CORRUPT-NEXT: U puts
CORRUPT-NEXT: trivial-object-test2.elf-x86-64:
CORRUPT-NEXT: 00000000 t bar
CORRUPT-NEXT: 00000006 T foo
CORRUPT-NEXT: 00000016 T main
CORRUPT-NEXT: 0000000000000000 t bar
CORRUPT-NEXT: 0000000000000006 T foo
CORRUPT-NEXT: 0000000000000016 T main
check that the we *don't* update the symbol table.
RUN: llvm-ar s %t.a

View File

@ -2,25 +2,25 @@ RUN: llvm-nm -D %p/Inputs/shared-object-test.elf-i386 \
RUN: | FileCheck %s -check-prefix ELF-32
ELF-32-NOT: U
ELF-32: 0012c8 A __bss_start
ELF-32: 0012c8 A _edata
ELF-32: 0012cc A _end
ELF-32: 0012c8 B common_sym
ELF-32: 0012c4 D defined_sym
ELF-32: 0001f0 T global_func
ELF-32: 000000 D tls_sym
ELF-32: 000012c8 A __bss_start
ELF-32: 000012c8 A _edata
ELF-32: 000012cc A _end
ELF-32: 000012c8 B common_sym
ELF-32: 000012c4 D defined_sym
ELF-32: 000001f0 T global_func
ELF-32: 00000000 D tls_sym
RUN: llvm-nm -D %p/Inputs/shared-object-test.elf-x86-64 \
RUN: | FileCheck %s -check-prefix ELF-64
ELF-64-NOT: U
ELF-64: 200454 A __bss_start
ELF-64: 200454 A _edata
ELF-64: 200458 A _end
ELF-64: 200454 B common_sym
ELF-64: 200450 D defined_sym
ELF-64: 0002f0 T global_func
ELF-64: 000000 D tls_sym
ELF-64: 0000000000200454 A __bss_start
ELF-64: 0000000000200454 A _edata
ELF-64: 0000000000200458 A _end
ELF-64: 0000000000200454 B common_sym
ELF-64: 0000000000200450 D defined_sym
ELF-64: 00000000000002f0 T global_func
ELF-64: 0000000000000000 D tls_sym
RUN: not llvm-nm -D %p/Inputs/weak-global-symbol.macho-i386 2>&1 \
RUN: | FileCheck %s -check-prefix ERROR

View File

@ -5,11 +5,11 @@ RUN: | FileCheck %s -check-prefix COFF
RUN: llvm-nm %p/Inputs/trivial-object-test.elf-i386 \
RUN: | FileCheck %s -check-prefix ELF
RUN: llvm-nm %p/Inputs/trivial-object-test.elf-x86-64 \
RUN: | FileCheck %s -check-prefix ELF
RUN: | FileCheck %s -check-prefix ELF64
RUN: llvm-nm %p/Inputs/weak.elf-x86-64 \
RUN: | FileCheck %s -check-prefix WEAK-ELF
RUN: | FileCheck %s -check-prefix WEAK-ELF64
RUN: llvm-nm %p/Inputs/absolute.elf-x86-64 \
RUN: | FileCheck %s -check-prefix ABSOLUTE-ELF
RUN: | FileCheck %s -check-prefix ABSOLUTE-ELF64
RUN: llvm-nm %p/Inputs/trivial-object-test.macho-i386 \
RUN: | FileCheck %s -check-prefix macho
RUN: llvm-nm %p/Inputs/trivial-object-test.macho-x86-64 \
@ -17,7 +17,7 @@ RUN: | FileCheck %s -check-prefix macho64
RUN: llvm-nm %p/Inputs/common.coff-i386 \
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
RUN: | FileCheck %s -check-prefix ELF-SEC-ADDR64
RUN: llvm-nm %p/Inputs/thumb-symbols.elf.arm \
RUN: | FileCheck %s -check-prefix ELF-THUMB
@ -43,30 +43,34 @@ ELF: U SomeOtherFunction
ELF: 00000000 T main
ELF: U puts
WEAK-ELF: w f1
WEAK-ELF: 00000000 W f2
WEAK-ELF: v x1
WEAK-ELF: 00000000 V x2
ELF64: U SomeOtherFunction
ELF64: 0000000000000000 T main
ELF64: U puts
ABSOLUTE-ELF: 00000123 a a1
ABSOLUTE-ELF: 00000123 A a2
WEAK-ELF64: w f1
WEAK-ELF64: 0000000000000000 W f2
WEAK-ELF64: v x1
WEAK-ELF64: 0000000000000000 V x2
ABSOLUTE-ELF64: 0000000000000123 a a1
ABSOLUTE-ELF64: 0000000000000123 A a2
macho: 00000000 U _SomeOtherFunction
macho: 00000000 T _main
macho: 00000000 U _puts
macho64: 00000028 s L_.str
macho64: 00000000 U _SomeOtherFunction
macho64: 00000000 T _main
macho64: 00000000 U _puts
macho64: 0000000000000028 s L_.str
macho64: 0000000000000000 U _SomeOtherFunction
macho64: 0000000000000000 T _main
macho64: 0000000000000000 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
ELF-SEC-ADDR64: 0000000000000058 D a
ELF-SEC-ADDR64-NEXT: 000000000000005c D b
ELF-SEC-ADDR64-NEXT: 0000000000000040 T f
ELF-SEC-ADDR64-NEXT: 0000000000000050 T g
ELF-SEC-ADDR64-NEXT: 0000000000000060 D p
Test that we drop the thumb bit only from function addresses.

View File

@ -1,6 +1,6 @@
RUN: llvm-nm %p/Inputs/macho-universal.x86_64.i386 | FileCheck %s
CHECK: macho-universal.x86_64.i386:x86_64
CHECK: main
CHECK: 0000000100000f60 T _main
CHECK: macho-universal.x86_64.i386:i386
CHECK: main
CHECK: 00001fa0 T _main

View File

@ -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) {