Properly handle common symbol and weak function
[external/binutils.git] / ld / testsuite / ld-elf / comm-data.exp
1 # Expect script for common symbol override.
2 #
3 # Copyright 2011, 2012 Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU Binutils.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21 #
22
23 #
24 # Written by Maciej W. Rozycki <macro@codesourcery.com>
25 #
26
27 # Exclude non-ELF targets.
28 if ![is_elf_format] {
29     return
30 }
31
32 # Exclude some more targets; feel free to include your favorite one
33 # if you like.
34 if { ![istarget *-*-linux*]
35      && ![istarget *-*-nacl*]
36      && ![istarget *-*-gnu*] } {
37     return
38 }
39
40 set testname "Common symbol override test"
41
42 # Define a global symbol.
43 run_ld_link_tests [list \
44     [list \
45         "$testname (auxiliary shared object build)" \
46         "-shared" \
47         "" \
48         { comm-data1.s } \
49         { \
50             { readelf -s comm-data1.sd } \
51         } \
52         "libcomm-data.so" \
53     ] \
54 ]
55
56 # Set the pointer size according to the ELF flavor.
57 set AFLAGS ""
58 if [is_elf64 "tmpdir/libcomm-data.so"] {
59     append AFLAGS " --defsym ELF64=1"
60 }
61
62 # Verify that a common symbol has been converted to an undefined
63 # reference to the global symbol of the same name defined above
64 # and that the debug reference has been dropped.
65 run_ld_link_tests [list \
66     [list \
67         "$testname" \
68         "-Ltmpdir -lcomm-data" \
69         "$AFLAGS" \
70         { comm-data2.s } \
71         { \
72             { readelf -s comm-data2.sd } \
73             { readelf -r comm-data2.rd } \
74             { readelf "-x .debug_foo" comm-data2.xd } \
75         } \
76         "comm-data" \
77     ] \
78     [list \
79         "$testname 3a" \
80         "-static" \
81         "" \
82         { comm-data3a.s comm-data3b.s } \
83         { \
84             { readelf -s comm-data3.sd } \
85         } \
86         "comm-data3a" \
87     ] \
88     [list \
89         "$testname 3b" \
90         "-static" \
91         "" \
92         { comm-data3b.s comm-data3a.s } \
93         { \
94             { readelf -s comm-data3.sd } \
95         } \
96         "comm-data3b" \
97     ] \
98 ]