• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1## Show that llvm-readelf + llvm-readobj demangle symbol names in symbol tables
2## (including dynamic symbols), relocations (including dynamic relocations), and groups.
3
4# RUN: yaml2obj %s -o %t.so
5
6## Check LLVM output style.
7# RUN: llvm-readobj --symbols --relocations --dyn-symbols --dyn-relocations \
8# RUN:              --elf-section-groups --cg-profile --addrsig         \
9# RUN:              --demangle %t.so > %t.llvm.long
10# RUN: llvm-readobj --symbols --relocations --dyn-symbols --dyn-relocations \
11# RUN:              --elf-section-groups --cg-profile --addrsig         \
12# RUN:              -C %t.so > %t.llvm.short
13# RUN: FileCheck %s --input-file %t.llvm.long --check-prefixes=LLVM-COMMON,LLVM-DEMANGLE
14# RUN: diff %t.llvm.long %t.llvm.short
15
16## Check that default is no demangling.
17# RUN: llvm-readobj --symbols --relocations --dyn-symbols --dyn-relocations \
18# RUN:              --elf-section-groups --cg-profile --addrsig         \
19# RUN:              %t.so > %t.llvm.default
20# RUN: llvm-readobj --symbols --relocations --dyn-symbols --dyn-relocations \
21# RUN:              --elf-section-groups --cg-profile --addrsig         \
22# RUN:              --demangle=false %t.so > %t.llvm.nodemangle
23# RUN: FileCheck %s --input-file %t.llvm.default --check-prefixes=LLVM-COMMON,LLVM-MANGLED
24# RUN: diff %t.llvm.default %t.llvm.nodemangle
25
26# LLVM-COMMON:        Relocations [
27# LLVM-COMMON:          Section {{.*}} .rela.text.foo {
28# LLVM-DEMANGLE-NEXT:     {{ }}foo(char){{ }}
29# LLVM-MANGLED-NEXT:      {{ }}_Z3fooc{{ }}
30# LLVM-COMMON-NEXT:     }
31# LLVM-COMMON:        ]
32
33# LLVM-COMMON:        Dynamic Relocations {
34# LLVM-DEMANGLE-NEXT:   {{ }}foo(int){{ }}
35# LLVM-MANGLED-NEXT:    {{ }}_Z3fooi{{ }}
36# LLVM-COMMON-NEXT:   }
37
38# LLVM-COMMON:   Symbols [
39# LLVM-DEMANGLE:   Name: foo(char){{ }}
40# LLVM-DEMANGLE:   Name: blah(float){{ }}
41# LLVM-MANGLED:    Name: _Z3fooc{{ }}
42# LLVM-MANGLED:    Name: _Z4blahf{{ }}
43# LLVM-COMMON:   ]
44
45# LLVM-COMMON:   DynamicSymbols [
46# LLVM-DEMANGLE:   Name: foo(int){{ }}
47# LLVM-MANGLED:    Name: _Z3fooi{{ }}
48# LLVM-COMMON:   ]
49
50# LLVM-COMMON:   Groups {
51# LLVM-DEMANGLE:   Signature: foo(char){{$}}
52# LLVM-MANGLED:    Signature: _Z3fooc{{$}}
53# LLVM-COMMON:   }
54
55# LLVM-COMMON:   CGProfile [
56# LLVM-DEMANGLE:   From: foo(char){{ }}
57# LLVM-DEMANGLE:   To:   blah(float){{ }}
58# LLVM-MANGLED:    From: _Z3fooc{{ }}
59# LLVM-MANGLED:    To:   _Z4blahf{{ }}
60# LLVM-COMMON:   ]
61
62# LLVM-COMMON:        Addrsig [
63# LLVM-DEMANGLE-NEXT:   Sym: foo(char){{ }}
64# LLVM-DEMANGLE-NEXT:   Sym: blah(float){{ }}
65# LLVM-MANGLED-NEXT:    Sym: _Z3fooc{{ }}
66# LLVM-MANGLED-NEXT:    Sym: _Z4blahf{{ }}
67# LLVM-COMMON-NEXT:   ]
68
69## Check GNU output style.
70# RUN: llvm-readelf --symbols --relocations --dyn-symbols --dyn-relocations \
71# RUN:              --elf-section-groups --addrsig --demangle %t.so > %t.gnu.long
72# RUN: llvm-readelf --symbols --relocations --dyn-symbols --dyn-relocations \
73# RUN:              --elf-section-groups --addrsig -C %t.so > %t.gnu.short
74# RUN: FileCheck %s --input-file %t.gnu.long --check-prefixes=GNU-COMMON,GNU-DEMANGLE
75# RUN: diff %t.gnu.long %t.gnu.short
76
77## Check that default is no demangling.
78# RUN: llvm-readelf --symbols --relocations --dyn-symbols --dyn-relocations \
79# RUN:              --elf-section-groups --addrsig %t.so > %t.gnu.default
80# RUN: llvm-readelf --symbols --relocations --dyn-symbols --dyn-relocations \
81# RUN:              --elf-section-groups --addrsig --demangle=false %t.so > %t.gnu.nodemangle
82# RUN: FileCheck %s --input-file %t.gnu.default --check-prefixes=GNU-COMMON,GNU-MANGLED
83# RUN: diff %t.gnu.default %t.gnu.nodemangle
84
85# GNU-COMMON:        Relocation section '.rela.text.foo' at offset {{.*}} contains 1 entries:
86# GNU-COMMON-NEXT:     Offset Info Type Symbol's Value Symbol's Name + Addend
87# GNU-DEMANGLE-NEXT:     foo(char){{ }}
88# GNU-MANGLED-NEXT:      _Z3fooc{{ }}
89
90# GNU-COMMON:        'RELA' relocation section at offset {{.*}} contains 24 bytes:
91# GNU-COMMON-NEXT:     Offset Info Type Symbol's Value Symbol's Name + Addend
92# GNU-DEMANGLE-NEXT:     foo(int){{ }}
93# GNU-MANGLED-NEXT:      _Z3fooi{{ }}
94
95# GNU-COMMON:        Symbol table '.dynsym' contains 2 entries:
96# GNU-COMMON-NEXT:     Num: Value            Size Type   Bind  Vis     Ndx Name
97# GNU-COMMON-NEXT:       0: 0000000000000000    0 NOTYPE LOCAL DEFAULT UND
98# GNU-DEMANGLE-NEXT:       foo(int){{$}}
99# GNU-MANGLED-NEXT:        _Z3fooi{{$}}
100
101# GNU-COMMON:        Symbol table '.symtab' contains 3 entries:
102# GNU-COMMON-NEXT:     Num: Value            Size Type   Bind  Vis     Ndx Name
103# GNU-COMMON-NEXT:       0: 0000000000000000    0 NOTYPE LOCAL DEFAULT UND
104# GNU-DEMANGLE-NEXT:       foo(char){{$}}
105# GNU-DEMANGLE-NEXT:       blah(float){{$}}
106# GNU-MANGLED-NEXT:        _Z3fooc{{$}}
107# GNU-MANGLED-NEXT:        _Z4blahf{{$}}
108
109# GNU-COMMON:        COMDAT group section [{{.*}}] `.group'
110# GNU-DEMANGLE-SAME: [foo(char)]
111# GNU-MANGLED-SAME:  [_Z3fooc]
112
113# GNU-COMMON:       Address-significant symbols section '.llvm_addrsig' contains 2 entries:
114# GNU-COMMON:          Num: Name
115# GNU-DEMANGLE-NEXT:     1: foo(char)
116# GNU-DEMANGLE-NEXT:     2: blah(float)
117# GNU-MANGLED-NEXT:      1: _Z3fooc
118# GNU-MANGLED-NEXT:      2: _Z4blahf
119
120!ELF
121FileHeader:
122  Class:           ELFCLASS64
123  Data:            ELFDATA2LSB
124  Type:            ET_DYN
125  Machine:         EM_X86_64
126Sections:
127  - Name:         .dynstr
128    Type:         SHT_STRTAB
129    Flags:        [ SHF_ALLOC ]
130    AddressAlign: 0x100
131    EntSize:      0x1
132  - Name:         .dynsym
133    Type:         SHT_DYNSYM
134    Flags:        [ SHF_ALLOC ]
135    Link:         .dynstr
136    Address:      0x100
137    AddressAlign: 0x100
138    EntSize:      0x18
139  - Name:         .rela.dyn
140    Type:         SHT_RELA
141    Flags:        [ SHF_ALLOC ]
142    Link:         .dynsym
143    Info:         .text.foo
144    Address:      0x200
145    AddressAlign: 0x100
146    EntSize:      0x18
147    Relocations:
148      - Offset: 0x10
149        Symbol: _Z3fooi
150        Type:   R_X86_64_PC32
151        Addend: 0x4
152  - Name:            .dynamic
153    Type:            SHT_DYNAMIC
154    Flags:           [ SHF_ALLOC ]
155    Address:         0x0000000000001000
156    Link:            .dynstr
157    AddressAlign:    0x0000000000001000
158    EntSize:         0x0000000000000010
159    Entries:
160      - Tag:             DT_STRTAB
161        Value:           0x0000000000000000
162      - Tag:             DT_STRSZ
163        Value:           0x0000000000000009
164      - Tag:             DT_SYMTAB
165        Value:           0x0000000000000100
166      - Tag:             DT_SYMENT
167        Value:           0x0000000000000018
168      - Tag:             DT_RELA
169        Value:           0x0000000000000200
170      - Tag:             DT_RELASZ
171        Value:           0x0000000000000018
172      - Tag:             DT_RELAENT
173        Value:           0x0000000000000018
174      - Tag:             DT_NULL
175        Value:           0x0000000000000000
176  - Name:  .text.foo
177    Type:  SHT_PROGBITS
178    Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]
179    Size:  0x40
180    Address: 0x2000
181    AddressAlign: 0x2000
182  - Name:  .group
183    Type:  SHT_GROUP
184    Link:  .symtab
185    Info:  _Z3fooc
186    Members:
187      - SectionOrType: GRP_COMDAT
188      - SectionOrType: .text.foo
189  - Name: .rela.text.foo
190    Type: SHT_RELA
191    Link: .symtab
192    Info: .text.foo
193    Relocations:
194      - Offset: 0x10
195        Symbol: _Z3fooc
196        Type:   R_X86_64_PC32
197  - Name: .llvm.call-graph-profile
198    Type: SHT_LLVM_CALL_GRAPH_PROFILE
199    Link: .symtab
200    EntSize: 16
201    Content: "01000000020000002000000000000000"
202  - Name: .llvm_addrsig
203    Type: SHT_LLVM_ADDRSIG
204    Link: .symtab
205    Content: "0102"
206Symbols:
207  - Name:    _Z3fooc
208    Type:    STT_FUNC
209    Section: .text.foo
210    Binding: STB_GLOBAL
211  - Name:    _Z4blahf
212    Type:    STT_FUNC
213    Section: .text.foo
214    Binding: STB_GLOBAL
215DynamicSymbols:
216  - Name:    _Z3fooi
217    Binding: STB_GLOBAL
218ProgramHeaders:
219  - Type:     PT_LOAD
220    Flags:    [ PF_R, PF_X ]
221    VAddr:    0x0
222    FirstSec: .dynstr
223    LastSec:  .text.foo
224  - Type:     PT_DYNAMIC
225    Flags:    [ PF_R ]
226    VAddr:    0x1000
227    FirstSec: .dynamic
228    LastSec:  .dynamic
229