[lld] c23b92a - [lld-macho] Support -add_ast_path
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 8 11:13:22 PDT 2021
Author: Jez Ng
Date: 2021-04-08T14:12:55-04:00
New Revision: c23b92acd0654bd63942fd70d39c7955354ba3f6
URL: https://github.com/llvm/llvm-project/commit/c23b92acd0654bd63942fd70d39c7955354ba3f6
DIFF: https://github.com/llvm/llvm-project/commit/c23b92acd0654bd63942fd70d39c7955354ba3f6.diff
LOG: [lld-macho] Support -add_ast_path
Swift builds seem to use it. All it requires is emitting the
corresponding paths as STABS.
Fixes llvm.org/PR49385.
Reviewed By: clayborg
Differential Revision: https://reviews.llvm.org/D100076
Added:
lld/test/MachO/add-ast-path.s
Modified:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/Options.td
lld/MachO/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 693c348d9153..b07c711bbb73 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -110,6 +110,7 @@ struct Configuration {
std::vector<llvm::StringRef> librarySearchPaths;
std::vector<llvm::StringRef> frameworkSearchPaths;
std::vector<llvm::StringRef> runtimePaths;
+ std::vector<std::string> astPaths;
std::vector<Symbol *> 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
index 7f3415700e33..8175afe1569b 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -913,6 +913,7 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
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
index e4bdc4baa45d..23a90346de0a 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -511,7 +511,7 @@ def save_temps : Flag<["-"], "save-temps">,
HelpText<"Save intermediate LTO compilation results">,
Group<grp_introspect>;
-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 @@ def oso_prefix : Separate<["-"], "oso_prefix">,
HelpText<"Remove the prefix <path> from OSO symbols in the debug map">,
Flags<[HelpHidden]>,
Group<grp_symtab>;
+def add_ast_path : Separate<["-"], "add_ast_path">,
+ MetaVarName<"<path>">,
+ HelpText<"AST paths will be emitted as STABS">,
+ Group<grp_symtab>;
def grp_bitcode : OptionGroup<"bitcode">, HelpText<"BITCODE BUILD FLOW">;
@@ -1092,10 +1096,6 @@ def slow_stubs : Flag<["-"], "slow_stubs">,
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<grp_undocumented>;
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
index 5bba34d7bf78..60fd36db200c 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -680,6 +680,12 @@ void SymtabSection::emitEndFunStab(Defined *defined) {
}
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<Defined *> symbolsNeedingStabs;
for (const SymtabEntry &entry :
concat<SymtabEntry>(localSymbols, externalSymbols)) {
@@ -705,8 +711,7 @@ void SymtabSection::emitStabs() {
InputFile *lastFile = nullptr;
for (Defined *defined : symbolsNeedingStabs) {
InputSection *isec = defined->isec;
- ObjFile *file = dyn_cast<ObjFile>(isec->file);
- assert(file);
+ ObjFile *file = cast<ObjFile>(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
index 000000000000..c8d63592de4e
--- /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
More information about the llvm-commits
mailing list