diff options
author | Jordan Rupprecht <rupprecht@google.com> | 2019-01-30 14:58:13 +0000 |
---|---|---|
committer | Jordan Rupprecht <rupprecht@google.com> | 2019-01-30 14:58:13 +0000 |
commit | d0f7bcfbe14491bb8db5107d85786fe553c02bf9 (patch) | |
tree | 5270c9e97b28bdce48fc0ad5de93741ace7e8d7d /llvm/test | |
parent | 307deab40a0f454a0cd77bb142a3e98b2dbe2b8b (diff) | |
download | bcm5719-llvm-d0f7bcfbe14491bb8db5107d85786fe553c02bf9.tar.gz bcm5719-llvm-d0f7bcfbe14491bb8db5107d85786fe553c02bf9.zip |
[llvm-objcopy] Support -X|--discard-locals.
Summary:
This adds support for the --discard-locals flag, which acts similarly to --discard-all, except it only applies to compiler-generated symbols (i.e. symbols starting with `.L` in ELF).
I am not sure about COFF local symbols: those appear to also use `.L` in most cases, but also use just `L` in other cases, so for now I am just leaving it unimplemented there.
Fixes PR36160
Reviewers: jhenderson, alexshap, jakehehrlich, mstorsjo, espindola
Reviewed By: jhenderson
Subscribers: llvm-commits, emaste, arichardson
Differential Revision: https://reviews.llvm.org/D57248
llvm-svn: 352626
Diffstat (limited to 'llvm/test')
3 files changed, 255 insertions, 0 deletions
diff --git a/llvm/test/tools/llvm-objcopy/ELF/discard-locals-rel.test b/llvm/test/tools/llvm-objcopy/ELF/discard-locals-rel.test new file mode 100644 index 00000000000..05e1acf6b1d --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/ELF/discard-locals-rel.test @@ -0,0 +1,27 @@ +# RUN: yaml2obj %s > %t +# RUN: not llvm-objcopy --discard-locals %t %t2 2>&1 | FileCheck %s + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + Relocations: + - Offset: 0x1000 + Symbol: .L.rel + Type: R_X86_64_PC32 +Symbols: + Local: + - Name: .L.rel + Type: STT_FUNC + Section: .text + +# CHECK: not stripping symbol '.L.rel' because it is named in a relocation. diff --git a/llvm/test/tools/llvm-objcopy/ELF/discard-locals.test b/llvm/test/tools/llvm-objcopy/ELF/discard-locals.test new file mode 100644 index 00000000000..be489a2f0de --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/ELF/discard-locals.test @@ -0,0 +1,121 @@ +# RUN: yaml2obj %s > %t +# RUN: cp %t %t1 +# RUN: llvm-objcopy --discard-locals %t %t2 +# Verify that llvm-objcopy has not modified the input. +# RUN: cmp %t %t1 +# RUN: llvm-readobj --symbols %t2 | FileCheck %s + +# RUN: llvm-objcopy -X %t %t3 +# Verify that llvm-objcopy has not modified the input. +# RUN: cmp %t %t1 +# RUN: cmp %t2 %t3 + +# Verify that llvm-strip modifies the symbol table the same way. + +# RUN: cp %t %t4 +# RUN: llvm-strip --discard-locals %t4 +# RUN: cmp %t2 %t4 + +# RUN: cp %t %t5 +# RUN: llvm-strip -X %t5 +# RUN: cmp %t2 %t5 + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + - Name: .LLVM.Custom.Section + Type: SHT_PROGBITS +Symbols: + Local: + - Name: Local + Type: STT_FUNC + Section: .text + - Name: .L.LocalSection + Type: STT_SECTION + Section: .text + - Type: STT_SECTION + Section: .LLVM.Custom.Section + - Name: .L.LocalFile + Type: STT_FILE + - Name: .L.str + Type: STT_OBJECT + Section: .text + - Name: .L.undefined + - Name: .L.abs + Index: SHN_ABS + Global: + - Name: .L.Global + Type: STT_FUNC + Section: .text + +# CHECK: Symbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: Local +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: Function +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: .L.LocalSection +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: Section +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: Section +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: .LLVM.Custom.Section +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: .L.LocalFile +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: File +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: Undefined +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: .L.undefined +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: Undefined +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: .L.Global +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Function +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: ] diff --git a/llvm/test/tools/llvm-objcopy/ELF/discard-mix-local-and-all.test b/llvm/test/tools/llvm-objcopy/ELF/discard-mix-local-and-all.test new file mode 100644 index 00000000000..f9e0613eecf --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/ELF/discard-mix-local-and-all.test @@ -0,0 +1,107 @@ +# RUN: yaml2obj %s > %t +# Establish baseline objects for further checks. --discard-locals only discards +# compiler-generated local symbols (starting with .L), --discard-all discards +# all regular local symbols. +# RUN: llvm-objcopy %t %t-discard-none +# RUN: llvm-readobj --symbols %t-discard-none | FileCheck %s --check-prefixes=CHECK,LOCAL,COMPILER-LOCAL +# RUN: llvm-objcopy --discard-all %t %t-discard-all +# RUN: llvm-readobj --symbols %t-discard-all | FileCheck %s +# RUN: llvm-objcopy --discard-locals %t %t-discard-locals +# RUN: llvm-readobj --symbols %t-discard-locals | FileCheck %s --check-prefixes=CHECK,LOCAL + +# When mixing --discard-all and --discard-locals, the last one wins. +# RUN: llvm-objcopy --discard-all --discard-locals %t %t.1.o +# RUN: cmp %t.1.o %t-discard-locals +# RUN: llvm-objcopy --discard-locals --discard-all %t %t.2.o +# RUN: cmp %t.2.o %t-discard-all +# RUN: llvm-objcopy -x -X %t %t.3.o +# RUN: cmp %t.3.o %t-discard-locals +# RUN: llvm-objcopy -X -x %t %t.4.o +# RUN: cmp %t.4.o %t-discard-all +# RUN: llvm-objcopy -x -X -x -X %t %t.5.o +# RUN: cmp %t.5.o %t-discard-locals +# RUN: llvm-objcopy -X -x -X -x %t %t.6.o +# RUN: cmp %t.6.o %t-discard-all +# RUN: llvm-objcopy -X -x -X -x --discard-locals %t %t.7.o +# RUN: cmp %t.7.o %t-discard-locals +# RUN: llvm-objcopy -X -x -X -x --discard-all %t %t.8.o +# RUN: cmp %t.8.o %t-discard-all + +# llvm-strip works in the same way. +# RUN: llvm-strip --discard-all --discard-locals %t -o %t.9.o +# RUN: cmp %t.9.o %t-discard-locals +# RUN: llvm-strip --discard-locals --discard-all %t -o %t.10.o +# RUN: cmp %t.10.o %t-discard-all +# RUN: llvm-strip -x -X %t -o %t.11.o +# RUN: cmp %t.11.o %t-discard-locals +# RUN: llvm-strip -X -x %t -o %t.12.o +# RUN: cmp %t.12.o %t-discard-all +# RUN: llvm-strip -x -X -x -X %t -o %t.13.o +# RUN: cmp %t.13.o %t-discard-locals +# RUN: llvm-strip -X -x -X -x %t -o %t.14.o +# RUN: cmp %t.14.o %t-discard-all +# RUN: llvm-strip -X -x -X -x --discard-locals %t -o %t.15.o +# RUN: cmp %t.15.o %t-discard-locals +# RUN: llvm-strip -X -x -X -x --discard-all %t -o %t.16.o +# RUN: cmp %t.16.o %t-discard-all + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS +Symbols: + Local: + - Name: Local + Type: STT_FUNC + Section: .text + - Name: .L.str + Type: STT_OBJECT + Section: .text + Global: + - Name: Global + Type: STT_FUNC + Section: .text + +# CHECK: Symbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined +# CHECK-NEXT: } +# LOCAL-NEXT: Symbol { +# LOCAL-NEXT: Name: Local +# LOCAL-NEXT: Value: +# LOCAL-NEXT: Size: +# LOCAL-NEXT: Binding: Local +# LOCAL-NEXT: Type: Function +# LOCAL-NEXT: Other: +# LOCAL-NEXT: Section: .text +# LOCAL-NEXT: } +# COMPILER-LOCAL-NEXT: Symbol { +# COMPILER-LOCAL-NEXT: Name: .L.str +# COMPILER-LOCAL-NEXT: Value: +# COMPILER-LOCAL-NEXT: Size: +# COMPILER-LOCAL-NEXT: Binding: Local +# COMPILER-LOCAL-NEXT: Type: Object +# COMPILER-LOCAL-NEXT: Other: +# COMPILER-LOCAL-NEXT: Section: .text +# COMPILER-LOCAL-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: Global +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Function +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: ] |