diff options
author | Kevin Enderby <enderby@apple.com> | 2016-03-29 20:18:07 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2016-03-29 20:18:07 +0000 |
commit | 2d431c3dba75ddf1b78a6d70d0585985e157ae1d (patch) | |
tree | 66b90df7d23110fc2b7e0200ad298647107b368c /llvm/tools/llvm-nm/llvm-nm.cpp | |
parent | ee2f96c79b920ab3375e20281805eeff5d93ebc4 (diff) | |
download | bcm5719-llvm-2d431c3dba75ddf1b78a6d70d0585985e157ae1d.tar.gz bcm5719-llvm-2d431c3dba75ddf1b78a6d70d0585985e157ae1d.zip |
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
llvm-svn: 264778
Diffstat (limited to 'llvm/tools/llvm-nm/llvm-nm.cpp')
-rw-r--r-- | llvm/tools/llvm-nm/llvm-nm.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index 65e9156a74d..241ee8fb40f 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -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,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) { @@ -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); @@ -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)) { |