[lld] r317405 - [ELF] - Fix error reporting with --strip-debug/--strip-all.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 4 01:20:30 PDT 2017


Author: grimar
Date: Sat Nov  4 01:20:30 2017
New Revision: 317405

URL: http://llvm.org/viewvc/llvm-project?rev=317405&view=rev
Log:
[ELF] - Fix error reporting with --strip-debug/--strip-all.

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

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

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=317405&r1=317404&r2=317405&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Nov  4 01:20:30 2017
@@ -1106,6 +1106,13 @@ template <class ELFT> void LinkerDriver:
     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

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=317405&r1=317404&r2=317405&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Sat Nov  4 01:20:30 2017
@@ -537,10 +537,6 @@ InputSectionBase *ObjFile<ELFT>::createI
     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.

Modified: lld/trunk/test/ELF/conflict-debug-variable.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/conflict-debug-variable.s?rev=317405&r1=317404&r2=317405&view=diff
==============================================================================
--- lld/trunk/test/ELF/conflict-debug-variable.s (original)
+++ lld/trunk/test/ELF/conflict-debug-variable.s Sat Nov  4 01:20:30 2017
@@ -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):




More information about the llvm-commits mailing list