Fix some bugs in the posix output of llvm-nm. Which is documented on

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/nm.html .

1) For Mach-O files the code was not printing the values in hex as is the default.
2) The values printed had leading zeros which they should not have.
3) The address for undefined symbols was printed as spaces instead of 0.
4) With the -A option with posix output for an archive did not use square
brackets around the archive member name.

rdar://25311883 and rdar://25299678


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264778 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kevin Enderby 2016-03-29 20:18:07 +00:00
parent 499797f6dc
commit ae7cf58516
5 changed files with 31 additions and 17 deletions

View File

@ -0,0 +1,5 @@
# RUN: llvm-nm -P -A %p/Inputs/libExample.a.macho-x86_64 | FileCheck %s
# CHECK: libExample.a.macho-x86_64[example.o]: EH_frame0 s 30 0
# CHECK: libExample.a.macho-x86_64[example.o]: _f T 0 0
# CHECK: libExample.a.macho-x86_64[example.o]: _f.eh S 48 0

View File

@ -1,4 +1,4 @@
# RUN: llvm-nm -P %p/Inputs/hello.obj.elf-x86_64 | FileCheck %s
CHECK: main T 0000000000000000 0000000000000000
CHECK: puts U 0000000000000000
CHECK: main T 0 0
CHECK: puts U 0 0

View File

@ -1,7 +1,7 @@
# RUN: llvm-nm -P %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s
# CHECK: EH_frame0 s 104 0
# CHECK: L_.str s 59 0
# CHECK: EH_frame0 s 68 0
# CHECK: L_.str s 3b 0
# CHECK: _main T 0 0
# CHECK: _main.eh S 128 0
# CHECK: _main.eh S 80 0
# CHECK: _printf U 0 0

View File

@ -583,26 +583,26 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
printDashes = "----------------";
switch (AddressRadix) {
case Radix::o:
printFormat = "%016" PRIo64;
printFormat = OutputFormat == posix ? "%" PRIo64 : "%016" PRIo64;
break;
case Radix::x:
printFormat = "%016" PRIx64;
printFormat = OutputFormat == posix ? "%" PRIx64 : "%016" PRIx64;
break;
default:
printFormat = "%016" PRId64;
printFormat = OutputFormat == posix ? "%" PRId64 : "%016" PRId64;
}
} else {
printBlanks = " ";
printDashes = "--------";
switch (AddressRadix) {
case Radix::o:
printFormat = "%08" PRIo64;
printFormat = OutputFormat == posix ? "%" PRIo64 : "%08" PRIo64;
break;
case Radix::x:
printFormat = "%08" PRIx64;
printFormat = OutputFormat == posix ? "%" PRIx64 : "%08" PRIx64;
break;
default:
printFormat = "%08" PRId64;
printFormat = OutputFormat == posix ? "%" PRId64 : "%08" PRId64;
}
}
@ -617,10 +617,14 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
if (PrintFileName) {
if (!ArchitectureName.empty())
outs() << "(for architecture " << ArchitectureName << "):";
if (OutputFormat == posix && !ArchiveName.empty())
outs() << ArchiveName << "[" << CurrentFilename << "]: ";
else {
if (!ArchiveName.empty())
outs() << ArchiveName << ":";
outs() << CurrentFilename << ": ";
}
}
if ((JustSymbolName || (UndefinedOnly && isa<MachOObjectFile>(Obj) &&
OutputFormat != darwin)) && OutputFormat != posix) {
outs() << I->Name << "\n";
@ -630,8 +634,13 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
char SymbolAddrStr[18] = "";
char SymbolSizeStr[18] = "";
if (OutputFormat == sysv || I->TypeChar == 'U')
if (OutputFormat == sysv || I->TypeChar == 'U') {
if (OutputFormat == posix)
format(printFormat, I->Address)
.print(SymbolAddrStr, sizeof(SymbolAddrStr));
else
strcpy(SymbolAddrStr, printBlanks);
}
if (OutputFormat == sysv)
strcpy(SymbolSizeStr, printBlanks);
@ -656,7 +665,7 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
} else if (OutputFormat == posix) {
outs() << I->Name << " " << I->TypeChar << " ";
if (MachO)
outs() << I->Address << " " << "0" /* SymbolSizeStr */ << "\n";
outs() << SymbolAddrStr << " " << "0" /* SymbolSizeStr */ << "\n";
else
outs() << SymbolAddrStr << " " << SymbolSizeStr << "\n";
} else if (OutputFormat == bsd || (OutputFormat == darwin && !MachO)) {