]> granicus.if.org Git - llvm/commitdiff
Add a warning when the llvm-nm -print-size flag is used on a Mach-O file as
authorKevin Enderby <enderby@apple.com>
Wed, 25 Jan 2017 21:33:38 +0000 (21:33 +0000)
committerKevin Enderby <enderby@apple.com>
Wed, 25 Jan 2017 21:33:38 +0000 (21:33 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293099 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-nm/ARM/Inputs/print-size.macho-armv7m [new file with mode: 0644]
test/tools/llvm-nm/ARM/lit.local.cfg [new file with mode: 0644]
test/tools/llvm-nm/ARM/macho-print-size.test [new file with mode: 0644]
tools/llvm-nm/llvm-nm.cpp

diff --git a/test/tools/llvm-nm/ARM/Inputs/print-size.macho-armv7m b/test/tools/llvm-nm/ARM/Inputs/print-size.macho-armv7m
new file mode 100644 (file)
index 0000000..0014b68
Binary files /dev/null and b/test/tools/llvm-nm/ARM/Inputs/print-size.macho-armv7m differ
diff --git a/test/tools/llvm-nm/ARM/lit.local.cfg b/test/tools/llvm-nm/ARM/lit.local.cfg
new file mode 100644 (file)
index 0000000..236e1d3
--- /dev/null
@@ -0,0 +1,2 @@
+if not 'ARM' in config.root.targets:
+    config.unsupported = True
diff --git a/test/tools/llvm-nm/ARM/macho-print-size.test b/test/tools/llvm-nm/ARM/macho-print-size.test
new file mode 100644 (file)
index 0000000..f32a7aa
--- /dev/null
@@ -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.
index aa89f89c31d56f354d9a91f455ec0334cda4e535..2bdda318ebf10062b4cbf90e4cfdb68b519d8d9e 100644 (file)
@@ -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(SymbolicFile *O, std::string &Filename) {
   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::string &Filename) {
           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::string &Filename) {
     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);