[PATCH] D95843: [tools][llvm-libtool] Emit warnings for files without symbols
Alexander Shaposhnikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 1 18:43:13 PST 2021
alexshap created this revision.
alexshap added reviewers: smeenai, compnerd.
alexshap requested review of this revision.
Herald added a project: LLVM.
1. Emit warnings for files without symbols.
2. Add -no_warning_for_no_symbols (consistent with cctools libtool, see https://www.manpagez.com/man/1/libtool/osx-10.11.6.php)
Test plan: make check-all
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95843
Files:
llvm/test/tools/llvm-libtool-darwin/no-symbols-warning.test
llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
Index: llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
===================================================================
--- llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -89,6 +89,11 @@
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",
@@ -241,6 +246,9 @@
Member.MemberName.data());
auto *O = dyn_cast<MachOObjectFile>(ObjOrErr->get());
+ if (!NoWarningForNoSymbols && O->symbols().empty())
+ WithColor::warning() << Member.MemberName + " has no symbols.\n";
+
uint32_t FileCPUType, FileCPUSubtype;
std::tie(FileCPUType, FileCPUSubtype) = MachO::getCPUTypeFromArchitecture(
MachO::getArchitectureFromName(O->getArchTriple().getArchName()));
Index: llvm/test/tools/llvm-libtool-darwin/no-symbols-warning.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-libtool-darwin/no-symbols-warning.test
@@ -0,0 +1,28 @@
+## This test verifies that the tool emits a warning for object files
+## without symbols.
+
+# RUN: yaml2obj %s -o %t-empty.o
+# RUN: yaml2obj %S/Inputs/input1.yaml -o %t-non-empty.o
+
+# RUN: llvm-libtool-darwin -static -o %t.lib %t-empty.o 2>&1 | \
+# RUN: FileCheck --check-prefix=WARNING %s -DPREFIX=%basename_t.tmp
+
+# WARNING: warning: [[PREFIX]]-empty.o has no symbols.
+
+# RUN: llvm-libtool-darwin -no_warning_for_no_symbols -static -o %t.lib %t-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:'
+
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x1000007
+ cpusubtype: 0x3
+ filetype: 0x1
+ ncmds: 0
+ sizeofcmds: 0
+ flags: 0x2000
+ reserved: 0x0
+...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95843.320660.patch
Type: text/x-patch
Size: 2281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210202/53ee669e/attachment.bin>
More information about the llvm-commits
mailing list