[lld] r369878 - [ELF] Error if --strip-all and --emit-relocs are used together

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 25 23:23:54 PDT 2019


Author: maskray
Date: Sun Aug 25 23:23:53 2019
New Revision: 369878

URL: http://llvm.org/viewvc/llvm-project?rev=369878&view=rev
Log:
[ELF] Error if --strip-all and --emit-relocs are used together

--strip-all suppresses the creation of in.symtab
This can cause a null pointer dereference in OutputSection::finalize()

  // --emit-relocs => copyRelocs is true
  if (!config->copyRelocs || (type != SHT_RELA && type != SHT_REL))
    return;
  ...
  link = in.symTab->getParent()->sectionIndex; // in.symTab is null

Let's just disallow the combination. In some cases the combination can
cause GNU linkers to fail:

* ld.bfd: final link failed: invalid operation
* gold: internal error in set_no_output_symtab_entry, at ../../gold/object.h:1814

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D66704

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/test/ELF/strip-all.s

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=369878&r1=369877&r2=369878&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sun Aug 25 23:23:53 2019
@@ -314,6 +314,9 @@ static void checkOptions() {
   if (!config->relocatable && !config->defineCommon)
     error("-no-define-common not supported in non relocatable output");
 
+  if (config->strip == StripPolicy::All && config->emitRelocs)
+    error("--strip-all and --emit-relocs may not be used together");
+
   if (config->zText && config->zIfuncNoplt)
     error("-z text and -z ifunc-noplt may not be used together");
 

Modified: lld/trunk/test/ELF/strip-all.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/strip-all.s?rev=369878&r1=369877&r2=369878&view=diff
==============================================================================
--- lld/trunk/test/ELF/strip-all.s (original)
+++ lld/trunk/test/ELF/strip-all.s Sun Aug 25 23:23:53 2019
@@ -21,6 +21,9 @@
 #RUN: ld.lld %t.o -s -o %t1
 #RUN: llvm-objdump -section-headers %t1 | FileCheck %s -check-prefix AFTER
 
+# RUN: not ld.lld %t.o --strip-all --emit-relocs -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s
+# ERR: error: --strip-all and --emit-relocs may not be used together
+
 # exits with return code 42 on linux
 .globl _start
 _start:




More information about the llvm-commits mailing list