diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -104,6 +104,7 @@ bool adhocCodesign = false; bool emitFunctionStarts = false; bool emitBitcodeBundle = false; + bool emitDataInCodeInfo = false; bool emitEncryptionInfo = false; bool timeTraceEnabled = false; bool dataConst = false; diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1043,6 +1043,7 @@ config->implicitDylibs = !args.hasArg(OPT_no_implicit_dylibs); config->emitFunctionStarts = !args.hasArg(OPT_no_function_starts); config->emitBitcodeBundle = args.hasArg(OPT_bitcode_bundle); + config->emitDataInCodeInfo = !args.hasArg(OPT_no_data_in_code_info); config->dedupLiterals = args.hasArg(OPT_deduplicate_literals); // FIXME: Add a commandline flag for this too. diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -735,7 +735,8 @@ parseRelocations(sectionHeaders, sectionHeaders[i], subsections[i]); parseDebugInfo(); - parseDataInCode(); + if (config->emitDataInCodeInfo) + parseDataInCode(); } void ObjFile::parseDebugInfo() { diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -1170,8 +1170,7 @@ Flags<[HelpHidden]>, Group; def no_data_in_code_info : Flag<["-"], "no_data_in_code_info">, - HelpText<"This option is undocumented in ld64">, - Flags<[HelpHidden]>, + HelpText<"Do not emit data-in-code information">, Group; def debug_snapshot : Flag<["-"], "debug_snapshot">, HelpText<"This option is undocumented in ld64">, diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -666,7 +666,8 @@ make(symtabSection, indirectSymtabSection)); if (functionStartsSection) in.header->addLoadCommand(make(functionStartsSection)); - in.header->addLoadCommand(make(dataInCodeSection)); + if (dataInCodeSection) + in.header->addLoadCommand(make(dataInCodeSection)); if (config->emitEncryptionInfo) in.header->addLoadCommand(make>()); for (StringRef path : config->runtimePaths) @@ -865,7 +866,8 @@ indirectSymtabSection = make(); if (config->adhocCodesign) codeSignatureSection = make(); - dataInCodeSection = make(); + if (config->emitDataInCodeInfo) + dataInCodeSection = make(); if (config->emitFunctionStarts) functionStartsSection = make(); if (config->emitBitcodeBundle) diff --git a/lld/test/MachO/data-in-code.s b/lld/test/MachO/data-in-code.s --- a/lld/test/MachO/data-in-code.s +++ b/lld/test/MachO/data-in-code.s @@ -5,11 +5,10 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/bar.s -o %t/bar.o # RUN: %lld %t/foo.o %t/bar.o -o %t/main.exe -# RUN: llvm-objdump --private-headers %t/main.exe > %t/objdump +# RUN: llvm-otool -l %t/main.exe > %t/objdump # RUN: llvm-objdump --macho --data-in-code %t/main.exe >> %t/objdump # RUN: FileCheck %s < %t/objdump - # CHECK-LABEL: sectname __text # CHECK-NEXT: segname __TEXT # CHECK-NEXT: addr @@ -26,6 +25,11 @@ # CHECK-NEXT: [[#%x,TEXT + 28]] 24 JUMP_TABLE32 # CHECK-NEXT: [[#%x,TEXT + 68]] 12 JUMP_TABLE32 +# RUN: %lld %t/foo.o %t/bar.o -no_data_in_code_info -o %t/main.exe +# RUN: llvm-otool -l %t/main.exe | FileCheck --check-prefix=OMIT %s + +# OMIT-NOT: LC_DATA_IN_CODE + #--- foo.s .text .globl _main