[lld] r251184 - Reapply r251144: fixed test.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 24 01:52:46 PDT 2015


Author: grimar
Date: Sat Oct 24 03:52:46 2015
New Revision: 251184

URL: http://llvm.org/viewvc/llvm-project?rev=251184&view=rev
Log:
Reapply r251144: fixed test.

Added:
    lld/trunk/test/elf2/strip-all.s
      - copied, changed from r251147, lld/trunk/test/elf2/strip-all.s
Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Options.td
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=251184&r1=251183&r2=251184&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Sat Oct 24 03:52:46 2015
@@ -58,6 +58,7 @@ struct Configuration {
   bool NoUndefined;
   bool Shared;
   bool Static = false;
+  bool StripAll;
   bool SysvHash = true;
   bool Verbose;
   bool ZNodelete = false;

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=251184&r1=251183&r2=251184&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Oct 24 03:52:46 2015
@@ -146,6 +146,7 @@ void LinkerDriver::createFiles(opt::Inpu
   Config->NoInhibitExec = Args.hasArg(OPT_noinhibit_exec);
   Config->NoUndefined = Args.hasArg(OPT_no_undefined);
   Config->Shared = Args.hasArg(OPT_shared);
+  Config->StripAll = Args.hasArg(OPT_strip_all);
   Config->Verbose = Args.hasArg(OPT_verbose);
 
   Config->DynamicLinker = getString(Args, OPT_dynamic_linker);

Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=251184&r1=251183&r2=251184&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Sat Oct 24 03:52:46 2015
@@ -90,6 +90,9 @@ def shared : Flag<["-"], "shared">,
 def soname : Joined<["-"], "soname=">,
   HelpText<"Set DT_SONAME">;
 
+def strip_all : Flag<["--"], "strip-all">,
+  HelpText<"Strip all symbols">;
+
 def sysroot : Joined<["--"], "sysroot=">,
   HelpText<"Set the system root">;
 
@@ -124,6 +127,7 @@ def alias_shared_Bshareable : Flag<["-"]
 def alias_soname_h : Separate<["-"], "h">, Alias<soname>;
 def alias_soname_soname : Separate<["-"], "soname">, Alias<soname>;
 def alias_script_T : Separate<["-"], "T">, Alias<script>;
+def alias_strip_all: Flag<["-"], "s">, Alias<strip_all>;
 def alias_undefined_u : Separate<["-"], "u">, Alias<undefined>;
 
 // Options listed below are silently ignored now.
@@ -135,7 +139,6 @@ def no_add_needed : Flag<["--"], "no-add
 def no_fatal_warnings : Flag<["--"], "no-fatal-warnings">;
 def no_warn_mismatch : Flag<["--"], "no-warn-mismatch">;
 def start_group : Flag<["--"], "start-group">;
-def strip_all : Flag<["--"], "strip-all">;
 def version_script : Separate<["--"], "version-script">;
 def warn_common : Flag<["--"], "warn-common">;
 def warn_shared_textrel : Flag<["--"], "warn-shared-textrel">;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=251184&r1=251183&r2=251184&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sat Oct 24 03:52:46 2015
@@ -99,7 +99,8 @@ template <class ELFT> void lld::elf2::wr
   StringTableSection<ELFT> ShStrTab(".shstrtab", false);
   Out<ELFT>::ShStrTab = &ShStrTab;
   StringTableSection<ELFT> StrTab(".strtab", false);
-  Out<ELFT>::StrTab = &StrTab;
+  if (!Config->StripAll)
+    Out<ELFT>::StrTab = &StrTab;
   StringTableSection<ELFT> DynStrTab(".dynstr", true);
   Out<ELFT>::DynStrTab = &DynStrTab;
   OutputSection<ELFT> Bss(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
@@ -111,8 +112,11 @@ template <class ELFT> void lld::elf2::wr
     Out<ELFT>::GotPlt = &GotPlt;
   PltSection<ELFT> Plt;
   Out<ELFT>::Plt = &Plt;
-  SymbolTableSection<ELFT> SymTab(*Symtab, *Out<ELFT>::StrTab);
-  Out<ELFT>::SymTab = &SymTab;
+  std::unique_ptr<SymbolTableSection<ELFT>> SymTab;
+  if (!Config->StripAll) {
+    SymTab.reset(new SymbolTableSection<ELFT>(*Symtab, *Out<ELFT>::StrTab));
+    Out<ELFT>::SymTab = SymTab.get();
+  }
   SymbolTableSection<ELFT> DynSymTab(*Symtab, *Out<ELFT>::DynStrTab);
   Out<ELFT>::DynSymTab = &DynSymTab;
   HashTableSection<ELFT> HashTab;
@@ -288,7 +292,8 @@ template <class ELFT> void Writer<ELFT>:
       StringRef SymName = *SymNameOrErr;
       if (!shouldKeepInSymtab<ELFT>(*F, SymName, Sym))
         continue;
-      Out<ELFT>::SymTab->addLocalSymbol(SymName);
+      if (Out<ELFT>::SymTab)
+        Out<ELFT>::SymTab->addLocalSymbol(SymName);
     }
   }
 }
@@ -513,7 +518,8 @@ template <class ELFT> void Writer<ELFT>:
       CommonSymbols.push_back(C);
     if (!includeInSymtab<ELFT>(*Body))
       continue;
-    Out<ELFT>::SymTab->addSymbol(Body);
+    if (Out<ELFT>::SymTab)
+      Out<ELFT>::SymTab->addSymbol(Body);
 
     if (isOutputDynamic() && includeInDynamicSymtab(*Body))
       Out<ELFT>::DynSymTab->addSymbol(Body);
@@ -522,9 +528,11 @@ template <class ELFT> void Writer<ELFT>:
 
   // This order is not the same as the final output order
   // because we sort the sections using their attributes below.
-  OutputSections.push_back(Out<ELFT>::SymTab);
+  if (Out<ELFT>::SymTab)
+    OutputSections.push_back(Out<ELFT>::SymTab);
   OutputSections.push_back(Out<ELFT>::ShStrTab);
-  OutputSections.push_back(Out<ELFT>::StrTab);
+  if (Out<ELFT>::StrTab)
+    OutputSections.push_back(Out<ELFT>::StrTab);
   if (isOutputDynamic()) {
     OutputSections.push_back(Out<ELFT>::DynSymTab);
     if (Out<ELFT>::GnuHashTab)

Copied: lld/trunk/test/elf2/strip-all.s (from r251147, lld/trunk/test/elf2/strip-all.s)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/strip-all.s?p2=lld/trunk/test/elf2/strip-all.s&p1=lld/trunk/test/elf2/strip-all.s&r1=251147&r2=251184&rev=251184&view=diff
==============================================================================
--- lld/trunk/test/elf2/strip-all.s (original)
+++ lld/trunk/test/elf2/strip-all.s Sat Oct 24 03:52:46 2015
@@ -1,20 +1,20 @@
 # REQUIRES: x86
 
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: ld.lld2 %t -o %t1
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld2 %t.o -o %t1
 #RUN: llvm-objdump -section-headers %t1 | FileCheck %s -check-prefix BEFORE
 #BEFORE:       4 .symtab 00000030
 #BEFORE-NEXT:  5 .shstrtab 0000002c
 #BEFORE-NEXT:  6 .strtab 00000008
 
-#RUN: ld.lld2 %t.o -e main --strip-all -o %t1
+#RUN: ld.lld2 %t.o --strip-all -o %t1
 #RUN: llvm-objdump -section-headers %t1 | FileCheck %s -check-prefix AFTER
 #AFTER-NOT: .symtab
-#AFTER: 7 .shstrtab 0000003f
+#AFTER: 4 .shstrtab 0000001c
 #AFTER-NOT: .strtab
 
 # Test alias -s
-#RUN: ld.lld2 %t.o -e main -s -o %t1
+#RUN: ld.lld2 %t.o -s -o %t1
 #RUN: llvm-objdump -section-headers %t1 | FileCheck %s -check-prefix AFTER
 
 # exits with return code 42 on linux




More information about the llvm-commits mailing list