[ELF] Add --rosegment to complement --no-rosegment
authorFangrui Song <maskray@google.com>
Thu, 30 Apr 2020 00:31:35 +0000 (17:31 -0700)
committerFangrui Song <maskray@google.com>
Thu, 30 Apr 2020 01:00:00 +0000 (18:00 -0700)
This option can cancel --no-rosegment and it just seems right to have
a corresponding positive option for a --no-* negative option.

Anecdotally, gold had --rosegment but did not have --no-rosegment.
I added --no-rosegment (https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9a6c68caa9543e09b064b7ac7c2b658f277bc19c) for binutils>=2.35

lld/ELF/Driver.cpp
lld/ELF/Options.td
lld/test/ELF/segments.s

index ff0c115..31a2a3a 100644 (file)
@@ -965,7 +965,7 @@ static void readConfigs(opt::InputArgList &args) {
   config->searchPaths = args::getStrings(args, OPT_library_path);
   config->sectionStartMap = getSectionStartMap(args);
   config->shared = args.hasArg(OPT_shared);
-  config->singleRoRx = args.hasArg(OPT_no_rosegment);
+  config->singleRoRx = !args.hasFlag(OPT_rosegment, OPT_no_rosegment, true);
   config->soName = args.getLastArgValue(OPT_soname);
   config->sortSection = getSortSection(args);
   config->splitStackAdjustSize = args::getInteger(args, OPT_split_stack_adjust_size, 16384);
index ad4e489..cb0c12a 100644 (file)
@@ -256,9 +256,6 @@ def no_nmagic: F<"no-nmagic">, MetaVarName<"<magic>">,
 def no_omagic: F<"no-omagic">, MetaVarName<"<magic>">,
   HelpText<"Do not set the text data sections to be writable, page align sections (default)">;
 
-def no_rosegment: F<"no-rosegment">,
-  HelpText<"Do not put read-only non-executable sections in their own segment">;
-
 def no_undefined: F<"no-undefined">,
   HelpText<"Report unresolved symbols even if the linker is creating a shared library">;
 
@@ -311,6 +308,10 @@ def print_map: F<"print-map">,
 
 defm reproduce: Eq<"reproduce", "Write a tar file containing input files and command line options to reproduce link">;
 
+defm rosegment: B<"rosegment",
+  "Put read-only non-executable sections in their own segment (default)",
+  "Do not put read-only non-executable sections in their own segment">;
+
 defm rpath: Eq<"rpath", "Add a DT_RUNPATH to the output">;
 
 def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;
index 5165fc3..9b88f48 100644 (file)
@@ -3,8 +3,8 @@
 
 # RUN: ld.lld %t -o %t1
 # RUN: llvm-readobj --program-headers %t1 | FileCheck --check-prefix=ROSEGMENT %s
-# RUN: ld.lld --omagic --no-omagic %t -o %t1
-# RUN: llvm-readobj --program-headers %t1 | FileCheck --check-prefix=ROSEGMENT %s
+# RUN: ld.lld --no-rosegment --rosegment %t -o - | cmp - %t1
+# RUN: ld.lld --omagic --no-omagic %t -o - | cmp - %t1
 
 # ROSEGMENT:      ProgramHeader {
 # ROSEGMENT:        Type: PT_LOAD