[llvm] r293099 - Add a warning when the llvm-nm -print-size flag is used on a Mach-O file as

Kevin Enderby via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 25 13:33:38 PST 2017


Author: enderby
Date: Wed Jan 25 15:33:38 2017
New Revision: 293099

URL: http://llvm.org/viewvc/llvm-project?rev=293099&view=rev
Log:
Add a warning when the llvm-nm -print-size flag is used on a Mach-O file as
Mach-O files don’t have size information about the symbols in the object file
format unlike ELF.

Also add the part of the fix to llvm-nm that was missed with r290001 so
-arch armv7m works.

rdar://25681018

Added:
    llvm/trunk/test/tools/llvm-nm/ARM/
    llvm/trunk/test/tools/llvm-nm/ARM/Inputs/
    llvm/trunk/test/tools/llvm-nm/ARM/Inputs/print-size.macho-armv7m   (with props)
    llvm/trunk/test/tools/llvm-nm/ARM/lit.local.cfg
    llvm/trunk/test/tools/llvm-nm/ARM/macho-print-size.test
Modified:
    llvm/trunk/tools/llvm-nm/llvm-nm.cpp

Added: llvm/trunk/test/tools/llvm-nm/ARM/Inputs/print-size.macho-armv7m
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/ARM/Inputs/print-size.macho-armv7m?rev=293099&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/tools/llvm-nm/ARM/Inputs/print-size.macho-armv7m
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: llvm/trunk/test/tools/llvm-nm/ARM/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/ARM/lit.local.cfg?rev=293099&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/ARM/lit.local.cfg (added)
+++ llvm/trunk/test/tools/llvm-nm/ARM/lit.local.cfg Wed Jan 25 15:33:38 2017
@@ -0,0 +1,2 @@
+if not 'ARM' in config.root.targets:
+    config.unsupported = True

Added: llvm/trunk/test/tools/llvm-nm/ARM/macho-print-size.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/ARM/macho-print-size.test?rev=293099&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/ARM/macho-print-size.test (added)
+++ llvm/trunk/test/tools/llvm-nm/ARM/macho-print-size.test Wed Jan 25 15:33:38 2017
@@ -0,0 +1,3 @@
+@ RUN: llvm-nm -print-size -arch armv7m %p/Inputs/print-size.macho-armv7m 2>&1 | FileCheck %s
+
+@ CHECK: llvm-nm: warning sizes with -print-size for Mach-O files are always zero.

Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=293099&r1=293098&r2=293099&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Wed Jan 25 15:33:38 2017
@@ -129,6 +129,7 @@ cl::opt<bool> PrintSize("print-size",
                         cl::desc("Show symbol size instead of address"));
 cl::alias PrintSizeS("S", cl::desc("Alias for --print-size"),
                      cl::aliasopt(PrintSize), cl::Grouping);
+bool MachOPrintSizeWarning = false;
 
 cl::opt<bool> SizeSort("size-sort", cl::desc("Sort symbols by size"));
 
@@ -1057,15 +1058,19 @@ static bool checkMachOAndArchFlags(Symbo
   MachO::mach_header H;
   MachO::mach_header_64 H_64;
   Triple T;
+  const char *McpuDefault, *ArchFlag;
   if (MachO->is64Bit()) {
     H_64 = MachO->MachOObjectFile::getHeader64();
-    T = MachOObjectFile::getArchTriple(H_64.cputype, H_64.cpusubtype);
+    T = MachOObjectFile::getArchTriple(H_64.cputype, H_64.cpusubtype,
+                                       &McpuDefault, &ArchFlag);
   } else {
     H = MachO->MachOObjectFile::getHeader();
-    T = MachOObjectFile::getArchTriple(H.cputype, H.cpusubtype);
+    T = MachOObjectFile::getArchTriple(H.cputype, H.cpusubtype,
+                                       &McpuDefault, &ArchFlag);
   }
+  const std::string ArchFlagName(ArchFlag);
   if (none_of(ArchFlags, [&](const std::string &Name) {
-        return Name == T.getArchName();
+        return Name == ArchFlagName;
       })) {
     error("No architecture specified", Filename);
     return false;
@@ -1120,6 +1125,11 @@ static void dumpSymbolNamesFromFile(std:
           continue;
         }
         if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) {
+          if (!MachOPrintSizeWarning && PrintSize &&  isa<MachOObjectFile>(O)) {
+            errs() << ToolName << ": warning sizes with -print-size for Mach-O "
+                      "files are always zero.\n";
+            MachOPrintSizeWarning = true;
+          }
           if (!checkMachOAndArchFlags(O, Filename))
             return;
           if (!PrintFileName) {
@@ -1357,6 +1367,11 @@ static void dumpSymbolNamesFromFile(std:
     return;
   }
   if (SymbolicFile *O = dyn_cast<SymbolicFile>(&Bin)) {
+    if (!MachOPrintSizeWarning && PrintSize &&  isa<MachOObjectFile>(O)) {
+      errs() << ToolName << ": warning sizes with -print-size for Mach-O files "
+                "are always zero.\n";
+      MachOPrintSizeWarning = true;
+    }
     if (!checkMachOAndArchFlags(O, Filename))
       return;
     dumpSymbolNamesFromObject(*O, true);




More information about the llvm-commits mailing list