[lld] r251144 - [ELF2] --strip-all/-s command line implemented

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 23 14:12:12 PDT 2015


Rolled back the change in r251148. Please re-submit with a fix. Thanks!

On Fri, Oct 23, 2015 at 2:09 PM, Rui Ueyama <ruiu at google.com> wrote:

> George,
>
> The new test you added is failing. Can you take a look?
>
> $ bin/llvm-lit -v /ssd/llvm/tools/lld/test/elf2/strip-all.s
> ninja: no work to do.
> -- Testing: 1 tests, 1 threads --
> FAIL: lld :: elf2/strip-all.s (1 of 1)
> ******************** TEST 'lld :: elf2/strip-all.s' FAILED
> ********************
> Script:
> --
> llvm-mc -filetype=obj -triple=x86_64-unknown-linux
> /ssd/llvm/tools/lld/test/elf2/strip-all.s -o
> /ssd/build/tools/lld/test/elf2/Output/strip-all.s.tmp
> ld.lld2 /ssd/build/tools/lld/test/elf2/Output/strip-all.s.tmp -o
> /ssd/build/tools/lld/test/elf2/Output/strip-all.s.tmp1
> llvm-objdump -section-headers
> /ssd/build/tools/lld/test/elf2/Output/strip-all.s.tmp1 | FileCheck
> /ssd/llvm/tools/lld/test/elf2/strip-all.s -check-prefix BEFORE
> ld.lld2 /ssd/build/tools/lld/test/elf2/Output/strip-all.s.tmp.o -e main
> --strip-all -o /ssd/build/tools/lld/test/elf2/Output/strip-all.s.tmp1
> llvm-objdump -section-headers
> /ssd/build/tools/lld/test/elf2/Output/strip-all.s.tmp1 | FileCheck
> /ssd/llvm/tools/lld/test/elf2/strip-all.s -check-prefix AFTER
> ld.lld2 /ssd/build/tools/lld/test/elf2/Output/strip-all.s.tmp.o -e main -s
> -o /ssd/build/tools/lld/test/elf2/Output/strip-all.s.tmp1
> llvm-objdump -section-headers
> /ssd/build/tools/lld/test/elf2/Output/strip-all.s.tmp1 | FileCheck
> /ssd/llvm/tools/lld/test/elf2/strip-all.s -check-prefix AFTER
> --
> Exit Code: 1
>
> Command Output (stderr):
> --
> undefined symbol: main
>
> --
>
> ********************
> Testing Time: 0.03s
> ********************
> Failing Tests (1):
>     lld :: elf2/strip-all.s
>
>   Unexpected Failures: 1
>
> On Fri, Oct 23, 2015 at 1:24 PM, George Rimar via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: grimar
>> Date: Fri Oct 23 15:24:44 2015
>> New Revision: 251144
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=251144&view=rev
>> Log:
>> [ELF2] --strip-all/-s command line implemented
>>
>> -s, --strip-all - Strip all symbols
>> Implementation removes .strtab and .symtab sections from output.
>>
>> Differential Revision: http://reviews.llvm.org/D13934
>>
>> Added:
>>     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=251144&r1=251143&r2=251144&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/Config.h (original)
>> +++ lld/trunk/ELF/Config.h Fri Oct 23 15:24:44 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=251144&r1=251143&r2=251144&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/Driver.cpp (original)
>> +++ lld/trunk/ELF/Driver.cpp Fri Oct 23 15:24:44 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=251144&r1=251143&r2=251144&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/Options.td (original)
>> +++ lld/trunk/ELF/Options.td Fri Oct 23 15:24:44 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=251144&r1=251143&r2=251144&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/Writer.cpp (original)
>> +++ lld/trunk/ELF/Writer.cpp Fri Oct 23 15:24:44 2015
>> @@ -97,7 +97,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);
>> @@ -109,8 +110,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;
>> @@ -286,7 +290,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);
>>      }
>>    }
>>  }
>> @@ -512,7 +517,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);
>> @@ -521,9 +527,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)
>>
>> Added: lld/trunk/test/elf2/strip-all.s
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/strip-all.s?rev=251144&view=auto
>>
>> ==============================================================================
>> --- lld/trunk/test/elf2/strip-all.s (added)
>> +++ lld/trunk/test/elf2/strip-all.s Fri Oct 23 15:24:44 2015
>> @@ -0,0 +1,25 @@
>> +# REQUIRES: x86
>> +
>> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
>> +# RUN: ld.lld2 %t -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: llvm-objdump -section-headers %t1 | FileCheck %s -check-prefix
>> AFTER
>> +#AFTER-NOT: .symtab
>> +#AFTER: 7 .shstrtab 0000003f
>> +#AFTER-NOT: .strtab
>> +
>> +# Test alias -s
>> +#RUN: ld.lld2 %t.o -e main -s -o %t1
>> +#RUN: llvm-objdump -section-headers %t1 | FileCheck %s -check-prefix
>> AFTER
>> +
>> +# exits with return code 42 on linux
>> +.globl _start;
>> +_start:
>> +  mov $60, %rax
>> +  mov $42, %rdi
>> +  syscall
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151023/a9f0dbb9/attachment.html>


More information about the llvm-commits mailing list