[PATCH] D117749: [lld-macho] Add support for -add_empty_section
Keith Smiley via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 19 22:32:10 PST 2022
keith created this revision.
Herald added a subscriber: dang.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
keith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is a ld64 option equivalent to `-sectcreate seg sect /dev/null`
that's useful for creating sections like the RESTRICT section.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D117749
Files:
lld/MachO/Driver.cpp
lld/MachO/Options.td
lld/test/MachO/sectcreate.s
Index: lld/test/MachO/sectcreate.s
===================================================================
--- lld/test/MachO/sectcreate.s
+++ lld/test/MachO/sectcreate.s
@@ -20,6 +20,9 @@
# RUN: llvm-objdump -s %t | FileCheck --check-prefix=STRIPPED %s
# RUN: llvm-readobj --sections %t | FileCheck --check-prefix=STRIPPEDSEC %s
+# RUN: %lld -add_empty_section __foo __bar -o %t %t.o
+# RUN: llvm-readobj --sections %t | FileCheck --check-prefix=EMPTYSECTION %s
+
# CHECK: Contents of section __TEXT,__text:
# CHECK: Contents of section __DATA,__data:
# CHECK: my string!.
@@ -40,6 +43,11 @@
# STRIPPEDSEC-NOT: NoDeadStrip
+# EMPTYSECTION: Name: __bar
+# EMPTYSECTION: Segment: __foo
+# EMPTYSECTION: Size: 0x0
+# EMPTYSECTION-NOT: Name:
+
.text
.global _main
_main:
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -252,6 +252,10 @@
Alias<sectcreate>,
HelpText<"Alias for -sectcreate">,
Group<grp_content>;
+def add_empty_section : MultiArg<["-"], "add_empty_section", 2>,
+ MetaVarName<"<segment> <section>">,
+ HelpText<"Create an empty <section> in <segment>">,
+ Group<grp_content>;
def filelist : Separate<["-"], "filelist">,
MetaVarName<"<file>">,
HelpText<"Read names of files to link from <file>">,
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1558,6 +1558,12 @@
inputFiles.insert(make<OpaqueFile>(*buffer, segName, sectName));
}
+ for (const Arg *arg : args.filtered(OPT_add_empty_section)) {
+ StringRef segName = arg->getValue(0);
+ StringRef sectName = arg->getValue(1);
+ inputFiles.insert(make<OpaqueFile>(MemoryBufferRef(), segName, sectName));
+ }
+
gatherInputSections();
if (config->callGraphProfileSort)
extractCallGraphProfile();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117749.401513.patch
Type: text/x-patch
Size: 1957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220120/b7a4a9b5/attachment.bin>
More information about the llvm-commits
mailing list