diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -110,6 +110,7 @@ std::vector librarySearchPaths; std::vector frameworkSearchPaths; std::vector runtimePaths; + std::vector astPaths; std::vector explicitUndefineds; // There are typically very few custom segmentProtections, so use a vector // instead of a map. diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -913,6 +913,7 @@ config->mapFile = args.getLastArgValue(OPT_map); config->outputFile = args.getLastArgValue(OPT_o, "a.out"); + config->astPaths = args.getAllArgValues(OPT_add_ast_path); config->headerPad = args::getHex(args, OPT_headerpad, /*Default=*/32); config->headerPadMaxInstallNames = args.hasArg(OPT_headerpad_max_install_names); diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -511,7 +511,7 @@ HelpText<"Save intermediate LTO compilation results">, Group; -def grp_symtab : OptionGroup<"symtab">, HelpText<"SYMBOL TABLE OPTIMIZATIONS">; +def grp_symtab : OptionGroup<"symtab">, HelpText<"SYMBOL TABLE">; def S : Flag<["-"], "S">, HelpText<"Strip debug information (STABS or DWARF) from the output">, @@ -536,6 +536,10 @@ HelpText<"Remove the prefix from OSO symbols in the debug map">, Flags<[HelpHidden]>, Group; +def add_ast_path : Separate<["-"], "add_ast_path">, + MetaVarName<"">, + HelpText<"AST paths will be emitted as STABS">, + Group; def grp_bitcode : OptionGroup<"bitcode">, HelpText<"BITCODE BUILD FLOW">; @@ -1092,10 +1096,6 @@ def grp_undocumented : OptionGroup<"undocumented">, HelpText<"UNDOCUMENTED">; -def add_ast_path : Flag<["-"], "add_ast_path">, - HelpText<"This option is undocumented in ld64">, - Flags<[HelpHidden]>, - Group; def add_linker_option : Flag<["-"], "add_linker_option">, HelpText<"This option is undocumented in ld64">, Flags<[HelpHidden]>, diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -680,6 +680,12 @@ } void SymtabSection::emitStabs() { + for (const std::string &s : config->astPaths) { + StabsEntry astStab(N_AST); + astStab.strx = stringTableSection.addString(s); + stabs.emplace_back(std::move(astStab)); + } + std::vector symbolsNeedingStabs; for (const SymtabEntry &entry : concat(localSymbols, externalSymbols)) { @@ -705,8 +711,7 @@ InputFile *lastFile = nullptr; for (Defined *defined : symbolsNeedingStabs) { InputSection *isec = defined->isec; - ObjFile *file = dyn_cast(isec->file); - assert(file); + ObjFile *file = cast(isec->file); if (lastFile == nullptr || lastFile != file) { if (lastFile != nullptr) diff --git a/lld/test/MachO/add-ast-path.s b/lld/test/MachO/add-ast-path.s new file mode 100644 --- /dev/null +++ b/lld/test/MachO/add-ast-path.s @@ -0,0 +1,11 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o +# RUN: %lld -lSystem %t.o -o %t -add_ast_path asdf -add_ast_path fdsa +# RUN: dsymutil -s %t | FileCheck %s +# CHECK: [ 0] {{[0-9a-f]+}} 32 (N_AST ) 00 0000 0000000000000000 'asdf' +# CHECK-NEXT: [ 1] {{[0-9a-f]+}} 32 (N_AST ) 00 0000 0000000000000000 'fdsa' + +.globl _main + +_main: + ret