[lld] 64c1734 - [lld/mac] Write -v output to stderr
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 2 10:59:33 PDT 2021
Author: Nico Weber
Date: 2021-11-02T13:59:14-04:00
New Revision: 64c1734438256639ecf41c8349563c9292a617ac
URL: https://github.com/llvm/llvm-project/commit/64c1734438256639ecf41c8349563c9292a617ac
DIFF: https://github.com/llvm/llvm-project/commit/64c1734438256639ecf41c8349563c9292a617ac.diff
LOG: [lld/mac] Write -v output to stderr
This matches ld64, and it's conceivable that projects try to read
this information off stderr for that reason.
--version keeps writing to stdout.
Differential Revision: https://reviews.llvm.org/D113020
Added:
Modified:
lld/Common/ErrorHandler.cpp
lld/MachO/Driver.cpp
lld/include/lld/Common/ErrorHandler.h
lld/test/MachO/syslibroot.test
Removed:
################################################################################
diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp
index c8c5ffed71268..399b6cac75470 100644
--- a/lld/Common/ErrorHandler.cpp
+++ b/lld/Common/ErrorHandler.cpp
@@ -192,12 +192,12 @@ void ErrorHandler::log(const Twine &msg) {
reportDiagnostic(logName, Colors::RESET, "", msg);
}
-void ErrorHandler::message(const Twine &msg) {
+void ErrorHandler::message(const Twine &msg, llvm::raw_ostream &s) {
if (disableOutput)
return;
std::lock_guard<std::mutex> lock(mu);
- lld::outs() << msg << "\n";
- lld::outs().flush();
+ s << msg << "\n";
+ s.flush();
}
void ErrorHandler::warn(const Twine &msg) {
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 9ecc05e1c8d2f..826e5e816adc2 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1364,15 +1364,17 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
config->platform() == PlatformKind::macOS);
if (args.hasArg(OPT_v)) {
- message(getLLDVersion());
+ message(getLLDVersion(), lld::errs());
message(StringRef("Library search paths:") +
- (config->librarySearchPaths.empty()
- ? ""
- : "\n\t" + join(config->librarySearchPaths, "\n\t")));
+ (config->librarySearchPaths.empty()
+ ? ""
+ : "\n\t" + join(config->librarySearchPaths, "\n\t")),
+ lld::errs());
message(StringRef("Framework search paths:") +
- (config->frameworkSearchPaths.empty()
- ? ""
- : "\n\t" + join(config->frameworkSearchPaths, "\n\t")));
+ (config->frameworkSearchPaths.empty()
+ ? ""
+ : "\n\t" + join(config->frameworkSearchPaths, "\n\t")),
+ lld::errs());
}
config->progName = argsArr[0];
diff --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h
index 04602fad6d516..d95a2537c1f2c 100644
--- a/lld/include/lld/Common/ErrorHandler.h
+++ b/lld/include/lld/Common/ErrorHandler.h
@@ -109,7 +109,7 @@ class ErrorHandler {
void error(const Twine &msg, ErrorTag tag, ArrayRef<StringRef> args);
[[noreturn]] void fatal(const Twine &msg);
void log(const Twine &msg);
- void message(const Twine &msg);
+ void message(const Twine &msg, llvm::raw_ostream &s);
void warn(const Twine &msg);
void reset() {
@@ -137,7 +137,9 @@ inline void error(const Twine &msg, ErrorTag tag, ArrayRef<StringRef> args) {
}
[[noreturn]] inline void fatal(const Twine &msg) { errorHandler().fatal(msg); }
inline void log(const Twine &msg) { errorHandler().log(msg); }
-inline void message(const Twine &msg) { errorHandler().message(msg); }
+inline void message(const Twine &msg, llvm::raw_ostream &s = outs()) {
+ errorHandler().message(msg, s);
+}
inline void warn(const Twine &msg) { errorHandler().warn(msg); }
inline uint64_t errorCount() { return errorHandler().errorCount; }
diff --git a/lld/test/MachO/syslibroot.test b/lld/test/MachO/syslibroot.test
index 1a71ea538a0f5..55c08104358d0 100644
--- a/lld/test/MachO/syslibroot.test
+++ b/lld/test/MachO/syslibroot.test
@@ -1,68 +1,77 @@
# Ensure that a nonexistent path is ignored with a syslibroot
+# Don't use %lld to not pick up the default syslibroot flag.
-RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib -o /dev/null \
-RUN: -syslibroot /var/empty | FileCheck %s -check-prefix CHECK-NONEXISTENT-SYSLIBROOT
+RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib \
+RUN: -o /dev/null -syslibroot /var/empty 2>&1 \
+RUN: | FileCheck %s -check-prefix CHECK-NONEXISTENT-SYSLIBROOT
CHECK-NONEXISTENT-SYSLIBROOT: Library search paths:
CHECK-NONEXISTENT-SYSLIBROOT-NEXT: Framework search paths:
RUN: mkdir -p %t/usr/lib
-RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib -o /dev/null \
-RUN: -syslibroot %t 2>&1 | FileCheck %s -check-prefix CHECK-SYSLIBROOT -DROOT=%t
+RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib \
+RUN: -o /dev/null -syslibroot %t 2>&1 \
+RUN: | FileCheck %s -check-prefix CHECK-SYSLIBROOT -DROOT=%t
CHECK-SYSLIBROOT-NOT: directory not found{{.*}}usr/local/lib
CHECK-SYSLIBROOT: Library search paths:
CHECK-SYSLIBROOT-NEXT: [[ROOT]]/usr/lib
RUN: mkdir -p %t/Library/libxml2-development
-RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib -o /dev/null \
-RUN: -syslibroot %t -L /Library/libxml2-development | FileCheck %s -check-prefix CHECK-ABSOLUTE-PATH-REROOTED -DROOT=%t
+RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib \
+RUN: -o /dev/null -syslibroot %t -L /Library/libxml2-development 2>&1 \
+RUN: | FileCheck %s -check-prefix CHECK-ABSOLUTE-PATH-REROOTED -DROOT=%t
CHECK-ABSOLUTE-PATH-REROOTED: Library search paths:
CHECK-ABSOLUTE-PATH-REROOTED: [[ROOT]]/Library/libxml2-development
CHECK-ABSOLUTE-PATH-REROOTED: [[ROOT]]/usr/lib
-RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib -o /dev/null \
-RUN: -syslibroot %t -L %t/Library/libxml2-development | FileCheck %s -check-prefix CHECK-PATH-WITHOUT-REROOT -DPATH=%t/Library/libxml2-development
+RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib \
+RUN: -o /dev/null -syslibroot %t -L %t/Library/libxml2-development 2>&1 \
+RUN: | FileCheck %s -check-prefix CHECK-PATH-WITHOUT-REROOT -DPATH=%t/Library/libxml2-development
CHECK-PATH-WITHOUT-REROOT: Library search paths:
CHECK-PATH-WITHOUT-REROOT-NEXT: [[PATH]]
RUN: mkdir -p %t.2/usr/lib
-RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib -o /dev/null \
-RUN: -syslibroot %t -syslibroot %t.2 | FileCheck %s -check-prefix CHECK-SYSLIBROOT-MATRIX -DROOT=%t
+RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib \
+RUN: -o /dev/null -syslibroot %t -syslibroot %t.2 2>&1 \
+RUN: | FileCheck %s -check-prefix CHECK-SYSLIBROOT-MATRIX -DROOT=%t
CHECK-SYSLIBROOT-MATRIX: Library search paths:
CHECK-SYSLIBROOT-MATRIX: [[ROOT]]/usr/lib
CHECK-SYSLIBROOT-MATRIX: [[ROOT]].2/usr/lib
-RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib -o /dev/null \
-RUN: -syslibroot %t -syslibroot %t.2 -syslibroot / | \
-RUN: FileCheck %s -check-prefix CHECK-SYSLIBROOT-IGNORED -DROOT=%t
+RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib \
+RUN: -o /dev/null -syslibroot %t -syslibroot %t.2 -syslibroot / 2>&1 \
+RUN: | FileCheck %s -check-prefix CHECK-SYSLIBROOT-IGNORED -DROOT=%t
CHECK-SYSLIBROOT-IGNORED: Library search paths:
CHECK-SYSLIBROOT-IGNORED-NOT: [[ROOT]]/usr/lib
CHECK-SYSLIBROOT-IGNORED-NOT: [[ROOT]].2/usr/lib
RUN: mkdir -p %t/System/Library/Frameworks
-RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib -o /dev/null \
-RUN: -syslibroot %t | FileCheck %s -check-prefix CHECK-SYSLIBROOT-FRAMEWORK -DROOT=%t
+RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib \
+RUN: -o /dev/null -syslibroot %t 2>&1 \
+RUN: | FileCheck %s -check-prefix CHECK-SYSLIBROOT-FRAMEWORK -DROOT=%t
CHECK-SYSLIBROOT-FRAMEWORK: Framework search paths:
CHECK-SYSLIBROOT-FRAMEWORK: [[ROOT]]/System/Library/Frameworks
RUN: mkdir -p %t/Library/Frameworks
RUN: mkdir -p %t.2/Library/Frameworks
-RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib -o /dev/null \
-RUN: -syslibroot %t -syslibroot %t.2 -F /Library/Frameworks | \
-RUN: FileCheck %s -check-prefix CHECK-SYSLIBROOT-FRAMEWORK-MATRIX -DROOT=%t
+RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib \
+RUN: -o /dev/null -syslibroot %t -syslibroot %t.2 \
+RUN: -F /Library/Frameworks 2>&1 \
+RUN: | FileCheck %s -check-prefix CHECK-SYSLIBROOT-FRAMEWORK-MATRIX -DROOT=%t
CHECK-SYSLIBROOT-FRAMEWORK-MATRIX: Framework search paths:
CHECK-SYSLIBROOT-FRAMEWORK-MATRIX: [[ROOT]]/Library/Frameworks
CHECK-SYSLIBROOT-FRAMEWORK-MATRIX: [[ROOT]].2/Library/Frameworks
-RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib -o /dev/null \
-RUN: -syslibroot %t -syslibroot %t.2 -syslibroot / -F /Library/Frameworks | \
-RUN: FileCheck %s -check-prefix CHECK-SYSLIBROOT-FRAMEWORK-IGNORED -DROOT=%t
+RUN: ld64.lld -arch x86_64 -platform_version macos 10 11 -v -dylib \
+RUN: -o /dev/null -syslibroot %t -syslibroot %t.2 -syslibroot / \
+RUN: -F /Library/Frameworks 2>&1 \
+RUN: | FileCheck %s -check-prefix CHECK-SYSLIBROOT-FRAMEWORK-IGNORED -DROOT=%t
CHECK-SYSLIBROOT-FRAMEWORK-IGNORED: Framework search paths:
CHECK-SYSLIBROOT-FRAMEWORK-IGNORED-NOT: [[ROOT]]/Library/Frameworks
More information about the llvm-commits
mailing list