From b579938d40b48f24e05e4022a647be933ffc1b89 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 15 Jun 2021 21:38:29 -0400 Subject: [PATCH] [lld/mac] Add support for -no_data_in_code_info flag Differential Revision: https://reviews.llvm.org/D104345 --- lld/MachO/Config.h | 1 + lld/MachO/Driver.cpp | 1 + lld/MachO/InputFiles.cpp | 3 ++- lld/MachO/Options.td | 3 +-- lld/MachO/Writer.cpp | 6 ++++-- lld/test/MachO/data-in-code.s | 8 ++++++-- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h index 4d76c0e..2f76114 100644 --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -104,6 +104,7 @@ struct Configuration { 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 index 4fc2693..16e83a1 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1043,6 +1043,7 @@ bool macho::link(ArrayRef argsArr, bool canExitEarly, 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 index 6b20d30..a70cfed 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -735,7 +735,8 @@ template void ObjFile::parse() { 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 index 945efda..481d7aa 100644 --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -1170,8 +1170,7 @@ def data_in_code_info : Flag<["-"], "data_in_code_info">, 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 index b55795d..523f501 100644 --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -666,7 +666,8 @@ template void Writer::createLoadCommands() { 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 @@ template void Writer::createOutputSections() { 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 index 6e06fb6..fb4e24d 100644 --- 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 -- 2.7.4