[lld] 0e8d498 - [lld-macho] Standardize error messages
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 23 16:56:08 PST 2022
Author: Jez Ng
Date: 2022-12-23T19:44:56-05:00
New Revision: 0e8d4980a8bc5eead1bcbbb37324ccb25a374cde
URL: https://github.com/llvm/llvm-project/commit/0e8d4980a8bc5eead1bcbbb37324ccb25a374cde
DIFF: https://github.com/llvm/llvm-project/commit/0e8d4980a8bc5eead1bcbbb37324ccb25a374cde.diff
LOG: [lld-macho] Standardize error messages
Errors / warnings that originate from a particular file should be of the
form `$file: $message`.
Reviewed By: #lld-macho, keith
Differential Revision: https://reviews.llvm.org/D140634
Added:
Modified:
lld/MachO/Arch/ARM64.cpp
lld/MachO/InputFiles.cpp
lld/MachO/InputFiles.h
lld/test/MachO/invalid/invalid-loh.s
lld/test/MachO/invalid/no-id-dylink.yaml
lld/test/MachO/link-search-at-executable-path.s
lld/test/MachO/special-symbol-ld-install-name.s
lld/test/MachO/special-symbol-ld-previous.s
lld/test/MachO/sub-library.s
Removed:
################################################################################
diff --git a/lld/MachO/Arch/ARM64.cpp b/lld/MachO/Arch/ARM64.cpp
index 02e2d393ef6ee..6627d41fbec36 100644
--- a/lld/MachO/Arch/ARM64.cpp
+++ b/lld/MachO/Arch/ARM64.cpp
@@ -624,7 +624,8 @@ void ARM64::applyOptimizationHints(uint8_t *outBuf, const ObjFile &obj) const {
auto isValidOffset = [&](uint64_t offset) {
if (offset < sectionAddr || offset >= sectionAddr + section->getSize()) {
- error("linker optimization hint spans multiple sections");
+ error(toString(&obj) +
+ ": linker optimization hint spans multiple sections");
return false;
}
return true;
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 0dda9c787011d..6088572cab0b2 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -1648,11 +1648,12 @@ static bool isImplicitlyLinked(StringRef path) {
return false;
}
-static void loadReexport(StringRef path, DylibFile *umbrella,
+void DylibFile::loadReexport(StringRef path, DylibFile *umbrella,
const InterfaceFile *currentTopLevelTapi) {
DylibFile *reexport = findDylib(path, umbrella, currentTopLevelTapi);
if (!reexport)
- error("unable to locate re-export with install name " + path);
+ error(toString(this) + ": unable to locate re-export with install name " +
+ path);
}
DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella,
@@ -1676,7 +1677,7 @@ DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella,
} else if (!isBundleLoader) {
// macho_executable and macho_bundle don't have LC_ID_DYLIB,
// so it's OK.
- error("dylib " + toString(this) + " missing LC_ID_DYLIB load command");
+ error(toString(this) + ": dylib missing LC_ID_DYLIB load command");
return;
}
@@ -1705,8 +1706,8 @@ DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella,
if (dyldInfo && exportsTrie) {
// It's unclear what should happen in this case. Maybe we should only error
// out if the two load commands refer to
diff erent data?
- error("dylib " + toString(this) +
- " has both LC_DYLD_INFO_ONLY and LC_DYLD_EXPORTS_TRIE");
+ error(toString(this) +
+ ": dylib has both LC_DYLD_INFO_ONLY and LC_DYLD_EXPORTS_TRIE");
return;
} else if (dyldInfo) {
parseExportedSymbols(dyldInfo->export_off, dyldInfo->export_size);
@@ -2003,13 +2004,14 @@ void DylibFile::handleLDPreviousSymbol(StringRef name, StringRef originalName) {
VersionTuple start;
if (start.tryParse(startVersion)) {
- warn("failed to parse start version, symbol '" + originalName +
- "' ignored");
+ warn(toString(this) + ": failed to parse start version, symbol '" +
+ originalName + "' ignored");
return;
}
VersionTuple end;
if (end.tryParse(endVersion)) {
- warn("failed to parse end version, symbol '" + originalName + "' ignored");
+ warn(toString(this) + ": failed to parse end version, symbol '" +
+ originalName + "' ignored");
return;
}
if (config->platformInfo.minimum < start ||
@@ -2022,7 +2024,8 @@ void DylibFile::handleLDPreviousSymbol(StringRef name, StringRef originalName) {
if (!compatVersion.empty()) {
VersionTuple cVersion;
if (cVersion.tryParse(compatVersion)) {
- warn("failed to parse compatibility version, symbol '" + originalName +
+ warn(toString(this) +
+ ": failed to parse compatibility version, symbol '" + originalName +
"' ignored");
return;
}
@@ -2061,7 +2064,8 @@ void DylibFile::handleLDInstallNameSymbol(StringRef name,
std::tie(condition, installName) = name.split('$');
VersionTuple version;
if (!condition.consume_front("os") || version.tryParse(condition))
- warn("failed to parse os version, symbol '" + originalName + "' ignored");
+ warn(toString(this) + ": failed to parse os version, symbol '" +
+ originalName + "' ignored");
else if (version == config->platformInfo.minimum)
this->installName = saver().save(installName);
}
@@ -2076,7 +2080,7 @@ void DylibFile::handleLDHideSymbol(StringRef name, StringRef originalName) {
std::tie(minVersion, symbolName) = name.split('$');
VersionTuple versionTup;
if (versionTup.tryParse(minVersion)) {
- warn("Failed to parse hidden version, symbol `" + originalName +
+ warn(toString(this) + ": failed to parse hidden version, symbol `" + originalName +
"` ignored.");
return;
}
diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h
index 5ddf1b476295e..66cf92b84a81b 100644
--- a/lld/MachO/InputFiles.h
+++ b/lld/MachO/InputFiles.h
@@ -269,6 +269,8 @@ class DylibFile final : public InputFile {
void handleLDHideSymbol(StringRef name, StringRef originalName);
void checkAppExtensionSafety(bool dylibIsAppExtensionSafe) const;
void parseExportedSymbols(uint32_t offset, uint32_t size);
+ void loadReexport(StringRef path, DylibFile *umbrella,
+ const llvm::MachO::InterfaceFile *currentTopLevelTapi);
llvm::DenseSet<llvm::CachedHashStringRef> hiddenSymbols;
};
diff --git a/lld/test/MachO/invalid/invalid-loh.s b/lld/test/MachO/invalid/invalid-loh.s
index 9bf6b012709b8..20da17fa29edc 100644
--- a/lld/test/MachO/invalid/invalid-loh.s
+++ b/lld/test/MachO/invalid/invalid-loh.s
@@ -1,9 +1,10 @@
# REQUIRES: aarch64
+# RUN: rm -rf %t; mkdir -p %t
-# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t.o
-# RUN: not %lld -arch arm64 %t.o -o /dev/null 2>&1 | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t/test.o
+# RUN: not %lld -arch arm64 %t/test.o -o /dev/null 2>&1 | FileCheck %s
-# CHECK: error: linker optimization hint spans multiple sections
+# CHECK: error: {{.*}}test.o: linker optimization hint spans multiple sections
.globl _main
_main:
diff --git a/lld/test/MachO/invalid/no-id-dylink.yaml b/lld/test/MachO/invalid/no-id-dylink.yaml
index cc8b2f6174d7b..c022e0f1b4e33 100644
--- a/lld/test/MachO/invalid/no-id-dylink.yaml
+++ b/lld/test/MachO/invalid/no-id-dylink.yaml
@@ -3,7 +3,7 @@
# RUN: yaml2obj %s -o %t/libnoid.dylib
# RUN: echo ".globl _main; .text; _main: ret" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/no-id-dylink.o
# RUN: not %lld -o %t/no-id-dylink -L%t -lnoid %t/no-id-dylink.o 2>&1 | FileCheck %s
-# CHECK: error: dylib {{.*}}libnoid.dylib missing LC_ID_DYLIB load command
+# CHECK: error: {{.*}}libnoid.dylib: dylib missing LC_ID_DYLIB load command
## This YAML file was originally generated from linking the following source
## input with ld64 and passing the resulting binary through obj2yaml:
diff --git a/lld/test/MachO/link-search-at-executable-path.s b/lld/test/MachO/link-search-at-executable-path.s
index 29f2ac81f2718..5e0b6636eac5f 100644
--- a/lld/test/MachO/link-search-at-executable-path.s
+++ b/lld/test/MachO/link-search-at-executable-path.s
@@ -20,7 +20,7 @@
## It also doesn't help if the needed reexport isn't next to the library.
# RUN: not %lld -lSystem %t/main.o %t/libbar.dylib -o %t/test 2>&1 | FileCheck --check-prefix=ERR %s
-# ERR: error: unable to locate re-export with install name @executable_path/libfoo.dylib
+# ERR: error: {{.*}}libbar.dylib: unable to locate re-export with install name @executable_path/libfoo.dylib
#--- foo.s
.globl _foo
diff --git a/lld/test/MachO/special-symbol-ld-install-name.s b/lld/test/MachO/special-symbol-ld-install-name.s
index 8cd676dee1df6..0feb2bfb5bd1d 100644
--- a/lld/test/MachO/special-symbol-ld-install-name.s
+++ b/lld/test/MachO/special-symbol-ld-install-name.s
@@ -23,7 +23,7 @@
# RUN: %no-fatal-warnings-lld -o %t/libfoo3.dylib %t/libLDInstallNameInvalid.tbd %t/foo.o -dylib \
# RUN: -platform_version macos 11.0.0 11.0.0 2>&1 | FileCheck --check-prefix=INVALID-VERSION %s
-# INVALID-VERSION: failed to parse os version, symbol '$ld$install_name$os11.a$/New' ignored
+# INVALID-VERSION: libLDInstallNameInvalid.tbd(/Old): failed to parse os version, symbol '$ld$install_name$os11.a$/New' ignored
## Case 3: If there's another library that has '/New' as its original
## install_name, we should take current-version and compatibility-version from
diff --git a/lld/test/MachO/special-symbol-ld-previous.s b/lld/test/MachO/special-symbol-ld-previous.s
index eb143160e5873..d9059efad9906 100644
--- a/lld/test/MachO/special-symbol-ld-previous.s
+++ b/lld/test/MachO/special-symbol-ld-previous.s
@@ -59,9 +59,9 @@
# RUN: %no-fatal-warnings-lld -o %t/libfoo1.dylib %t/libLDPreviousInvalid.tbd %t/ref_xxx.o -dylib \
# RUN: -platform_version macos 11.0.0 11.0.0 2>&1 | FileCheck --check-prefix=INVALID-VERSION %s
-# INVALID-VERSION-DAG: failed to parse start version, symbol '$ld$previous$/New$1.2.3$1$3.a$14.0$$' ignored
-# INVALID-VERSION-DAG: failed to parse end version, symbol '$ld$previous$/New$1.2.3$1$3.0$14.b$$' ignored
-# INVALID-VERSION-DAG: failed to parse compatibility version, symbol '$ld$previous$/New$1.2.c$1$3.0$14.0$$' ignored
+# INVALID-VERSION-DAG: libLDPreviousInvalid.tbd(/Old): failed to parse start version, symbol '$ld$previous$/New$1.2.3$1$3.a$14.0$$' ignored
+# INVALID-VERSION-DAG: libLDPreviousInvalid.tbd(/Old): failed to parse end version, symbol '$ld$previous$/New$1.2.3$1$3.0$14.b$$' ignored
+# INVALID-VERSION-DAG: libLDPreviousInvalid.tbd(/Old): failed to parse compatibility version, symbol '$ld$previous$/New$1.2.c$1$3.0$14.0$$' ignored
#--- ref_xxx.s
.long _xxx at GOTPCREL
diff --git a/lld/test/MachO/sub-library.s b/lld/test/MachO/sub-library.s
index a67e12f08f22d..ed0a96aa58f90 100644
--- a/lld/test/MachO/sub-library.s
+++ b/lld/test/MachO/sub-library.s
@@ -58,7 +58,7 @@
# RUN: rm -f %t/libgoodbye.dylib
# RUN: not %lld -o %t/sub-library -L%t -lsuper %t/sub-library.o 2>&1 \
# RUN: | FileCheck %s --check-prefix=MISSING-REEXPORT -DDIR=%t
-# MISSING-REEXPORT: error: unable to locate re-export with install name [[DIR]]/libgoodbye.dylib
+# MISSING-REEXPORT: error: {{.*}}libsuper.dylib: unable to locate re-export with install name [[DIR]]/libgoodbye.dylib
## We can match dylibs without extensions too.
More information about the llvm-commits
mailing list