aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test
blob: 3eefed2b2066671f8f24de2cd715af140354faa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# RUN: yaml2obj %s -o %t
# RUN: cp %t %t3
# RUN: llvm-objcopy --strip-debug %t %t2
# RUN: llvm-readobj --file-headers --sections --symbols %t2 | FileCheck %s

# Verify that the previous run of llvm-objcopy has not modified the input.
# RUN: cmp %t %t3

# RUN: llvm-objcopy -g %t %t2g
# Verify that --strip-debug and -g produce the same output
# RUN: cmp %t2 %t2g

# RUN: llvm-strip --strip-debug %t3
# RUN: cmp %t2 %t3

# RUN: cp %t %t4
# RUN: llvm-strip -d %t4
# RUN: cmp %t2 %t4

# RUN: cp %t %t5
# RUN: llvm-strip -g %t5
# RUN: cmp %t2 %t5

# RUN: cp %t %t6
# RUN: llvm-strip -S %t6
# RUN: cmp %t2 %t6

# RUN: rm -f %t.a
# RUN: llvm-ar crs %t.a %t
# RUN: llvm-objcopy --strip-debug %t.a %t.a
# RUN: llvm-ar p %t.a > %t7
# RUN: cmp %t2 %t7

# Verify that an archive with multiple object files is handled correctly.
# RUN: cp %t %t.duplicate
# RUN: cp %t2 %t.duplicate.stripped
# RUN: rm -f %t.multiple-stripped-obj.a
# RUN: llvm-ar crs %t.multiple-stripped-obj.a %t2 %t.duplicate.stripped
# RUN: rm -f %t.multiple-obj.a
# RUN: llvm-ar crs %t.multiple-obj.a %t %t.duplicate
# RUN: llvm-objcopy --strip-debug %t.multiple-obj.a %t.multiple-obj.stripped.a
# RUN: llvm-ar p %t.multiple-stripped-obj.a > %t.multiple-stripped-obj.a.dump
# RUN: llvm-ar p %t.multiple-obj.stripped.a > %t.multiple-obj.stripped.a.dump
# RUN: cmp %t.multiple-stripped-obj.a.dump %t.multiple-obj.stripped.a.dump

# We can not use %t inside the patterns passed to FileCheck,
# thus we have to use "recognizable" file names.
# RUN: cp %t %t1.o
# RUN: cp %s %t2.txt
# RUN: cp %t %t3.o
# RUN: rm -f %t.non-object.a
# RUN: llvm-ar cr %t.non-object.a %t1.o %t2.txt %t3.o
# RUN: llvm-ar t %t.non-object.a | FileCheck %s --check-prefix=NON-OBJECT-ARCHIVE-MEMBERS

# NON-OBJECT-ARCHIVE-MEMBERS: 1.o
# NON-OBJECT-ARCHIVE-MEMBERS-NEXT: 2.txt
# NON-OBJECT-ARCHIVE-MEMBERS-NEXT: 3.o

# RUN: cp %t.non-object.a %t.non-object.copy.a
# RUN: not llvm-objcopy --strip-debug %t.non-object.a %t2.non-object.a 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT

# BAD-FORMAT: The file was not recognized as a valid object file

# Verify that %t.non-object.a has not been modified.
# RUN: cmp %t.non-object.a %t.non-object.copy.a

# RUN: rm -f %t.thin.a
# Copy %t to %t.thin.archive.member to avoid changing %t directly.
# RUN: cp %t %t.thin.archive.member
# RUN: llvm-ar crsT %t.thin.a %t.thin.archive.member
# RUN: llvm-objcopy --strip-debug %t.thin.a %t2.thin.a
# RUN: cat %t.thin.a | FileCheck %s --check-prefix=VERIFY-THIN-ARCHIVE
# RUN: cat %t2.thin.a | FileCheck %s --check-prefix=VERIFY-THIN-ARCHIVE

# VERIFY-THIN-ARCHIVE: !<thin>

# Verify that the member of a thin archive was properly modified.
# RUN: cmp %t2 %t.thin.archive.member

# RUN: rm -f %t.non-object.thin.a
# RUN: llvm-ar crsT %t.non-object.thin.a %t1.o %t2.txt %t3.o
# RUN: cp %t.non-object.thin.a %t.non-object.thin.copy.a
# RUN: not llvm-objcopy --strip-debug %t.non-object.thin.a %t.non-object.thin.a 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT

# Verify that in the case of error thin archive and its memebers are not getting modified.
# RUN: cmp %t.non-object.thin.a %t.non-object.thin.copy.a
# RUN: cmp %t %t1.o
# RUN: cmp %s %t2.txt
# RUN: cmp %t %t3.o

!ELF
FileHeader:
  Class:           ELFCLASS64
  Data:            ELFDATA2LSB
  Type:            ET_REL
  Machine:         EM_X86_64
Sections:
  - Name:            .debugfoo
    Type:            SHT_PROGBITS
    Content:         "00000000"
  ## .zdebug is no longer recognized as a debug section.
  - Name:            .zdebugfoo
    Type:            SHT_PROGBITS
    Content:         "00000000"
  - Name:            .gdb_index
    Type:            SHT_PROGBITS
    Content:         "00000000"
  - Name:            .text
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
    AddressAlign:    0x0000000000000010
    Content:         "00000000"
Symbols:
  - Name:    foo
    Section: .text
    Binding:  STB_GLOBAL
  - Name:    debugfoo
    Section: .debugfoo
    Binding:  STB_GLOBAL
  - Name:    filesymbol
    Type:    STT_FILE

# CHECK: SectionHeaderCount: 6

# CHECK: Name: .zdebugfoo
# CHECK: Name: .text
# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab

# Check that *only* foo is copied and not debugfoo or filesymbol.
# CHECK:      Symbols [
# CHECK-NEXT:   Symbol {
# CHECK-NEXT:     Name:
# CHECK-NEXT:     Value:
# CHECK-NEXT:     Size:
# CHECK-NEXT:     Binding:
# CHECK-NEXT:     Type:
# CHECK-NEXT:     Other:
# CHECK-NEXT:     Section: Undefined
# CHECK-NEXT:   }
# CHECK-NEXT:   Symbol {
# CHECK-NEXT:     Name: foo
# CHECK-NEXT:     Value:
# CHECK-NEXT:     Size:
# CHECK-NEXT:     Binding: Global
# CHECK-NEXT:     Type:
# CHECK-NEXT:     Other:
# CHECK-NEXT:     Section: .text
# CHECK-NEXT:   }
# CHECK-NEXT: ]