blob: d7079f6abcb2a0db24b149c96531bf1dc8b884f3 [file] [log] [blame]
Jake Ehrlich1bfefc12017-11-13 22:13:08 +00001# RUN: yaml2obj %s > %t
Alexander Shaposhnikovd7eaf272018-06-04 18:55:41 +00002# RUN: cp %t %t3
Jordan Rupprecht298ea3f2019-01-11 18:06:31 +00003# RUN: llvm-objcopy --strip-debug %t %t2
4# RUN: llvm-readobj --file-headers --sections --symbols %t2 | FileCheck %s
Jake Ehrlich1bfefc12017-11-13 22:13:08 +00005
Alexander Shaposhnikovd7eaf272018-06-04 18:55:41 +00006# Verify that the previous run of llvm-objcopy has not modified the input.
7# RUN: cmp %t %t3
Alexander Shaposhnikovcca69982018-05-07 19:32:09 +00008
Douglas Yung914e8382019-01-25 09:57:20 +00009# RUN: llvm-objcopy -g %t %t2g
10# Verify that --strip-debug and -g produce the same output
11# RUN: cmp %t2 %t2g
12
Jordan Rupprecht298ea3f2019-01-11 18:06:31 +000013# RUN: llvm-strip --strip-debug %t3
Alexander Shaposhnikovcca69982018-05-07 19:32:09 +000014# RUN: cmp %t2 %t3
15
Alexander Shaposhnikovd7eaf272018-06-04 18:55:41 +000016# 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
Alexander Shaposhnikov42b5ef02018-07-06 17:51:03 +000028# 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
Fangrui Song87b4b8f2018-07-31 21:26:35 +000074
Alexander Shaposhnikov42b5ef02018-07-06 17:51:03 +000075# 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
Jake Ehrlich1bfefc12017-11-13 22:13:08 +000091!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"
Fangrui Song87b4b8f2018-07-31 21:26:35 +0000101 - Name: .zdebugfoo
102 Type: SHT_PROGBITS
103 Content: "00000000"
104 - Name: .gdb_index
105 Type: SHT_PROGBITS
106 Content: "00000000"
Jake Ehrlich1bfefc12017-11-13 22:13:08 +0000107 - Name: .text
108 Type: SHT_PROGBITS
109 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
110 AddressAlign: 0x0000000000000010
111 Content: "00000000"
112Symbols:
113 Global:
114 - Name: foo
115 Section: .text
116 - Name: debugfoo
117 Section: .debugfoo
118
119# CHECK: SectionHeaderCount: 5
120
121# CHECK: Name: .text
122# CHECK: Name: .symtab
123# CHECK: Name: .strtab
124# CHECK: Name: .shstrtab
125
126# Check that *only* foo is copied and not debugfoo
127# CHECK: Symbols [
128# CHECK-NEXT: Symbol {
129# CHECK-NEXT: Name:
130# CHECK-NEXT: Value:
131# CHECK-NEXT: Size:
132# CHECK-NEXT: Binding:
133# CHECK-NEXT: Type:
134# CHECK-NEXT: Other:
135# CHECK-NEXT: Section: Undefined
136# CHECK-NEXT: }
137# CHECK-NEXT: Symbol {
138# CHECK-NEXT: Name: foo
139# CHECK-NEXT: Value:
140# CHECK-NEXT: Size:
141# CHECK-NEXT: Binding: Global
142# CHECK-NEXT: Type:
143# CHECK-NEXT: Other:
144# CHECK-NEXT: Section: .text
145# CHECK-NEXT: }
146# CHECK-NEXT: ]