1# RUN: yaml2obj %s -o %t
2# RUN: cp %t %t3
3# RUN: llvm-objcopy --strip-debug %t %t2
4# RUN: llvm-readobj --file-headers --sections --symbols %t2 | FileCheck %s
5
6# Verify that the previous run of llvm-objcopy has not modified the input.
7# RUN: cmp %t %t3
8
9# RUN: llvm-objcopy -g %t %t2g
10# Verify that --strip-debug and -g produce the same output
11# RUN: cmp %t2 %t2g
12
13# RUN: llvm-strip --strip-debug %t3
14# RUN: cmp %t2 %t3
15
16# RUN: cp %t %t4
17# RUN: llvm-strip -d %t4
18# RUN: cmp %t2 %t4
19
20# RUN: cp %t %t5
21# RUN: llvm-strip -g %t5
22# RUN: cmp %t2 %t5
23
24# RUN: cp %t %t6
25# RUN: llvm-strip -S %t6
26# RUN: cmp %t2 %t6
27
28# RUN: rm -f %t.a
29# RUN: llvm-ar crs %t.a %t
30# RUN: llvm-objcopy --strip-debug %t.a %t.a
31# RUN: llvm-ar p %t.a > %t7
32# RUN: cmp %t2 %t7
33
34# Verify that an archive with multiple object files is handled correctly.
35# RUN: cp %t %t.duplicate
36# RUN: cp %t2 %t.duplicate.stripped
37# RUN: rm -f %t.multiple-stripped-obj.a
38# RUN: llvm-ar crs %t.multiple-stripped-obj.a %t2 %t.duplicate.stripped
39# RUN: rm -f %t.multiple-obj.a
40# RUN: llvm-ar crs %t.multiple-obj.a %t %t.duplicate
41# RUN: llvm-objcopy --strip-debug %t.multiple-obj.a %t.multiple-obj.stripped.a
42# RUN: llvm-ar p %t.multiple-stripped-obj.a > %t.multiple-stripped-obj.a.dump
43# RUN: llvm-ar p %t.multiple-obj.stripped.a > %t.multiple-obj.stripped.a.dump
44# RUN: cmp %t.multiple-stripped-obj.a.dump %t.multiple-obj.stripped.a.dump
45
46# We can not use %t inside the patterns passed to FileCheck,
47# thus we have to use "recognizable" file names.
48# RUN: cp %t %t1.o
49# RUN: cp %s %t2.txt
50# RUN: cp %t %t3.o
51# RUN: rm -f %t.non-object.a
52# RUN: llvm-ar cr %t.non-object.a %t1.o %t2.txt %t3.o
53# RUN: llvm-ar t %t.non-object.a | FileCheck %s --check-prefix=NON-OBJECT-ARCHIVE-MEMBERS
54
55# NON-OBJECT-ARCHIVE-MEMBERS: 1.o
56# NON-OBJECT-ARCHIVE-MEMBERS-NEXT: 2.txt
57# NON-OBJECT-ARCHIVE-MEMBERS-NEXT: 3.o
58
59# RUN: cp %t.non-object.a %t.non-object.copy.a
60# RUN: not llvm-objcopy --strip-debug %t.non-object.a %t2.non-object.a 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT
61
62# BAD-FORMAT: The file was not recognized as a valid object file
63
64# Verify that %t.non-object.a has not been modified.
65# RUN: cmp %t.non-object.a %t.non-object.copy.a
66
67# RUN: rm -f %t.thin.a
68# Copy %t to %t.thin.archive.member to avoid changing %t directly.
69# RUN: cp %t %t.thin.archive.member
70# RUN: llvm-ar crsT %t.thin.a %t.thin.archive.member
71# RUN: llvm-objcopy --strip-debug %t.thin.a %t2.thin.a
72# RUN: cat %t.thin.a | FileCheck %s --check-prefix=VERIFY-THIN-ARCHIVE
73# RUN: cat %t2.thin.a | FileCheck %s --check-prefix=VERIFY-THIN-ARCHIVE
74
75# VERIFY-THIN-ARCHIVE: !<thin>
76
77# Verify that the member of a thin archive was properly modified.
78# RUN: cmp %t2 %t.thin.archive.member
79
80# RUN: rm -f %t.non-object.thin.a
81# RUN: llvm-ar crsT %t.non-object.thin.a %t1.o %t2.txt %t3.o
82# RUN: cp %t.non-object.thin.a %t.non-object.thin.copy.a
83# RUN: not llvm-objcopy --strip-debug %t.non-object.thin.a %t.non-object.thin.a 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT
84
85# Verify that in the case of error thin archive and its memebers are not getting modified.
86# RUN: cmp %t.non-object.thin.a %t.non-object.thin.copy.a
87# RUN: cmp %t %t1.o
88# RUN: cmp %s %t2.txt
89# RUN: cmp %t %t3.o
90
91!ELF
92FileHeader:
93  Class:           ELFCLASS64
94  Data:            ELFDATA2LSB
95  Type:            ET_REL
96  Machine:         EM_X86_64
97Sections:
98  - Name:            .debugfoo
99    Type:            SHT_PROGBITS
100    Content:         "00000000"
101  - Name:            .zdebugfoo
102    Type:            SHT_PROGBITS
103    Content:         "00000000"
104  - Name:            .gdb_index
105    Type:            SHT_PROGBITS
106    Content:         "00000000"
107  - Name:            .text
108    Type:            SHT_PROGBITS
109    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
110    AddressAlign:    0x0000000000000010
111    Content:         "00000000"
112Symbols:
113  - Name:    foo
114    Section: .text
115    Binding:  STB_GLOBAL
116  - Name:    debugfoo
117    Section: .debugfoo
118    Binding:  STB_GLOBAL
119  - Name:    filesymbol
120    Type:    STT_FILE
121
122# CHECK: SectionHeaderCount: 5
123
124# CHECK: Name: .text
125# CHECK: Name: .symtab
126# CHECK: Name: .strtab
127# CHECK: Name: .shstrtab
128
129# Check that *only* foo is copied and not debugfoo or filesymbol.
130# CHECK:      Symbols [
131# CHECK-NEXT:   Symbol {
132# CHECK-NEXT:     Name:
133# CHECK-NEXT:     Value:
134# CHECK-NEXT:     Size:
135# CHECK-NEXT:     Binding:
136# CHECK-NEXT:     Type:
137# CHECK-NEXT:     Other:
138# CHECK-NEXT:     Section: Undefined
139# CHECK-NEXT:   }
140# CHECK-NEXT:   Symbol {
141# CHECK-NEXT:     Name: foo
142# CHECK-NEXT:     Value:
143# CHECK-NEXT:     Size:
144# CHECK-NEXT:     Binding: Global
145# CHECK-NEXT:     Type:
146# CHECK-NEXT:     Other:
147# CHECK-NEXT:     Section: .text
148# CHECK-NEXT:   }
149# CHECK-NEXT: ]
150