aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
diff options
context:
space:
mode:
authorKeith Smiley <keithbsmiley@gmail.com>2022-02-02 17:46:11 -0800
committerKeith Smiley <keithbsmiley@gmail.com>2022-02-07 14:39:21 -0800
commit4c12a75e69927c40b992d568187504b2ee268e92 (patch)
tree122639dbbe859f4f0a4f66661e829b84bcb683c9 /llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
parentd1ecfaa097b1b5602c778acccbd687173ac434e8 (diff)
downloadllvm-4c12a75e69927c40b992d568187504b2ee268e92.zip
llvm-4c12a75e69927c40b992d568187504b2ee268e92.tar.gz
llvm-4c12a75e69927c40b992d568187504b2ee268e92.tar.bz2
[llvm-libtool-darwin] Add -warnings_as_errors
libtool can currently produce 2 warnings: 1. No symbols were in the object file 2. An object file with the same basename was specified multiple times The first warning here is often harmless and may just mean you have some translation units with no symbols for the target you're building for. The second warning can lead to real issues like those mentioned in https://reviews.llvm.org/D113130 where ODR violations can slip in. This introduces a new -warnings_as_errors flag that can be used by build systems that want to verify they never hit these warnings. For example with bazel the libtool caller first uniques names to make sure the duplicate base name case is not possible, but if that doesn't work as expected, having it fail would be preferred. It's also worth noting that llvm-libtool-darwin works around an issue that cctools libtool experiences related to debug info and duplicate basenames, the workaround is described here: https://github.com/llvm/llvm-project/blob/30baa5d2a450d5e302d8cba3fc7a26a59d4b7ae1/llvm/lib/Object/ArchiveWriter.cpp#L424-L465 And it avoids this bug: https://github.com/keith/radars/tree/f0cbbb1c37126ec6528c132510b29e08566377a7/DuplicateBasenameIssue Differential Revision: https://reviews.llvm.org/D118931
Diffstat (limited to 'llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp')
-rw-r--r--llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
index cd56e10..0c429c0 100644
--- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -98,6 +98,11 @@ static cl::opt<bool> NoWarningForNoSymbols(
cl::desc("Do not warn about files that have no symbols"),
cl::cat(LibtoolCategory), cl::init(false));
+static cl::opt<bool> WarningsAsErrors("warnings_as_errors",
+ cl::desc("Treat warnings as errors"),
+ cl::cat(LibtoolCategory),
+ cl::init(false));
+
static const std::array<std::string, 3> StandardSearchDirs{
"/lib",
"/usr/lib",
@@ -370,10 +375,17 @@ private:
return Error::success();
}
- if (!NoWarningForNoSymbols && O->symbols().empty())
- WithColor::warning() << "'" + Member.MemberName +
- "': has no symbols for architecture " +
- O->getArchTriple().getArchName() + "\n";
+ if (!NoWarningForNoSymbols && O->symbols().empty()) {
+ Error E = createFileError(
+ Member.MemberName,
+ createStringError(std::errc::invalid_argument,
+ "has no symbols for architecture %s",
+ O->getArchTriple().getArchName().str().c_str()));
+
+ if (WarningsAsErrors)
+ return E;
+ WithColor::defaultWarningHandler(std::move(E));
+ }
uint64_t FileCPUID = getCPUID(FileCPUType, FileCPUSubtype);
Builder.Data.MembersPerArchitecture[FileCPUID].push_back(
@@ -581,8 +593,11 @@ static Error createStaticLibrary(const Config &C) {
const auto &NewMembers = DataOrError->MembersPerArchitecture;
- if (Error E = checkForDuplicates(NewMembers))
+ if (Error E = checkForDuplicates(NewMembers)) {
+ if (WarningsAsErrors)
+ return E;
WithColor::defaultWarningHandler(std::move(E));
+ }
if (NewMembers.size() == 1)
return writeArchive(OutputFile, NewMembers.begin()->second.getMembers(),