[ELF] - Fix error reporting with --strip-debug/--strip-all.
authorGeorge Rimar <grimar@accesssoftek.com>
Sat, 4 Nov 2017 08:20:30 +0000 (08:20 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Sat, 4 Nov 2017 08:20:30 +0000 (08:20 +0000)
Currently LLD tries to use information about functions and variables location
taking it from debug sections. When --strip-* is given we discard such sections
and that breaks error reporting.
Patch stops discarding such sections and just removes them from InputSections list.

Differential revision: https://reviews.llvm.org/D39550

llvm-svn: 317405

lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/test/ELF/conflict-debug-variable.s

index c4d3bf2..62f52d9 100644 (file)
@@ -1106,6 +1106,13 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
     for (InputSectionBase *S : F->getSections())
       InputSections.push_back(cast<InputSection>(S));
 
+  // We do not want to emit debug sections if --strip-all
+  // or -strip-debug are given.
+  if (Config->Strip != StripPolicy::None)
+    llvm::erase_if(InputSections, [](InputSectionBase *S) {
+      return S->Name.startswith(".debug") || S->Name.startswith(".zdebug");
+    });
+
   Config->EFlags = Target->calcEFlags();
 
   // This adds a .comment section containing a version string. We have to add it
index c2f5bb4..9327dc0 100644 (file)
@@ -537,10 +537,6 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &Sec) {
     return &InputSection::Discarded;
   }
 
-  if (Config->Strip != StripPolicy::None &&
-      (Name.startswith(".debug") || Name.startswith(".zdebug")))
-    return &InputSection::Discarded;
-
   // The linkonce feature is a sort of proto-comdat. Some glibc i386 object
   // files contain definitions of symbol "__x86.get_pc_thunk.bx" in linkonce
   // sections. Drop those sections to avoid duplicate symbol errors.
index 69e8665..6099fb2 100644 (file)
@@ -30,6 +30,9 @@
 # CHECK-NEXT: >>> defined at 1.c:1
 # CHECK-NEXT: >>>            {{.*}}:(.bss+0x0)
 
+## Check that stripping debug sections does not break error reporting.
+# RUN: not ld.lld --strip-debug %t.o %t.o -o %t 2>&1 | FileCheck %s
+
 # Used reduced output from following code and gcc 7.1.0
 # to produce this input file:
 # Source (1.c):