[lld/mac] Implement -arch_multiple

This is the other flag clang passes when calling clang with two -arch
flags (which means with this, `clang -arch x86_64 -arch arm64 -fuse-ld=lld ...`
now no longer prints any warnings \o/). Since clang calls the linker several
times in that setup, it's not clear to the user from which invocation the
errors are. The flag's help text is

    Specifies that the linker should augment error and warning messages
    with the architecture name.

In ld64, the only effect of the flag is that undefined symbols are prefaced
with

    Undefined symbols for architecture x86_64:

instead of the usual "Undefined symbols:". So for now, let's add this
only to undefined symbol errors too. That's probably the most common
linker diagnostic.

Another idea would be to prefix errors and warnings with "ld64.lld(x86_64):"
instead of the usual "ld64.lld:", but I'm not sure if people would
misunderstand that as a comment about the arch of ld itself.
But open to suggestions on what effect this flag should have :) And we
don't have to get it perfect now, we can iterate on it.

Differential Revision: https://reviews.llvm.org/D105450
This commit is contained in:
Nico Weber 2021-07-05 20:52:09 -04:00
parent 203b48c71a
commit 64be5b7d87
5 changed files with 17 additions and 2 deletions

View File

@ -95,6 +95,7 @@ struct Configuration {
Symbol *entry = nullptr; Symbol *entry = nullptr;
bool hasReexports = false; bool hasReexports = false;
bool allLoad = false; bool allLoad = false;
bool archMultiple = false;
bool forceLoadObjC = false; bool forceLoadObjC = false;
bool forceLoadSwift = false; bool forceLoadSwift = false;
bool staticLink = false; bool staticLink = false;

View File

@ -1139,6 +1139,7 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
error("--lto-O: invalid optimization level: " + Twine(config->ltoo)); error("--lto-O: invalid optimization level: " + Twine(config->ltoo));
config->runtimePaths = args::getStrings(args, OPT_rpath); config->runtimePaths = args::getStrings(args, OPT_rpath);
config->allLoad = args.hasArg(OPT_all_load); config->allLoad = args.hasArg(OPT_all_load);
config->archMultiple = args.hasArg(OPT_arch_multiple);
config->forceLoadObjC = args.hasArg(OPT_ObjC); config->forceLoadObjC = args.hasArg(OPT_ObjC);
config->forceLoadSwift = args.hasArg(OPT_force_load_swift_libs); config->forceLoadSwift = args.hasArg(OPT_force_load_swift_libs);
config->deadStripDylibs = args.hasArg(OPT_dead_strip_dylibs); config->deadStripDylibs = args.hasArg(OPT_dead_strip_dylibs);

View File

@ -877,7 +877,6 @@ def final_output : Separate<["-"], "final_output">,
Group<grp_rare>; Group<grp_rare>;
def arch_multiple : Flag<["-"], "arch_multiple">, def arch_multiple : Flag<["-"], "arch_multiple">,
HelpText<"Augment error and warning messages with the architecture name">, HelpText<"Augment error and warning messages with the architecture name">,
Flags<[HelpHidden]>,
Group<grp_rare>; Group<grp_rare>;
def dot : Separate<["-"], "dot">, def dot : Separate<["-"], "dot">,
MetaVarName<"<path>">, MetaVarName<"<path>">,

View File

@ -198,7 +198,10 @@ Defined *SymbolTable::addSynthetic(StringRef name, InputSection *isec,
void lld::macho::treatUndefinedSymbol(const Undefined &sym, StringRef source) { void lld::macho::treatUndefinedSymbol(const Undefined &sym, StringRef source) {
auto message = [source, &sym]() { auto message = [source, &sym]() {
std::string message = "undefined symbol: " + toString(sym); std::string message = "undefined symbol";
if (config->archMultiple)
message += (" for arch " + getArchitectureName(config->arch())).str();
message += ": " + toString(sym);
if (!source.empty()) if (!source.empty())
message += "\n>>> referenced by " + source.str(); message += "\n>>> referenced by " + source.str();
else else

View File

@ -0,0 +1,11 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t.o %s
# RUN: not %lld -o %t.out -arch_multiple %t.o 2>&1 | FileCheck %s
# CHECK: error: undefined symbol for arch x86_64: _foo
.globl _main
_main:
callq _foo
ret