[llvm] cdcb60a - [llvm-libtool] Emit warnings for files without symbols

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 16 17:52:48 PST 2021


Author: Alexander Shaposhnikov
Date: 2021-02-16T17:52:12-08:00
New Revision: cdcb60a820571f7384920fb534ce23e7568bfc03

URL: https://github.com/llvm/llvm-project/commit/cdcb60a820571f7384920fb534ce23e7568bfc03
DIFF: https://github.com/llvm/llvm-project/commit/cdcb60a820571f7384920fb534ce23e7568bfc03.diff

LOG: [llvm-libtool] Emit warnings for files without symbols

1. Emit warnings for files without symbols.
2. Add -no_warning_for_no_symbols.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D95843

Added: 
    llvm/test/tools/llvm-libtool-darwin/no-symbols-warning.test

Modified: 
    llvm/docs/CommandGuide/llvm-libtool-darwin.rst
    llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandGuide/llvm-libtool-darwin.rst b/llvm/docs/CommandGuide/llvm-libtool-darwin.rst
index 6be849a22fd7..ccdf464301ed 100644
--- a/llvm/docs/CommandGuide/llvm-libtool-darwin.rst
+++ b/llvm/docs/CommandGuide/llvm-libtool-darwin.rst
@@ -64,6 +64,10 @@ OPTIONS
   :option:`-L` and before the default search path. The default search path
   includes directories `/lib`, `/usr/lib` and `/usr/local/lib`.
 
+.. option:: -no_warning_for_no_symbols
+
+   Do not warn about files that have no symbols.
+
 .. option:: -o <filename>
 
   Specify the output file name. Must be specified exactly once.

diff  --git a/llvm/test/tools/llvm-libtool-darwin/no-symbols-warning.test b/llvm/test/tools/llvm-libtool-darwin/no-symbols-warning.test
new file mode 100644
index 000000000000..4e53b259a146
--- /dev/null
+++ b/llvm/test/tools/llvm-libtool-darwin/no-symbols-warning.test
@@ -0,0 +1,50 @@
+## This test verifies that the tool emits a warning for object files
+## without symbols.
+
+# RUN: yaml2obj --docnum=1 %s -o %t-x86_64-empty.o
+# RUN: yaml2obj --docnum=2 %s -o %t-armv7-empty.o
+# RUN: echo 'target triple = "arm64-apple-ios8.0.0"' | llvm-as -o %t-empty.bc
+# RUN: yaml2obj %S/Inputs/input1.yaml -o %t-non-empty.o
+
+# RUN: llvm-libtool-darwin -static -o %t.lib %t-x86_64-empty.o 2>&1 | \
+# RUN:   FileCheck --check-prefix=WARNING %s -DPREFIX=%basename_t.tmp
+
+# WARNING: warning: [[PREFIX]]-x86_64-empty.o has no symbols
+
+# RUN: llvm-libtool-darwin -no_warning_for_no_symbols -static -o %t.lib \
+# RUN:   %t-x86_64-empty.o 2>&1 | \
+# RUN:   FileCheck %s --allow-empty --implicit-check-not='warning:'
+
+# RUN: llvm-libtool-darwin -static -o %t.lib %t-non-empty.o 2>&1 | \
+# RUN:   FileCheck %s --allow-empty --implicit-check-not='warning:'
+
+# RUN: llvm-libtool-darwin -arch_only x86_64 -static -o %t.lib \
+# RUN:   %t-non-empty.o %t-armv7-empty.o 2>&1 | \
+# RUN:   FileCheck %s --allow-empty --implicit-check-not='warning:'
+
+# RUN: llvm-libtool-darwin -static -o %t.lib %t-empty.bc 2>&1 | \
+# RUN:   FileCheck %s --allow-empty --implicit-check-not='warning:'
+
+## x86_64
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x1000007
+  cpusubtype:      0x3
+  filetype:        0x1
+  ncmds:           0
+  sizeofcmds:      0
+  flags:           0x2000
+  reserved:        0x0
+...
+
+## armv7
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACE
+  cputype:         0x0000000C
+  cpusubtype:      0x00000009
+  filetype:        0x00000001
+  ncmds:           0
+  sizeofcmds:      0
+  flags:           0x00002000

diff  --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
index 1ff6328ee6b6..021736418419 100644
--- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -89,6 +89,11 @@ static cl::opt<bool>
     VersionOption("V", cl::desc("Print the version number and exit"),
                   cl::cat(LibtoolCategory));
 
+static cl::opt<bool> NoWarningForNoSymbols(
+    "no_warning_for_no_symbols",
+    cl::desc("Do not warn about files that have no symbols"),
+    cl::cat(LibtoolCategory), cl::init(false));
+
 static const std::array<std::string, 3> StandardSearchDirs{
     "/lib",
     "/usr/lib",
@@ -251,6 +256,9 @@ static Error verifyAndAddMachOObject(MembersPerArchitectureMap &Members,
     return Error::success();
   }
 
+  if (!NoWarningForNoSymbols && O->symbols().empty())
+    WithColor::warning() << Member.MemberName + " has no symbols\n";
+
   uint64_t FileCPUID = getCPUID(FileCPUType, FileCPUSubtype);
   Members[FileCPUID].push_back(std::move(Member));
   return Error::success();


        


More information about the llvm-commits mailing list