[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
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369878 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/ELF/Driver.cpp b/ELF/Driver.cpp
index 88376b5..8996386 100644
--- a/ELF/Driver.cpp
+++ b/ELF/Driver.cpp
@@ -314,6 +314,9 @@
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");
diff --git a/test/ELF/strip-all.s b/test/ELF/strip-all.s
index f322119..7e05ba8 100644
--- a/test/ELF/strip-all.s
+++ b/test/ELF/strip-all.s
@@ -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: