Skip to content

Commit

Permalink
Fix some bugs in the posix output of llvm-nm. Which is documented on
Browse files Browse the repository at this point in the history
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
  • Loading branch information
enderby committed Mar 29, 2016
1 parent 499797f commit ae7cf58
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
Binary file not shown.
5 changes: 5 additions & 0 deletions test/tools/llvm-nm/X86/posixArchiveMachO.test
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/tools/llvm-nm/X86/posixELF.test
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions test/tools/llvm-nm/X86/posixMachO.test
Original file line number Diff line number Diff line change
@@ -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
33 changes: 21 additions & 12 deletions tools/llvm-nm/llvm-nm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -617,9 +617,13 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
if (PrintFileName) {
if (!ArchitectureName.empty())
outs() << "(for architecture " << ArchitectureName << "):";
if (!ArchiveName.empty())
outs() << ArchiveName << ":";
outs() << CurrentFilename << ": ";
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) {
Expand All @@ -630,8 +634,13 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
char SymbolAddrStr[18] = "";
char SymbolSizeStr[18] = "";

if (OutputFormat == sysv || I->TypeChar == 'U')
strcpy(SymbolAddrStr, printBlanks);
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);

Expand All @@ -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)) {
Expand Down

0 comments on commit ae7cf58

Please sign in to comment.