[lld] r265722 - ELF: Add --strip-debug option.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 7 14:04:52 PDT 2016
Author: ruiu
Date: Thu Apr 7 16:04:51 2016
New Revision: 265722
URL: http://llvm.org/viewvc/llvm-project?rev=265722&view=rev
Log:
ELF: Add --strip-debug option.
If --strip-debug option is given, then all sections whose names start
with ".debug" are removed from output.
Added:
lld/trunk/test/ELF/strip-debug.s
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/Options.td
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=265722&r1=265721&r2=265722&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Thu Apr 7 16:04:51 2016
@@ -79,6 +79,7 @@ struct Configuration {
bool Shared;
bool Static = false;
bool StripAll;
+ bool StripDebug;
bool SysvHash = true;
bool Threads;
bool Trace;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=265722&r1=265721&r2=265722&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Apr 7 16:04:51 2016
@@ -291,6 +291,7 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->SaveTemps = Args.hasArg(OPT_save_temps);
Config->Shared = Args.hasArg(OPT_shared);
Config->StripAll = Args.hasArg(OPT_strip_all);
+ Config->StripDebug = Args.hasArg(OPT_strip_debug);
Config->Threads = Args.hasArg(OPT_threads);
Config->Trace = Args.hasArg(OPT_trace);
Config->Verbose = Args.hasArg(OPT_verbose);
@@ -315,11 +316,16 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->ZOrigin = hasZOption(Args, "origin");
Config->ZRelro = !hasZOption(Args, "norelro");
- Config->Pic = Config->Pie || Config->Shared;
-
if (Config->Relocatable)
Config->StripAll = false;
+ // --strip-all implies --strip-debug.
+ if (Config->StripAll)
+ Config->StripDebug = true;
+
+ // Config->Pic is true if we are generating position-independent code.
+ Config->Pic = Config->Pie || Config->Shared;
+
if (auto *Arg = Args.getLastArg(OPT_hash_style)) {
StringRef S = Arg->getValue();
if (S == "gnu") {
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=265722&r1=265721&r2=265722&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Apr 7 16:04:51 2016
@@ -262,8 +262,13 @@ elf::ObjectFile<ELFT>::createInputSectio
if (Name == ".note.GNU-stack")
return &InputSection<ELFT>::Discarded;
- if (Name == ".note.GNU-split-stack")
+ if (Name == ".note.GNU-split-stack") {
error("objects using splitstacks are not supported");
+ return &InputSection<ELFT>::Discarded;
+ }
+
+ if (Config->StripDebug && Name.startswith(".debug"))
+ return &InputSection<ELFT>::Discarded;
// A MIPS object file has a special section that contains register
// usage info, which needs to be handled by the linker specially.
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=265722&r1=265721&r2=265722&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Thu Apr 7 16:04:51 2016
@@ -133,6 +133,9 @@ def start_lib : Flag<["--"], "start-lib"
def strip_all : Flag<["--"], "strip-all">,
HelpText<"Strip all symbols">;
+def strip_debug : Flag<["--"], "strip-debug">,
+ HelpText<"Strip debugging information">;
+
def sysroot : Joined<["--"], "sysroot=">,
HelpText<"Set the system root">;
Added: lld/trunk/test/ELF/strip-debug.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/strip-debug.s?rev=265722&view=auto
==============================================================================
--- lld/trunk/test/ELF/strip-debug.s (added)
+++ lld/trunk/test/ELF/strip-debug.s Thu Apr 7 16:04:51 2016
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux -g %s -o %t
+# RUN: ld.lld %t -o %t2
+# RUN: llvm-readobj -sections -symbols %t2 | FileCheck -check-prefix=DEFAULT %s
+# RUN: ld.lld %t -o %t2 --strip-debug
+# RUN: llvm-readobj -sections -symbols %t2 | FileCheck -check-prefix=STRIP %s
+# RUN: ld.lld %t -o %t2 --strip-all
+# RUN: llvm-readobj -sections -symbols %t2 | FileCheck -check-prefix=STRIP %s
+
+# DEFAULT: Name: .debug_info
+# DEFAULT: Name: .debug_abbrev
+# DEFAULT: Name: .debug_aranges
+# DEFAULT: Name: .debug_line
+
+# STRIP-NOT: Name: .debug_info
+# STRIP-NOT: Name: .debug_abbrev
+# STRIP-NOT: Name: .debug_aranges
+# STRIP-NOT: Name: .debug_line
+
+.globl _start
+_start:
+ ret
More information about the llvm-commits
mailing list