Static tramp v5 (#624)
[platform/upstream/libffi.git] / configure.ac
1 dnl Process this with autoconf to create configure
2
3 AC_PREREQ(2.68)
4
5 AC_INIT([libffi], [3.3], [http://github.com/libffi/libffi/issues])
6 AC_CONFIG_HEADERS([fficonfig.h])
7
8 AC_CANONICAL_SYSTEM
9 target_alias=${target_alias-$host_alias}
10
11 case "${host}" in
12   frv*-elf)
13     LDFLAGS=`echo $LDFLAGS | sed "s/\-B[^ ]*libgloss\/frv\///"`\ -B`pwd`/../libgloss/frv/
14     ;;
15 esac
16
17 AX_ENABLE_BUILDDIR
18
19 AM_INIT_AUTOMAKE
20
21 # The same as in boehm-gc and libstdc++. Have to borrow it from there.
22 # We must force CC to /not/ be precious variables; otherwise
23 # the wrong, non-multilib-adjusted value will be used in multilibs.
24 # As a side effect, we have to subst CFLAGS ourselves.
25 # Also save and restore CFLAGS, since AC_PROG_CC will come up with
26 # defaults of its own if none are provided.
27
28 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
29 m4_define([_AC_ARG_VAR_PRECIOUS],[])
30 save_CFLAGS=$CFLAGS
31 AC_PROG_CC
32 AC_PROG_CXX
33 CFLAGS=$save_CFLAGS
34 m4_undefine([_AC_ARG_VAR_PRECIOUS])
35 m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
36
37 AC_SUBST(CFLAGS)
38
39 AM_PROG_AS
40 AM_PROG_CC_C_O
41 AC_PROG_LIBTOOL
42 AC_CONFIG_MACRO_DIR([m4])
43
44 # Test for 64-bit build.
45 AC_CHECK_SIZEOF([size_t])
46
47 AX_COMPILER_VENDOR
48 AX_CC_MAXOPT
49 # The AX_CFLAGS_WARN_ALL macro doesn't currently work for sunpro
50 # compiler.
51 if test "$ax_cv_c_compiler_vendor" != "sun"; then
52   AX_CFLAGS_WARN_ALL
53 fi
54
55 if test "x$GCC" = "xyes"; then
56   CFLAGS="$CFLAGS -fexceptions"
57 fi
58
59 cat > local.exp <<EOF
60 set CC_FOR_TARGET "$CC"
61 set CXX_FOR_TARGET "$CXX"
62 EOF
63
64 AM_MAINTAINER_MODE
65
66 AC_CHECK_HEADERS(sys/memfd.h)
67 AC_CHECK_FUNCS([memfd_create])
68
69 AC_CHECK_HEADERS(sys/mman.h)
70 AC_CHECK_FUNCS([mmap mkostemp mkstemp])
71 AC_FUNC_MMAP_BLACKLIST
72
73 dnl The -no-testsuite modules omit the test subdir.
74 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
75
76 TARGETDIR="unknown"
77 HAVE_LONG_DOUBLE_VARIANT=0
78
79 . ${srcdir}/configure.host
80
81 if test -n "${UNSUPPORTED}"; then
82   AC_MSG_ERROR(["libffi has not been ported to $host."])
83 fi
84
85 AC_SUBST(AM_RUNTESTFLAGS)
86 AC_SUBST(AM_LTLDFLAGS)
87
88 AC_HEADER_STDC
89 AC_CHECK_FUNCS(memcpy)
90 AC_FUNC_ALLOCA
91
92 AC_CHECK_SIZEOF(double)
93 AC_CHECK_SIZEOF(long double)
94
95 # Also AC_SUBST this variable for ffi.h.
96 if test -z "$HAVE_LONG_DOUBLE"; then
97   HAVE_LONG_DOUBLE=0
98   if test $ac_cv_sizeof_long_double != 0; then
99     if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
100       AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
101       HAVE_LONG_DOUBLE=1
102     else
103       if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
104         HAVE_LONG_DOUBLE=1
105         AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
106       fi
107     fi
108   fi
109 fi
110 AC_SUBST(HAVE_LONG_DOUBLE)
111 AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
112
113 AC_C_BIGENDIAN
114
115 GCC_AS_CFI_PSEUDO_OP
116
117 case "$TARGET" in
118   SPARC)
119     AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
120         libffi_cv_as_sparc_ua_pcrel, [
121         save_CFLAGS="$CFLAGS"
122         save_LDFLAGS="$LDFLAGS"
123         CFLAGS="$CFLAGS -fpic"
124         LDFLAGS="$LDFLAGS -shared"
125         AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
126                     [libffi_cv_as_sparc_ua_pcrel=yes],
127                     [libffi_cv_as_sparc_ua_pcrel=no])
128         CFLAGS="$save_CFLAGS"
129         LDFLAGS="$save_LDFLAGS"])
130     if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
131         AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
132                   [Define if your assembler and linker support unaligned PC relative relocs.])
133     fi
134
135     AC_CACHE_CHECK([assembler .register pseudo-op support],
136        libffi_cv_as_register_pseudo_op, [
137        libffi_cv_as_register_pseudo_op=unknown
138        # Check if we have .register
139        AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
140                        [libffi_cv_as_register_pseudo_op=yes],
141                        [libffi_cv_as_register_pseudo_op=no])
142     ])
143     if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
144        AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
145                [Define if your assembler supports .register.])
146     fi
147     ;;
148
149   X86*)
150     AC_CACHE_CHECK([assembler supports pc related relocs],
151         libffi_cv_as_x86_pcrel, [
152         libffi_cv_as_x86_pcrel=no
153         echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
154         if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
155             libffi_cv_as_x86_pcrel=yes
156         fi
157         ])
158     if test "x$libffi_cv_as_x86_pcrel" = xyes; then
159         AC_DEFINE(HAVE_AS_X86_PCREL, 1,
160                   [Define if your assembler supports PC relative relocs.])
161     fi
162     ;;
163
164   S390)
165     AC_CACHE_CHECK([compiler uses zarch features],
166         libffi_cv_as_s390_zarch, [
167         libffi_cv_as_s390_zarch=no
168         echo 'void foo(void) { bar(); bar(); }' > conftest.c
169         if $CC $CFLAGS -S conftest.c > /dev/null 2>&1; then
170             if grep -q brasl conftest.s; then
171                 libffi_cv_as_s390_zarch=yes
172             fi
173         fi
174         ])
175     if test "x$libffi_cv_as_s390_zarch" = xyes; then
176         AC_DEFINE(HAVE_AS_S390_ZARCH, 1,
177                   [Define if the compiler uses zarch features.])
178     fi
179     ;;
180 esac
181
182 AC_CACHE_CHECK([whether compiler supports pointer authentication],
183    libffi_cv_as_ptrauth, [
184    libffi_cv_as_ptrauth=unknown
185    AC_TRY_COMPILE(,[
186 #ifdef __clang__
187 # if __has_feature(ptrauth_calls)
188 #  define HAVE_PTRAUTH 1
189 # endif
190 #endif
191
192 #ifndef HAVE_PTRAUTH
193 # error Pointer authentication not supported
194 #endif
195                    ],
196                    [libffi_cv_as_ptrauth=yes],
197                    [libffi_cv_as_ptrauth=no])
198 ])
199 if test "x$libffi_cv_as_ptrauth" = xyes; then
200     AC_DEFINE(HAVE_PTRAUTH, 1,
201               [Define if your compiler supports pointer authentication.])
202 fi
203
204 # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
205 AC_ARG_ENABLE(pax_emutramp,
206   [  --enable-pax_emutramp       enable pax emulated trampolines, for we can't use PROT_EXEC],
207   if test "$enable_pax_emutramp" = "yes"; then
208     AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
209       [Define this if you want to enable pax emulated trampolines])
210   fi)
211
212 LT_SYS_SYMBOL_USCORE
213 if test "x$sys_symbol_underscore" = xyes; then
214     AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.])
215 fi
216
217 FFI_EXEC_TRAMPOLINE_TABLE=0
218 case "$target" in
219      *arm*-apple-* | aarch64-apple-*)
220        FFI_EXEC_TRAMPOLINE_TABLE=1
221        AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
222                  [Cannot use PROT_EXEC on this target, so, we revert to
223                    alternative means])
224      ;;
225      *-apple-* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris* | *-linux-android*)
226        AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
227                  [Cannot use malloc on this target, so, we revert to
228                    alternative means])
229      ;;
230 esac
231 AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
232 AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
233
234 if test x$TARGET = xX86_64; then
235     AC_CACHE_CHECK([toolchain supports unwind section type],
236         libffi_cv_as_x86_64_unwind_section_type, [
237         cat  > conftest1.s << EOF
238 .text
239 .globl foo
240 foo:
241 jmp bar
242 .section .eh_frame,"a",@unwind
243 bar:
244 EOF
245
246         cat > conftest2.c  << EOF
247 extern void foo();
248 int main(){foo();}
249 EOF
250
251         libffi_cv_as_x86_64_unwind_section_type=no
252         # we ensure that we can compile _and_ link an assembly file containing an @unwind section
253         # since the compiler can support it and not the linker (ie old binutils)
254         if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
255            $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
256             libffi_cv_as_x86_64_unwind_section_type=yes
257         fi
258         ])
259     if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
260         AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
261                   [Define if your assembler supports unwind section type.])
262     fi
263 fi
264
265 if test "x$GCC" = "xyes"; then
266   AX_CHECK_COMPILE_FLAG(-fno-lto, libffi_cv_no_lto=-fno-lto)
267
268   AC_CACHE_CHECK([whether .eh_frame section should be read-only],
269       libffi_cv_ro_eh_frame, [
270         libffi_cv_ro_eh_frame=yes
271         echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
272         if $CC $CFLAGS -c -fpic -fexceptions $libffi_cv_no_lto -o conftest.o conftest.c > /dev/null 2>&1; then
273             if readelf -WS conftest.o | grep -q -n 'eh_frame .* WA'; then
274                 libffi_cv_ro_eh_frame=no
275             fi
276         fi
277         rm -f conftest.*
278       ])
279   if test "x$libffi_cv_ro_eh_frame" = xyes; then
280       AC_DEFINE(HAVE_RO_EH_FRAME, 1,
281               [Define if .eh_frame sections should be read-only.])
282       AC_DEFINE(EH_FRAME_FLAGS, "a",
283               [Define to the flags needed for the .section .eh_frame directive.  ])
284   else
285       AC_DEFINE(EH_FRAME_FLAGS, "aw",
286               [Define to the flags needed for the .section .eh_frame directive.  ])
287   fi
288
289   AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
290       libffi_cv_hidden_visibility_attribute, [
291         echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1  ; }' > conftest.c
292         libffi_cv_hidden_visibility_attribute=no
293         if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
294             if egrep '(\.hidden|\.private_extern).*foo' conftest.s >/dev/null; then
295                 libffi_cv_hidden_visibility_attribute=yes
296             fi
297         fi
298         rm -f conftest.*
299       ])
300   if test $libffi_cv_hidden_visibility_attribute = yes; then
301       AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
302               [Define if __attribute__((visibility("hidden"))) is supported.])
303   fi
304 fi
305
306 AC_ARG_ENABLE(docs,
307               AC_HELP_STRING([--disable-docs],
308                              [Disable building of docs (default: no)]),
309               [enable_docs=no],
310               [enable_docs=yes])
311 AM_CONDITIONAL(BUILD_DOCS, [test x$enable_docs = xyes])
312
313 AH_BOTTOM([
314 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
315 #ifdef LIBFFI_ASM
316 #ifdef __APPLE__
317 #define FFI_HIDDEN(name) .private_extern name
318 #else
319 #define FFI_HIDDEN(name) .hidden name
320 #endif
321 #else
322 #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
323 #endif
324 #else
325 #ifdef LIBFFI_ASM
326 #define FFI_HIDDEN(name)
327 #else
328 #define FFI_HIDDEN
329 #endif
330 #endif
331 ])
332
333 AC_SUBST(TARGET)
334 AC_SUBST(TARGETDIR)
335
336 changequote(<,>)
337 TARGET_OBJ=
338 for i in $SOURCES; do
339   TARGET_OBJ="${TARGET_OBJ} src/${TARGETDIR}/"`echo $i | sed 's/[cS]$/lo/'`
340 done
341 changequote([,])
342 AC_SUBST(TARGET_OBJ)
343
344 AC_SUBST(SHELL)
345
346 AC_ARG_ENABLE(debug,
347 [  --enable-debug          debugging mode],
348   if test "$enable_debug" = "yes"; then
349     AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
350   fi)
351 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
352
353 AC_ARG_ENABLE(structs,
354 [  --disable-structs       omit code for struct support],
355   if test "$enable_structs" = "no"; then
356     AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this if you do not want support for aggregate types.])
357   fi)
358 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
359
360 AC_ARG_ENABLE(raw-api,
361 [  --disable-raw-api       make the raw api unavailable],
362   if test "$enable_raw_api" = "no"; then
363     AC_DEFINE(FFI_NO_RAW_API, 1, [Define this if you do not want support for the raw API.])
364   fi)
365
366 case "$target" in
367      *-cygwin*)
368      ;;
369      *arm*-*-linux-* | aarch64*-*-linux-* | i*86-*-linux-* | x86_64-*-linux-*)
370        AC_DEFINE(FFI_EXEC_STATIC_TRAMP, 1,
371                  [Define this if you want statically defined trampolines])
372      ;;
373 esac
374
375 AC_ARG_ENABLE(purify-safety,
376 [  --enable-purify-safety  purify-safe mode],
377   if test "$enable_purify_safety" = "yes"; then
378     AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
379   fi)
380
381 AC_ARG_ENABLE(multi-os-directory,
382 [  --disable-multi-os-directory
383                           disable use of gcc --print-multi-os-directory to change the library installation directory])
384                           
385 # These variables are only ever used when we cross-build to X86_WIN32.
386 # And we only support this with GCC, so...
387 if test "x$GCC" = "xyes"; then
388   if test -n "$with_cross_host" &&
389      test x"$with_cross_host" != x"no"; then
390     toolexecdir='${exec_prefix}'/'$(target_alias)'
391     toolexeclibdir='${toolexecdir}'/lib
392   else
393     toolexecdir='${libdir}'/gcc-lib/'$(target_alias)'
394     toolexeclibdir='${libdir}'
395   fi
396   if test x"$enable_multi_os_directory" != x"no"; then
397     multi_os_directory=`$CC $CFLAGS -print-multi-os-directory`
398     case $multi_os_directory in
399       .) ;; # Avoid trailing /.
400       ../*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
401     esac
402   fi
403   AC_SUBST(toolexecdir)
404 else
405   toolexeclibdir='${libdir}'
406 fi
407 AC_SUBST(toolexeclibdir)
408
409 # Check linker support.
410 LIBFFI_ENABLE_SYMVERS
411
412 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
413 AC_CONFIG_COMMANDS(src, [
414 test -d src || mkdir src
415 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
416 ], [TARGETDIR="$TARGETDIR"])
417
418 AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile doc/Makefile libffi.pc)
419
420 AC_OUTPUT
421
422 # Copy this file instead of using AC_CONFIG_LINK in order to support
423 # compiling with MSVC, which won't understand cygwin style symlinks.
424 cp ${srcdir}/src/$TARGETDIR/ffitarget.h include/ffitarget.h