1# RUN: yaml2obj %s -o %t 2# RUN: cp %t %t1 3# RUN: llvm-objcopy --strip-unneeded %t %t2 4## Verify that llvm-objcopy has not modified the input. 5# RUN: cmp %t %t1 6# RUN: llvm-readobj --symbols %t2 | FileCheck %s 7 8## Verify that --keep-file-symbols works together with --strip-unneeded 9# RUN: llvm-objcopy --keep-file-symbols --strip-unneeded %t %t2b 10# RUN: llvm-readobj --symbols %t2b | FileCheck %s --check-prefixes=CHECK,FILESYM 11 12# RUN: llvm-objcopy --strip-unneeded-symbol=bar \ 13# RUN: %t %t3 14# RUN: llvm-readobj --symbols %t3 | FileCheck %s --check-prefixes=STRIP-BAR,REMAIN 15 16# RUN: llvm-objcopy --regex --strip-unneeded-symbol='.*' %t %t4 17# RUN: cmp %t2 %t4 18 19## Verify that --strip-unneeded-symbols removes all unneeded symbols listed in 20## the file, but not those that aren't. 21## In this case, fileSymbol isn't mentioned (so isn't removed), barbaz is 22## mentioned, but isn't removed (because it is needed) and bar, foobar and 23## foobaz are mentioned and removed. 24# RUN: echo " bar # bar " > %t.list.txt 25# RUN: echo "foobar" >> %t.list.txt 26# RUN: echo "foobaz" >> %t.list.txt 27# RUN: echo " # comment " >> %t.list.txt 28# RUN: echo "barbaz" >> %t.list.txt 29# RUN: llvm-objcopy --strip-unneeded-symbols %t.list.txt %t %t5 30# RUN: cmp %t2b %t5 31 32# RUN: echo " .* # * - remove all " > %t.list2.txt 33# RUN: llvm-objcopy --regex --strip-unneeded-symbols %t.list2.txt %t %t6 34# RUN: cmp %t2 %t6 35 36## Verify that llvm-strip modifies the symbol table the same way. 37# RUN: llvm-strip --strip-unneeded %t 38# RUN: cmp %t %t2 39 40!ELF 41FileHeader: 42 Class: ELFCLASS64 43 Data: ELFDATA2LSB 44 Type: ET_REL 45 Machine: EM_X86_64 46Sections: 47 - Name: .text 48 Type: SHT_PROGBITS 49 Flags: [ SHF_ALLOC, SHF_EXECINSTR ] 50 Address: 0x1000 51 AddressAlign: 0x0000000000000010 52 Size: 64 53 - Name: .group 54 Type: SHT_GROUP 55 Link: .symtab 56 AddressAlign: 0x0000000000000004 57 Info: barfoo 58 Members: 59 - SectionOrType: GRP_COMDAT 60 - SectionOrType: .text 61 - Name: .rel.text 62 Type: SHT_REL 63 Link: .symtab 64 Info: .text 65 Relocations: 66 - Offset: 0x1000 67 Symbol: foo 68 Type: R_X86_64_PC32 69Symbols: 70 - Name: foo 71 Type: STT_FUNC 72 Section: .text 73 Value: 0x1000 74 Size: 8 75 - Name: bar 76 Type: STT_FUNC 77 Size: 8 78 Section: .text 79 Value: 0x1008 80 - Name: barfoo 81 Type: STT_FUNC 82 Size: 8 83 Section: .text 84 Value: 0x1010 85 - Name: fileSymbol 86 Type: STT_FILE 87 Index: SHN_ABS 88 - Name: sectionSymbol 89 Type: STT_SECTION 90 - Name: foobar 91 Type: STT_FUNC 92 Binding: STB_GLOBAL 93 - Name: barbaz 94 Type: STT_FUNC 95 Size: 8 96 Section: .text 97 Value: 0x1020 98 Binding: STB_GLOBAL 99 - Name: baz 100 Type: STT_FUNC 101 Size: 8 102 Section: .text 103 Value: 0x1018 104 Binding: STB_WEAK 105 - Name: foobaz 106 Type: STT_FUNC 107 Binding: STB_WEAK 108 109#CHECK: Symbols [ 110#CHECK-NEXT: Symbol { 111#CHECK-NEXT: Name: 112#CHECK-NEXT: Value: 0x0 113#CHECK-NEXT: Size: 0 114#CHECK-NEXT: Binding: Local 115#CHECK-NEXT: Type: None 116#CHECK-NEXT: Other: 0 117#CHECK-NEXT: Section: Undefined 118#CHECK-NEXT: } 119#CHECK-NEXT: Symbol { 120#CHECK-NEXT: Name: foo 121#CHECK-NEXT: Value: 0x1000 122#CHECK-NEXT: Size: 8 123#CHECK-NEXT: Binding: Local 124#CHECK-NEXT: Type: Function 125#CHECK-NEXT: Other: 0 126#CHECK-NEXT: Section: .text 127#CHECK-NEXT: } 128#CHECK-NEXT: Symbol { 129#CHECK-NEXT: Name: barfoo 130#CHECK-NEXT: Value: 0x1010 131#CHECK-NEXT: Size: 8 132#CHECK-NEXT: Binding: Local 133#CHECK-NEXT: Type: Function 134#CHECK-NEXT: Other: 0 135#CHECK-NEXT: Section: .text 136#CHECK-NEXT: } 137#FILESYM-NEXT:Symbol { 138#FILESYM-NEXT: Name: fileSymbol 139#FILESYM-NEXT: Value: 0x0 140#FILESYM-NEXT: Size: 0 141#FILESYM-NEXT: Binding: Local 142#FILESYM-NEXT: Type: File 143#FILESYM-NEXT: Other: 0 144#FILESYM-NEXT: Section: Absolute 145#FILESYM-NEXT:} 146#CHECK-NEXT: Symbol { 147#CHECK-NEXT: Name: sectionSymbol 148#CHECK-NEXT: Value: 0x0 149#CHECK-NEXT: Size: 0 150#CHECK-NEXT: Binding: Local 151#CHECK-NEXT: Type: Section 152#CHECK-NEXT: Other: 0 153#CHECK-NEXT: Section: Undefined 154#CHECK-NEXT: } 155#CHECK-NEXT: Symbol { 156#CHECK-NEXT: Name: barbaz 157#CHECK-NEXT: Value: 0x1020 158#CHECK-NEXT: Size: 8 159#CHECK-NEXT: Binding: Global 160#CHECK-NEXT: Type: Function 161#CHECK-NEXT: Other: 0 162#CHECK-NEXT: Section: .text 163#CHECK-NEXT: } 164#CHECK-NEXT: Symbol { 165#CHECK-NEXT: Name: baz 166#CHECK-NEXT: Value: 0x1018 167#CHECK-NEXT: Size: 8 168#CHECK-NEXT: Binding: Weak 169#CHECK-NEXT: Type: Function 170#CHECK-NEXT: Other: 0 171#CHECK-NEXT: Section: .text 172#CHECK-NEXT: } 173#CHECK-NEXT:] 174 175 176#STRIP-BAR-NOT: Name: bar ({{.*}}) 177#REMAIN: Name: foobar 178#REMAIN: Name: foobaz 179