[PATCH] D42858: Add -{no, }-check-sections flag to enable/disable section overlap checking.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 2 11:09:27 PST 2018


ruiu created this revision.
ruiu added reviewers: rafael, jhenderson.
Herald added a subscriber: emaste.

GNU linkers have this option. Fixes https://bugs.llvm.org/show_bug.cgi?id=36205


https://reviews.llvm.org/D42858

Files:
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/Options.td
  lld/ELF/Writer.cpp
  lld/test/ELF/linkerscript/overlapping-sections.s


Index: lld/test/ELF/linkerscript/overlapping-sections.s
===================================================================
--- lld/test/ELF/linkerscript/overlapping-sections.s
+++ lld/test/ELF/linkerscript/overlapping-sections.s
@@ -66,8 +66,10 @@
 # LMA-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000 -> 0x80FF]
 # LMA-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8080 -> 0x817F]
 
-# check that we create the expected binary with --noinhibit-exec:
+# Check that we create the expected binary with --noinhibit-exec or --no-check-sections:
 # RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --noinhibit-exec
+# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --no-check-sections
+# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --check-sections --no-check-sections
 
 # Verify that the .sec2 was indeed placed in a PT_LOAD where the PhysAddr
 # overlaps with where .sec1 is loaded:
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -455,7 +455,8 @@
       Sec->Addr = 0;
   }
 
-  checkNoOverlappingSections();
+  if (Config->CheckSections)
+    checkNoOverlappingSections();
 
   // It does not make sense try to open the file if we have error already.
   if (errorCount())
Index: lld/ELF/Options.td
===================================================================
--- lld/ELF/Options.td
+++ lld/ELF/Options.td
@@ -26,6 +26,9 @@
 
 def build_id_eq: J<"build-id=">, HelpText<"Generate build ID note">;
 
+def check_sections : F<"check-sections">,
+  HelpText<"Check segment addresses for overlaps">;
+
 defm compress_debug_sections : Eq<"compress-debug-sections">,
   HelpText<"Compress DWARF debug sections">;
 
@@ -175,6 +178,9 @@
 def no_as_needed: F<"no-as-needed">,
   HelpText<"Always DT_NEEDED for shared libraries">;
 
+def no_check_sections : F<"no-check-sections">,
+  HelpText<"Do not check segment addresses for overlaps">;
+
 def no_color_diagnostics: F<"no-color-diagnostics">,
   HelpText<"Do not use colors in diagnostics">;
 
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -600,6 +600,8 @@
   Config->AuxiliaryList = args::getStrings(Args, OPT_auxiliary);
   Config->Bsymbolic = Args.hasArg(OPT_Bsymbolic);
   Config->BsymbolicFunctions = Args.hasArg(OPT_Bsymbolic_functions);
+  Config->CheckSections =
+      Args.hasFlag(OPT_check_sections, OPT_no_check_sections, true);
   Config->Chroot = Args.getLastArgValue(OPT_chroot);
   Config->CompressDebugSections = getCompressDebugSections(Args);
   Config->DefineCommon = Args.hasFlag(OPT_define_common, OPT_no_define_common,
Index: lld/ELF/Config.h
===================================================================
--- lld/ELF/Config.h
+++ lld/ELF/Config.h
@@ -112,6 +112,7 @@
   bool AsNeeded = false;
   bool Bsymbolic;
   bool BsymbolicFunctions;
+  bool CheckSections;
   bool CompressDebugSections;
   bool DefineCommon;
   bool Demangle = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42858.132635.patch
Type: text/x-patch
Size: 3035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180202/d9e3d745/attachment.bin>


More information about the llvm-commits mailing list