summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-08-26 06:23:53 +0000
committerFangrui Song <maskray@google.com>2019-08-26 06:23:53 +0000
commit8e5184af71124be3ed7f53f4a25d5ea7742aa3c2 (patch)
tree6e4ad83419a8a2b426dabe53c949c3ee113ce3ff
parente18aa1e0a2d3ac9912829171b30f280624a2695c (diff)
downloadbcm5719-llvm-8e5184af71124be3ed7f53f4a25d5ea7742aa3c2.tar.gz
bcm5719-llvm-8e5184af71124be3ed7f53f4a25d5ea7742aa3c2.zip
[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 llvm-svn: 369878
-rw-r--r--lld/ELF/Driver.cpp3
-rw-r--r--lld/test/ELF/strip-all.s3
2 files changed, 6 insertions, 0 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 88376b5340c..8996386e99a 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -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");
diff --git a/lld/test/ELF/strip-all.s b/lld/test/ELF/strip-all.s
index f322119b0db..7e05ba81608 100644
--- a/lld/test/ELF/strip-all.s
+++ b/lld/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:
OpenPOWER on IntegriCloud