1 # export.at -- test symbol exports -*- Autotest -*-
3 # Copyright (C) 2007, 2008 Free Software Foundation, Inc.
4 # Written by Ralf Wildenhues, 2007
6 # This file is part of GNU Libtool.
8 # GNU Libtool is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of
11 # the License, or (at your option) any later version.
13 # GNU Libtool is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Libtool; see the file COPYING. If not, a copy
20 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
21 # or obtained by writing to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 AT_SETUP([Export test])
26 AT_KEYWORDS([libtool])
28 AT_CHECK([$LIBTOOL --features | grep 'disable shared libraries' && (exit 77)],
30 AT_CHECK([eval `$LIBTOOL --config | sed -n '/^archive_expsym_cmds=/,/^$/p'`
31 test -n "$archive_expsym_cmds" || echo false >can-hide
32 case $archive_expsym_cmds in
33 *-retain-symbols-file*) echo false >can-hide ;;
36 test -s can-hide && can_hide=false
38 LDFLAGS="$LDFLAGS -no-undefined"
43 [[/* all kinds of data items */
52 extern const int v5, v6;
53 extern const char *v7;
54 extern const char v8[];
55 extern int (*const v12) (void);
58 const char* v7 = "\01foo";
59 const char v8[] = "\01bar";
60 int v9(void) { return v2 + 1; }
62 int (*v11) (void) = v9;
63 int (*const v12) (void) = v9;
65 typedef struct { int arr[1000]; } large;
67 large v14 = { { 0 } };
68 large v15 = { { 1 } };
70 int w1 (void) { return 0; }
96 /* w32 fun. With GCC, you can have auto-import, which will work for
97 * functions and non-const variables. With MSVC, you have to explicitly
98 * import all variables. Depending on the amount of portability, you
99 * need these annotations: LIBA_SCOPE for GCC, and also LIBA_SCOPE_VAR
100 * for MSVC. Of course you can merge both to one, this test only avoids
101 * that in order to expose the auto-import feature on Cygwin.
103 * For users, it's best to realize that they should not provide any
104 * non-function API at all.
106 #if defined(LIBA_DLL_IMPORT)
107 # if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__)
108 # define LIBA_SCOPE extern __declspec(dllimport)
109 # if defined(_MSC_VER)
110 # define LIBA_SCOPE_VAR LIBA_SCOPE
114 #if !defined(LIBA_SCOPE)
115 # define LIBA_SCOPE extern
117 #if !defined(LIBA_SCOPE_VAR)
118 # define LIBA_SCOPE_VAR extern
123 LIBA_SCOPE_VAR int v1;
124 LIBA_SCOPE_VAR int v3, v4;
125 LIBA_SCOPE const int v5, v6;
126 LIBA_SCOPE_VAR const char* v7;
127 LIBA_SCOPE_VAR const char v8[];
129 LIBA_SCOPE_VAR int (*v10) (void);
130 LIBA_SCOPE_VAR int (*v11) (void);
131 LIBA_SCOPE int (*const v12) (void);
136 typedef struct { int arr[1000]; } large;
137 LIBA_SCOPE_VAR large v13, v14, v15;
141 char s = v7[0] + v8[0];
142 return s + v1 + v3 + v4 + v5 + v6 + v9() + v11() + v12()
143 + v13.arr[0] + v14.arr[0] + v15.arr[0]
150 /* these symbols should not be exported */
154 extern int w1 (void);
164 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a.c],[0],[ignore],[ignore])
165 AT_CHECK([$CC $CPPFLAGS -DLIBA_DLL_IMPORT $CFLAGS -c main.c],[0],[ignore],[ignore])
166 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c broken.c],[0],[ignore],[ignore])
168 for exportsyms in '' '-export-symbols-regex "v.*"' '-export-symbols asyms'
170 # case 1: shared library built from object.
171 LT_AT_CHECK([eval '$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la a.lo \
172 -rpath $libdir' $exportsyms], [], [ignore], [ignore])
173 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT liba.la],
174 [], [ignore], [ignore])
175 LT_AT_EXEC_CHECK([./main])
176 if test -n "$exportsyms" && $can_hide; then
177 AT_CHECK([if $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o broken$EXEEXT broken.$OBJEXT liba.la
178 then (exit 1); else :; fi], [], [ignore], [ignore])
181 # case 2: shared library built from convenience archive.
182 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libconv.la a.lo],
183 [], [ignore], [ignore])
184 LT_AT_CHECK([eval '$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la libconv.la \
185 -rpath $libdir' $exportsyms], [], [ignore], [ignore])
186 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT liba.la],
187 [], [ignore], [ignore])
188 LT_AT_EXEC_CHECK([./main])
189 if test -n "$exportsyms" && $can_hide; then
190 AT_CHECK([if $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o broken$EXEEXT broken.$OBJEXT liba.la
191 then (exit 1); else :; fi], [], [ignore], [ignore])
195 AT_CHECK([$can_hide || (exit 77)])