1#! /bin/sh
2# Copyright (C) 2020 Red Hat, Inc.
3# This file is part of elfutils.
4#
5# This file is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# elfutils is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18. $srcdir/test-subr.sh
19
20# void *SYM1;
21# void *SYM2 = 0;
22# extern void *SYM3;
23# static void *SYM4;
24#
25# void *SYM6 = &SYM3;
26# static void *SYM7 = &SYM3;
27#
28# void *SYM8 __attribute__((__weak__));
29#
30# void FUN1 (void) { }
31# static void FUN2 (void) { }
32# extern void FUN3 (void);
33#
34# void *FREF = FUN3;
35#
36# void __attribute__((__weak__)) FUN4 (void) { };
37#
38# int NUM0 = 0; __asm__(".type NUM0,%gnu_unique_object");
39# int __thread NUM1 = 1;
40#
41# gcc -m64 -c syms.c -o testfilesyms64
42# gcc -m32 -c syms.c -o testfilesyms32
43
44testfiles testfilesyms32 testfilesyms64
45
46testrun_compare ${abs_top_builddir}/src/nm --format=bsd testfilesyms32 <<\EOF
4700000008 D FREF
4800000000 T FUN1
4900000010 t FUN2
50         U FUN3
5100000020 W FUN4
5200000008 u NUM0
5300000000 D NUM1
5400000004 C SYM1
5500000000 B SYM2
56         U SYM3
570000000c b SYM4
5800000000 D SYM6
5900000004 d SYM7
6000000004 V SYM8
61         U _GLOBAL_OFFSET_TABLE_
6200000000 T __x86.get_pc_thunk.ax
63EOF
64
65testrun_compare ${abs_top_builddir}/src/nm --format=posix testfilesyms32 <<\EOF
66FREF D 00000008 00000004
67FUN1 T 00000000 00000010
68FUN2 t 00000010 00000010
69FUN3 U
70FUN4 W 00000020 00000010
71NUM0 u 00000008 00000004
72NUM1 D 00000000 00000004
73SYM1 C 00000004 00000004
74SYM2 B 00000000 00000004
75SYM3 U
76SYM4 b 0000000c 00000004
77SYM6 D 00000000 00000004
78SYM7 d 00000004 00000004
79SYM8 V 00000004 00000004
80_GLOBAL_OFFSET_TABLE_ U
81__x86.get_pc_thunk.ax T 00000000 00000000
82EOF
83
84testrun_compare ${abs_top_builddir}/src/nm --format=sysv testfilesyms32 <<\EOF
85
86
87Symbols from testfilesyms32:
88
89Name                  Value    Class  Type     Size     Line Section
90
91FREF                 |00000008|GLOBAL|OBJECT  |00000004|    |.data.rel
92FUN1                 |00000000|GLOBAL|FUNC    |00000010|    |.text
93FUN2                 |00000010|LOCAL |FUNC    |00000010|    |.text
94FUN3                 |        |GLOBAL|NOTYPE  |        |    |UNDEF
95FUN4                 |00000020|WEAK  |FUNC    |00000010|    |.text
96NUM0                 |00000008|UNIQUE|OBJECT  |00000004|    |.bss
97NUM1                 |00000000|GLOBAL|TLS     |00000004|    |.tdata
98SYM1                 |00000004|GLOBAL|OBJECT  |00000004|    |COMMON
99SYM2                 |00000000|GLOBAL|OBJECT  |00000004|    |.bss
100SYM3                 |        |GLOBAL|NOTYPE  |        |    |UNDEF
101SYM4                 |0000000c|LOCAL |OBJECT  |00000004|    |.bss
102SYM6                 |00000000|GLOBAL|OBJECT  |00000004|    |.data.rel
103SYM7                 |00000004|LOCAL |OBJECT  |00000004|    |.data.rel
104SYM8                 |00000004|WEAK  |OBJECT  |00000004|    |.bss
105_GLOBAL_OFFSET_TABLE_|        |GLOBAL|NOTYPE  |        |    |UNDEF
106__x86.get_pc_thunk.ax|00000000|GLOBAL|FUNC    |00000000|    |.text.__x86.get_pc_thunk.ax
107EOF
108
109testrun_compare ${abs_top_builddir}/src/nm --format=bsd testfilesyms64 <<\EOF
1100000000000000010 D FREF
1110000000000000000 T FUN1
1120000000000000007 t FUN2
113                 U FUN3
114000000000000000e W FUN4
1150000000000000010 u NUM0
1160000000000000000 D NUM1
1170000000000000008 C SYM1
1180000000000000000 B SYM2
119                 U SYM3
1200000000000000018 b SYM4
1210000000000000000 D SYM6
1220000000000000008 d SYM7
1230000000000000008 V SYM8
124EOF
125
126testrun_compare ${abs_top_builddir}/src/nm --format=posix testfilesyms64 <<\EOF
127FREF D 0000000000000010 0000000000000008
128FUN1 T 0000000000000000 0000000000000007
129FUN2 t 0000000000000007 0000000000000007
130FUN3 U
131FUN4 W 000000000000000e 0000000000000007
132NUM0 u 0000000000000010 0000000000000004
133NUM1 D 0000000000000000 0000000000000004
134SYM1 C 0000000000000008 0000000000000008
135SYM2 B 0000000000000000 0000000000000008
136SYM3 U
137SYM4 b 0000000000000018 0000000000000008
138SYM6 D 0000000000000000 0000000000000008
139SYM7 d 0000000000000008 0000000000000008
140SYM8 V 0000000000000008 0000000000000008
141EOF
142
143testrun_compare ${abs_top_builddir}/src/nm --format=sysv testfilesyms64 <<\EOF
144
145
146Symbols from testfilesyms64:
147
148Name   Value            Class  Type     Size             Line Section
149
150FREF  |0000000000000010|GLOBAL|OBJECT  |0000000000000008|    |.data.rel
151FUN1  |0000000000000000|GLOBAL|FUNC    |0000000000000007|    |.text
152FUN2  |0000000000000007|LOCAL |FUNC    |0000000000000007|    |.text
153FUN3  |                |GLOBAL|NOTYPE  |                |    |UNDEF
154FUN4  |000000000000000e|WEAK  |FUNC    |0000000000000007|    |.text
155NUM0  |0000000000000010|UNIQUE|OBJECT  |0000000000000004|    |.bss
156NUM1  |0000000000000000|GLOBAL|TLS     |0000000000000004|    |.tdata
157SYM1  |0000000000000008|GLOBAL|OBJECT  |0000000000000008|    |COMMON
158SYM2  |0000000000000000|GLOBAL|OBJECT  |0000000000000008|    |.bss
159SYM3  |                |GLOBAL|NOTYPE  |                |    |UNDEF
160SYM4  |0000000000000018|LOCAL |OBJECT  |0000000000000008|    |.bss
161SYM6  |0000000000000000|GLOBAL|OBJECT  |0000000000000008|    |.data.rel
162SYM7  |0000000000000008|LOCAL |OBJECT  |0000000000000008|    |.data.rel
163SYM8  |0000000000000008|WEAK  |OBJECT  |0000000000000008|    |.bss
164EOF
165
166exit 0
167