[lld] b579938 - [lld/mac] Add support for -no_data_in_code_info flag
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 16 03:43:10 PDT 2021
Author: Nico Weber
Date: 2021-06-16T06:40:42-04:00
New Revision: b579938d40b48f24e05e4022a647be933ffc1b89
URL: https://github.com/llvm/llvm-project/commit/b579938d40b48f24e05e4022a647be933ffc1b89
DIFF: https://github.com/llvm/llvm-project/commit/b579938d40b48f24e05e4022a647be933ffc1b89.diff
LOG: [lld/mac] Add support for -no_data_in_code_info flag
Differential Revision: https://reviews.llvm.org/D104345
Added:
Modified:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/InputFiles.cpp
lld/MachO/Options.td
lld/MachO/Writer.cpp
lld/test/MachO/data-in-code.s
Removed:
################################################################################
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 4d76c0ed287cc..2f7611406bc03 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 4fc269320b7b3..16e83a1dd88fe 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1043,6 +1043,7 @@ bool macho::link(ArrayRef<const char *> 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 6b20d30fca3e2..a70cfedbd9ba3 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -735,7 +735,8 @@ template <class LP> 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 945efdaea75a7..481d7aa6cb25d 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<grp_undocumented>;
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<grp_undocumented>;
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 b55795da831ba..523f5013e22fc 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -666,7 +666,8 @@ template <class LP> void Writer::createLoadCommands() {
make<LCDysymtab>(symtabSection, indirectSymtabSection));
if (functionStartsSection)
in.header->addLoadCommand(make<LCFunctionStarts>(functionStartsSection));
- in.header->addLoadCommand(make<LCDataInCode>(dataInCodeSection));
+ if (dataInCodeSection)
+ in.header->addLoadCommand(make<LCDataInCode>(dataInCodeSection));
if (config->emitEncryptionInfo)
in.header->addLoadCommand(make<LCEncryptionInfo<LP>>());
for (StringRef path : config->runtimePaths)
@@ -865,7 +866,8 @@ template <class LP> void Writer::createOutputSections() {
indirectSymtabSection = make<IndirectSymtabSection>();
if (config->adhocCodesign)
codeSignatureSection = make<CodeSignatureSection>();
- dataInCodeSection = make<DataInCodeSection>();
+ if (config->emitDataInCodeInfo)
+ dataInCodeSection = make<DataInCodeSection>();
if (config->emitFunctionStarts)
functionStartsSection = make<FunctionStartsSection>();
if (config->emitBitcodeBundle)
diff --git a/lld/test/MachO/data-in-code.s b/lld/test/MachO/data-in-code.s
index 6e06fb6bbf34a..fb4e24d809c55 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
More information about the llvm-commits
mailing list