diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -121,6 +121,7 @@ bool timeTraceEnabled = false; bool dataConst = false; bool dedupLiterals = true; + bool omitDebugInfo = false; uint32_t headerPad; uint32_t dylibCompatibilityVersion = 0; uint32_t dylibCurrentVersion = 0; diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1170,6 +1170,7 @@ args.hasArg(OPT_print_dylib_search) || getenv("RC_TRACE_DYLIB_SEARCHING"); config->printEachFile = args.hasArg(OPT_t); config->printWhyLoad = args.hasArg(OPT_why_load); + config->omitDebugInfo = args.hasArg(OPT_S); config->outputType = getOutputType(args); if (const Arg *arg = args.getLastArg(OPT_bundle_loader)) { if (config->outputType != MH_BUNDLE) diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -557,7 +557,6 @@ def S : Flag<["-"], "S">, HelpText<"Strip debug information (STABS or DWARF) from the output">, - Flags<[HelpHidden]>, Group; def x : Flag<["-"], "x">, HelpText<"Exclude non-global symbols from the output symbol table">, diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -876,6 +876,9 @@ } void SymtabSection::emitStabs() { + if (config->omitDebugInfo) + return; + for (const std::string &s : config->astPaths) { StabsEntry astStab(N_AST); astStab.strx = stringTableSection.addString(s); diff --git a/lld/test/MachO/stabs.s b/lld/test/MachO/stabs.s --- a/lld/test/MachO/stabs.s +++ b/lld/test/MachO/stabs.s @@ -53,13 +53,18 @@ ## Check that we emit relative path to object files in OSO entries ## when -oso_prefix is used. # RUN: cd %t && %lld -lSystem test.o foo.o no-debug.o -oso_prefix "%t" -o %t/test-rel -# RUN: dsymutil -s %t/test-rel | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH +# RUN: dsymutil -s %t/test-rel | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH # RUN: cd %t && %lld -lSystem test.o foo.o no-debug.o -oso_prefix "." -o %t/test-rel-dot -# RUN: dsymutil -s %t/test-rel-dot | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-DOT +# RUN: dsymutil -s %t/test-rel-dot | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-DOT ## Set HOME to %t (for ~ to expand to) # RUN: cd %t && env HOME=%t %lld -lSystem test.o foo.o no-debug.o -oso_prefix "~" -o %t/test-rel-tilde # RUN: dsymutil -s %t/test-rel-tilde | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH +## Check that we don't emit DWARF or stabs when -S is used +# RUN: %lld -lSystem test.o foo.o no-debug.o -S -o %t/test-no-debug +## grep returns an exit code of 1 if it cannot match the intended pattern. We +## expect to not find any entries which requires the exit code to be negated. +# RUN: llvm-nm -ap %t/test-no-debug | not grep -e ' - ' # RUN: cd %t && %lld -lSystem test.o foo.a no-debug.o -o %t/test # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \ @@ -77,7 +82,7 @@ # CHECK: (N_SO ) 00 0000 0000000000000000 '/tmp/test.cpp' # CHECK-NEXT: (N_OSO ) 03 0001 [[#%.16x,TEST_TIME]] '[[DIR]]/test.o' # REL-PATH: (N_OSO ) 03 0001 [[#%.16x,TEST_TIME]] '/test.o' -# REL-DOT: (N_OSO ) 03 0001 [[#%.16x,TEST_TIME]] 'test.o' +# REL-DOT: (N_OSO ) 03 0001 [[#%.16x,TEST_TIME]] 'test.o' # CHECK-NEXT: (N_STSYM ) [[#%.2d,MORE_DATA_ID + 1]] 0000 [[#%.16x,STATIC:]] '_static_var' # CHECK-NEXT: (N_FUN ) [[#%.2d,TEXT_ID + 1]] 0000 [[#%.16x,MAIN:]] '_main' # CHECK-NEXT: (N_FUN ) 00 0000 0000000000000006{{$}}