[PATCH] D117749: [lld-macho] Add support for -add_empty_section

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 28 18:52:29 PST 2022


keith updated this revision to Diff 404211.
keith added a comment.

Improve test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117749/new/

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
@@ -7,6 +7,7 @@
 # RUN:     -sectcreate SEG SEC1 %t1 \
 # RUN:     -segcreate SEG SEC2 %t3 \
 # RUN:     -sectcreate SEG SEC1 %t2 \
+# RUN:     -add_empty_section SEG SEC1 \
 # RUN:     -o %t %t.o
 # RUN: llvm-objdump -s %t | FileCheck %s
 
@@ -16,10 +17,17 @@
 # RUN:     -sectcreate SEG SEC1 %t1 \
 # RUN:     -segcreate SEG SEC2 %t3 \
 # RUN:     -sectcreate SEG SEC1 %t2 \
+# RUN:     -add_empty_section SEG SEC1 \
 # RUN:     -o %t %t.o
 # 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
+
+# RUN: %lld -sectcreate SEG SEC1 %t1 -add_empty_section SEG SEC1 -o %t %t.o
+# RUN: llvm-readobj --sections %t | FileCheck --check-prefix=CREATEDANDEMPTY %s
+
 # CHECK: Contents of section __TEXT,__text:
 # CHECK: Contents of section __DATA,__data:
 # CHECK: my string!.
@@ -40,6 +48,16 @@
 
 # STRIPPEDSEC-NOT: NoDeadStrip
 
+# EMPTYSECTION: Name: bar
+# EMPTYSECTION: Segment: foo
+# EMPTYSECTION: Size: 0x0
+# EMPTYSECTION-NOT: Name:
+
+# CREATEDANDEMPTY: Name: SEC1
+# CREATEDANDEMPTY: Segment: SEG
+# CREATEDANDEMPTY: Size: 0x10
+# CREATEDANDEMPTY-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
@@ -1513,6 +1513,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.404211.patch
Type: text/x-patch
Size: 2660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220129/8b612e14/attachment.bin>


More information about the llvm-commits mailing list