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 --- /dev/null +++ b/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 +... diff --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp --- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp +++ b/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 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 StandardSearchDirs{ "/lib", "/usr/lib", @@ -241,6 +246,9 @@ Member.MemberName.data()); auto *O = dyn_cast(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()));