ld: Move the .note.build-id section to near the start of the memory map.
[binutils-gdb.git] / gold / configure.ac
blob52f7a701128462a753a7270c260bf99553dff801
1 dnl Process this file with autoconf to produce a configure script.
2 dnl
3 dnl   Copyright (C) 2006-2024 Free Software Foundation, Inc.
4 dnl
5 dnl This file is free software; you can redistribute it and/or modify
6 dnl it under the terms of the GNU General Public License as published by
7 dnl the Free Software Foundation; either version 3 of the License, or
8 dnl (at your option) any later version.
9 dnl
10 dnl This program is distributed in the hope that it will be useful,
11 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 dnl GNU General Public License for more details.
14 dnl
15 dnl You should have received a copy of the GNU General Public License
16 dnl along with this program; see the file COPYING3.  If not see
17 dnl <http://www.gnu.org/licenses/>.
18 dnl
20 AC_INIT([gold], [0.1])
21 AC_CONFIG_SRCDIR(gold.cc)
23 AC_CANONICAL_TARGET
25 AM_INIT_AUTOMAKE([no-dist parallel-tests])
26 AM_SILENT_RULES([yes])
28 AM_CONFIG_HEADER(config.h:config.in)
30 AC_USE_SYSTEM_EXTENSIONS
32 # PR 14072
33 AH_VERBATIM([00_CONFIG_H_CHECK],
34 [/* Check that config.h is #included before system headers
35    (this works only for glibc, but that should be enough).  */
36 #if defined(__GLIBC__) && !defined(__FreeBSD_kernel__) && !defined(__CONFIG_H__)
37 #  error config.h must be #included before system headers
38 #endif
39 #define __CONFIG_H__ 1])
41 AC_ARG_WITH(sysroot,
42 [  --with-sysroot[=DIR]    search for usr/lib et al within DIR],
43 [sysroot=$withval], [sysroot=no])
45 if test "$sysroot" = "yes"; then
46   sysroot='${exec_prefix}/${target_alias}/sys-root'
47 elif test "$sysroot" = "no"; then
48   sysroot=
51 sysroot_relocatable=0
52 if test -n "$sysroot"; then
53   case "$sysroot" in
54     "${prefix}" | "${prefix}/"* | \
55     "${exec_prefix}" | "${exec_prefix}/"* | \
56     '${prefix}' | '${prefix}/'*| \
57     '${exec_prefix}' | '${exec_prefix}/'*)
58       sysroot_relocatable=1
59       ;;
60   esac
63 AC_DEFINE_UNQUOTED(TARGET_SYSTEM_ROOT, "$sysroot",
64   [System root for target files])
65 AC_DEFINE_UNQUOTED(TARGET_SYSTEM_ROOT_RELOCATABLE, $sysroot_relocatable,
66   [Whether the system root can be relocated])
68 dnl "install_as_default" is true if the linker to be installed as the
69 dnl default linker, ld.
70 dnl "installed_linker" is the installed gold linker name.
72 installed_linker=ld.gold
73 AC_ARG_ENABLE(gold,
74 [[  --enable-gold[=ARG]     build gold [ARG={default,yes,no}]]],
75 [case "${enableval}" in
76  default)
77    install_as_default=yes
78    ;;
79  yes)
80    if test x${enable_ld} = xno; then
81      install_as_default=yes
82    fi
83    ;;
84  esac],
85 [install_as_default=no])
86 AC_SUBST(install_as_default)
87 AC_SUBST(installed_linker)
89 AC_PLUGINS
90 if test "$plugins" = "yes"; then
91   AC_DEFINE(ENABLE_PLUGINS, 1,
92             [Define to enable linker plugins])
94 AM_CONDITIONAL(PLUGINS, test "$plugins" = "yes")
96 # Decide if -z relro should be enabled in ELF linker by default.
97 ac_default_ld_z_relro=unset
98 # Provide a configure time option to override our default.
99 AC_ARG_ENABLE(relro,
100               AS_HELP_STRING([--enable-relro],
101               [enable -z relro in ELF linker by default]),
102 [case "${enableval}" in
103   yes)  ac_default_ld_z_relro=1 ;;
104   no)  ac_default_ld_z_relro=0 ;;
105 esac])dnl
106 if test "${ac_default_ld_z_relro}" = unset; then
107   ac_default_ld_z_relro=1
109 AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_RELRO,
110   $ac_default_ld_z_relro,
111   [Define to 1 if you want to enable -z relro in ELF linker by default.])
113 AC_ARG_ENABLE([targets],
114 [  --enable-targets        alternative target configurations],
115 [case "${enableval}" in
116   yes | "")
117     AC_MSG_ERROR([--enable-targets option must specify target names or 'all'])
118     ;;
119   no)
120     enable_targets=
121     ;;
122   *)
123     enable_targets=$enableval
124     ;;
125 esac],
126 [# For now, enable all targets by default
127  enable_targets=all
130 # Canonicalize the enabled targets.
131 if test -n "$enable_targets"; then
132   for targ in `echo $enable_targets | sed -e 's/,/ /g'`; do
133     result=`$ac_config_sub $targ 2>/dev/null`
134     if test -n "$result"; then
135       canon_targets="$canon_targets $result"
136     else
137       # Permit unrecognized target names, like "all".
138       canon_targets="$canon_targets $targ"
139     fi
140   done
143 # Decide which "--hash-style" to use by default
144 # Provide a configure time option to override our default.
145 AC_ARG_ENABLE([default-hash-style],
146 AS_HELP_STRING([--enable-default-hash-style={sysv,gnu,both}],
147                [use this default hash style]),
148 [case "${enable_default_hash_style}" in
149   sysv | gnu | both) ;;
150   *) AC_MSG_ERROR([bad value ${enable_default_hash_style} for enable-default-hash-style option]) ;;
151 esac],
152 [case "${target}" in
153   # Enable gnu hash only on GNU targets, but not mips
154   mips*-*-*) enable_default_hash_style=sysv ;;
155   *-*-gnu* | *-*-linux* | *-*-nacl*) enable_default_hash_style=both ;;
156   *) enable_default_hash_style=sysv ;;
157 esac])
159 AC_DEFINE_UNQUOTED([DEFAULT_HASH_STYLE],
160   ["${enable_default_hash_style}"],
161   [Set the default --hash-style value])
163 # See which specific instantiations we need.
164 targetobjs=
165 all_targets=
166 default_machine=
167 default_size=
168 default_big_endian=
169 default_osabi=ELFOSABI_NONE
170 targ_32_little=
171 targ_32_big=
172 targ_64_little=
173 targ_64_big=
174 for targ in $target $canon_targets; do
175   if test "$targ" = "all"; then
176     targ_32_little=yes
177     targ_32_big=yes
178     targ_64_little=yes
179     targ_64_big=yes
180     all_targets=yes
181   else
182     . ${srcdir}/configure.tgt
184     if test "$targ_obj" = "UNKNOWN"; then
185       AC_MSG_ERROR("unsupported target $targ")
186     else
187       targetobjs="$targetobjs ${targ_obj}.\$(OBJEXT)"
188       if test "$targ_extra_obj" != ""; then
189         targetobjs="$targetobjs ${targ_extra_obj}.\$(OBJEXT)"
190       fi
191       if test "$targ_size" = "32" -o "$targ_extra_size" = "32"; then
192           if test "$targ_big_endian" = "true" \
193               -o "$targ_extra_big_endian" = "true"; then
194               targ_32_big=yes
195           fi
196           if test "$targ_big_endian" = "false" \
197               -o "$targ_extra_big_endian" = "false"; then
198               targ_32_little=yes
199           fi
200       fi
201       if test "$targ_size" = "64" -o "$targ_extra_size" = "64"; then
202           if test "$targ_big_endian" = "true" \
203               -o "$targ_extra_big_endian" = "true"; then
204               targ_64_big=yes
205           fi
206           if test "$targ_big_endian" = "false" \
207               -o "$targ_extra_big_endian" = "false"; then
208               targ_64_little=yes
209           fi
210       fi
212       if test "$target" = "$targ"; then
213         default_machine=$targ_machine
214         default_size=$targ_size
215         default_big_endian=$targ_big_endian
216         default_osabi=$targ_osabi
218         AM_CONDITIONAL(DEFAULT_TARGET_AARCH64, test "$targ_obj" = "aarch64")
219         AM_CONDITIONAL(DEFAULT_TARGET_ARM, test "$targ_obj" = "arm")
220         AM_CONDITIONAL(DEFAULT_TARGET_I386, test "$targ_obj" = "i386")
221         AM_CONDITIONAL(DEFAULT_TARGET_POWERPC, test "$targ_obj" = "powerpc")
222         AM_CONDITIONAL(DEFAULT_TARGET_SPARC, test "$targ_obj" = "sparc")
223         AM_CONDITIONAL(DEFAULT_TARGET_S390, test "$targ_obj" = "s390")
224         target_x86_64=no
225         target_x32=no
226         if test "$targ_obj" = "x86_64"; then
227           case "$target" in
228           x86_64*-linux-gnux32)
229             target_x32=yes
230             default_size=32
231             ;;
232           *)
233             target_x86_64=yes
234             ;;
235           esac
236         fi
237         AM_CONDITIONAL(DEFAULT_TARGET_X86_64, test "$target_x86_64" = "yes")
238         AM_CONDITIONAL(DEFAULT_TARGET_X32, test "$target_x32" = "yes")
239         AM_CONDITIONAL(DEFAULT_TARGET_X86_64_OR_X32,
240                        test "$target_x86_64" = "yes" -o "$target_x32" = "yes")
241         AM_CONDITIONAL(DEFAULT_TARGET_TILEGX, test "$targ_obj" = "tilegx")
242         AM_CONDITIONAL(DEFAULT_TARGET_MIPS, test "$targ_obj" = "mips")
243         DEFAULT_TARGET=${targ_obj}
244         AC_SUBST(DEFAULT_TARGET)
245       fi
246     fi
247   fi
248 done
250 # Remove any duplicates.
251 to=""
252 for t in $targetobjs; do
253   case " $to " in
254   *" $t "*) ;;
255   *) to="$to $t" ;;
256   esac
257 done
258 targetobjs=$to
260 if test -n "$targ_32_little"; then
261   AC_DEFINE(HAVE_TARGET_32_LITTLE, 1,
262               [Define to support 32-bit little-endian targets])
264 if test -n "$targ_32_big"; then
265   AC_DEFINE(HAVE_TARGET_32_BIG, 1,
266               [Define to support 32-bit big-endian targets])
268 if test -n "$targ_64_little"; then
269   AC_DEFINE(HAVE_TARGET_64_LITTLE, 1,
270               [Define to support 64-bit little-endian targets])
272 if test -n "$targ_64_big"; then
273   AC_DEFINE(HAVE_TARGET_64_BIG, 1,
274               [Define to support 64-bit big-endian targets])
277 if test -n "$all_targets"; then
278   TARGETOBJS='$(ALL_TARGETOBJS)'
279 else
280   TARGETOBJS="$targetobjs"
282 AC_SUBST(TARGETOBJS)
284 AC_DEFINE_UNQUOTED(GOLD_DEFAULT_MACHINE, $default_machine,
285                    [Default machine code])
286 AC_DEFINE_UNQUOTED(GOLD_DEFAULT_SIZE, $default_size,
287                    [Default size (32 or 64)])
288 AC_DEFINE_UNQUOTED(GOLD_DEFAULT_BIG_ENDIAN, $default_big_endian,
289                    [Default big endian (true or false)])
290 AC_DEFINE_UNQUOTED(GOLD_DEFAULT_OSABI, $default_osabi,
291                    [Default OSABI code])
293 AC_ARG_WITH(lib-path,
294 [  --with-lib-path=dir1:dir2...  set default LIB_PATH],
295 [case "$withval" in
296  yes) LIB_PATH='"/lib:/usr/lib"' ;;
297  no) LIB_PATH='""' ;;
298  *) LIB_PATH='"'"$withval"'"' ;;
299  esac],
300 [LIB_PATH='"::DEFAULT::"'])
301 AC_DEFINE_UNQUOTED(LIB_PATH, $LIB_PATH,
302                    [Default library search path])
303 if test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias"; then
304   AC_DEFINE(NATIVE_LINKER, 1, [Whether configured as a native linker])
307 AC_CHECK_TOOL(NM, nm)
309 AC_PROG_CC
310 AC_PROG_CXX
311 AC_PROG_YACC
312 AC_PROG_RANLIB
313 AC_PROG_INSTALL
314 AC_PROG_LN_S
316 ZW_GNU_GETTEXT_SISTER_DIR
317 AM_PO_SUBDIRS
319 AC_C_BIGENDIAN
321 AC_EXEEXT
323 AM_CONDITIONAL(NATIVE_LINKER,
324   test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias")
325 AM_CONDITIONAL(GCC, test "$GCC" = yes)
327 AM_CONDITIONAL(NATIVE_OR_CROSS_LINKER,
328   test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias" -o "x$host_alias" = "x$build_alias")
330 dnl Test for whether static linking is supported.  Some systems do not
331 dnl install static libraries.  This only affects the set of tests that
332 dnl we run.
333 AC_CACHE_CHECK([whether static linking works], [gold_cv_lib_static],
334 [LDFLAGS_hold=$LDFLAGS
335 LDFLAGS="$LDFLAGS -static"
336 AC_LINK_IFELSE([
337 AC_LANG_PROGRAM([[void f() { }]])],
338 [gold_cv_lib_static=yes], [gold_cv_lib_static=no])
339 LDFLAGS=$LDFLAGS_hold])
340 AM_CONDITIONAL(HAVE_STATIC, test "$gold_cv_lib_static" = "yes")
342 dnl Some architectures do not support taking pointers of functions
343 dnl defined in shared libraries except in -fPIC mode.  We need to
344 dnl tell the unittest framework if we're compiling for one of those
345 dnl targets, so it doesn't try to run the tests that do that.
346 AM_CONDITIONAL(FN_PTRS_IN_SO_WITHOUT_PIC, [
347   case $target_cpu in
348     powerpc*) false;;
349     x86_64) false;;
350     sparc64) false;;
351     s390x) false;;
352     *) true;;
353   esac])
355 dnl Test for gcc 4.1 or later.  Full support for -mcmodel=medium is
356 dnl only available in gcc 4.1.
357 AC_CACHE_CHECK([for gcc >= 4.1], [gold_cv_prog_gcc41],
358 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([
359 #if !defined __GNUC__
360 error
361 #elif __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1)
362 error
363 #endif
364 ])], [gold_cv_prog_gcc41=yes], [gold_cv_prog_gcc41=no])])
366 save_CFLAGS="$CFLAGS"
367 CFLAGS="$CFLAGS -mcmodel=medium"
368 AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], [have_mcmodel_medium=yes], [have_mcmodel_medium=no])
369 CFLAGS="$save_CFLAGS"
370 dnl Whether we can test -mcmodel=medium.
371 AM_CONDITIONAL(MCMODEL_MEDIUM,
372 [test "$target_cpu" = "x86_64" -a "$have_mcmodel_medium" = "yes" -a "$gold_cv_prog_gcc41" = "yes"])
374 dnl Test for gcc 9 or later.  Some incremental tests fail with GCC 9 or
375 dnl later.
376 AC_CACHE_CHECK([for gcc >= 9], [gold_cv_prog_gcc9],
377 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([
378 #if !defined __GNUC__ || __GNUC__ < 9
379 error
380 #endif
381 ])], [gold_cv_prog_gcc9=yes], [gold_cv_prog_gcc9=no])])
382 AM_CONDITIONAL(GCC9, [test "$gold_cv_prog_gcc9" = "yes"])
384 dnl Test for -fcf-protection on x86-64.  Some incremental tests fail with
385 dnl -fcf-protection.
386 AC_CACHE_CHECK([for -fcf-protection], [gold_cv_cflags_cf_protection],
387 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([
388 #if !defined __x86_64__ || !defined __CET__
389 error
390 #endif
391 ])], [gold_cv_cflags_cf_protection=yes], [gold_cv_cflags_cf_protection=no])])
392 AM_CONDITIONAL(CFLAGS_CF_PROTECTION, [test "$gold_cv_cflags_cf_protection" = "yes"])
394 AC_CACHE_CHECK([whether $CC supports -fmerge-constants],
395                [gold_cv_merge_constants], [
396 save_CFLAGS="$CFLAGS"
397 CFLAGS="$CFLAGS -fmerge-constants"
398 AC_COMPILE_IFELSE([AC_LANG_SOURCE([const char *s = "foo";])],
399                   [gold_cv_merge_constants=yes],
400                   [gold_cv_merge_constants=no])
401 CFLAGS="$save_CFLAGS"])
402 AC_SUBST([MERGE_CONSTANTS_FLAG])
403 AS_IF([test "$gold_cv_merge_constants" = yes],
404       [MERGE_CONSTANTS_FLAG=-fmerge-constants],
405       [MERGE_CONSTANTS_FLAG=])
407 dnl Test for __thread support.
408 AC_CACHE_CHECK([for thread support], [gold_cv_c_thread],
409 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([__thread int i = 1;])],
410 [gold_cv_c_thread=yes], [gold_cv_c_thread=no])])
412 AM_CONDITIONAL(TLS, test "$gold_cv_c_thread" = "yes")
414 dnl On GNU/Linux TLS in static programs only works when using glibc
415 dnl 2.4 or later.
416 AC_CACHE_CHECK([for glibc >= 2.4], [gold_cv_lib_glibc24],
417 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([
418 #include <features.h>
419 #if !defined __GLIBC__
420 error
421 #elif __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4)
422 error
423 #endif
424 ])], [gold_cv_lib_glibc24=yes], [gold_cv_lib_glibc24=no])])
426 AM_CONDITIONAL(STATIC_TLS, test "$gold_cv_lib_glibc24" = "yes")
428 dnl Test for #pragma omp threadprivate
429 AC_CACHE_CHECK([for omp support], [gold_cv_c_threadprivate],
430 [save_CFLAGS="$CFLAGS"
431 CFLAGS="$CFLAGS -fopenmp"
432 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
433 #include <omp.h>
434 int i;
435 #pragma omp threadprivate (i)
436 ])], [gold_cv_c_threadprivate=yes], [gold_cv_c_threadprivate=no])
437 CFLAGS="$save_CFLAGS"])
438 if test "$gold_cv_c_threadprivate" = "yes"; then
439   AC_DEFINE(HAVE_OMP_SUPPORT, 1,
440             [Define if compiler supports #pragma omp threadprivate])
442 AM_CONDITIONAL(OMP_SUPPORT, test "$gold_cv_c_threadprivate" = "yes")
444 dnl Test for the -ftls-dialect=gnu2 option.
445 dnl Use -Werror in case of compilers that make unknown -m options warnings.
446 dnl They would pass the test here, but fail in actual use when $WARN_CFLAGS
447 dnl gets set later by default Autoconf magic to include -Werror.  (We are
448 dnl assuming here that there is no compiler that groks -mtls-dialect=gnu2
449 dnl but does not grok -Werror.)
450 save_CFLAGS="$CFLAGS"
451 CFLAGS="$CFLAGS -Werror -fpic -mtls-dialect=gnu2"
452 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
453 __thread int i;
454 void foo (void)
456   i = 10;
458 ])], [have_tls_gnu2=yes], [have_tls_gnu2=no])
459 CFLAGS="$save_CFLAGS"
460 AM_CONDITIONAL(TLS_GNU2_DIALECT, test "$have_tls_gnu2" = "yes")
462 dnl On GNU/Linux TLS descriptors are supported by the dynamic loader
463 dnl only with glibc 2.9 or later.
464 AC_CACHE_CHECK([for glibc >= 2.9], [gold_cv_lib_glibc29],
465 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([
466 #include <features.h>
467 #if !defined __GLIBC__
468 error
469 #elif __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 9)
470 error
471 #endif
472 ])], [gold_cv_lib_glibc29=yes], [gold_cv_lib_glibc29=no])])
474 AM_CONDITIONAL(TLS_DESCRIPTORS, test "$gold_cv_lib_glibc29" = "yes")
476 dnl Test for the -frandom-seed option.
477 AC_CACHE_CHECK([for -frandom-seed support], [gold_cv_c_random_seed],
478 [save_CFLAGS="$CFLAGS"
479 CFLAGS="$CFLAGS -frandom-seed=foo"
480 AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], [gold_cv_c_random_seed=yes],
481 [gold_cv_c_random_seed=no])
482 CFLAGS="$save_CFLAGS"])
483 if test "$gold_cv_c_random_seed" = "yes"; then
484   # In Makefile, '$@' will be expanded to be the name of the file
485   # being built, providing a unique seed for each file.
486   RANDOM_SEED_CFLAGS=-frandom-seed=\$@
488 AC_SUBST(RANDOM_SEED_CFLAGS)
490 dnl On GNU/Linux ifunc is supported by the dynamic linker in glibc
491 dnl 2.11 or later, and by binutils 2.20.1 or later.
492 AC_CACHE_CHECK([for glibc ifunc support], [gold_cv_lib_glibc_ifunc],
493 [save_LDFLAGS="$LDFLAGS"
494 LDFLAGS="$LDFLAGS -static"
495 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
496 #include <features.h>
497 #if !defined __GLIBC__
498 error
499 #elif __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 11)
500 error
501 #endif
502 void func (void) { }
503 void invoke (void);
504 __asm__(".type invoke, %gnu_indirect_function");
505 typedef void (*funcptr) (void);
506 funcptr dispatch (void) __asm__ ("invoke");
507 funcptr dispatch (void) { return &func; }]],
508 [[invoke();]])
509 ], [
510 if ${NM} conftest$EXEEXT | grep "__rela\?_iplt_start" >/dev/null 2>&1; then
511   gold_cv_lib_glibc_ifunc=both
512 else
513   gold_cv_lib_glibc_ifunc=dyn
514 fi], [gold_cv_lib_glibc_ifunc=no])
515 LDFLAGS="$save_LDFLAGS"])
517 AM_CONDITIONAL(IFUNC, test "$gold_cv_lib_glibc_ifunc" != "no")
518 AM_CONDITIONAL(IFUNC_STATIC, test "$gold_cv_lib_glibc_ifunc" = "both")
520 AM_BINUTILS_WARNINGS
522 WARN_CXXFLAGS=`echo ${WARN_CFLAGS} | sed -e 's/-Wstrict-prototypes//' -e 's/-Wmissing-prototypes//' -e 's/-Wshadow//'`
523 AC_SUBST(WARN_CXXFLAGS)
525 AC_ARG_WITH(gold-ldflags,
526 [  --with-gold-ldflags=FLAGS  additional link flags for gold],
527 [if test "$withval" = "no" -o "$withval" = "yes"; then
528    GOLD_LDFLAGS=
529  else
530    GOLD_LDFLAGS=$withval
531  fi],
532 [GOLD_LDFLAGS=])
533 AC_SUBST(GOLD_LDFLAGS)
535 AC_ARG_WITH(gold-ldadd,
536 [  --with-gold-ldadd=LIBS     additional libraries for gold],
537 [if test "$withval" = "no" -o "$withval" = "yes"; then
538    GOLD_LDADD=
539  else
540    GOLD_LDADD=$withval
541  fi],
542 [GOLD_LDADD=])
543 AC_SUBST(GOLD_LDADD)
545 dnl Force support for large files by default.  This may need to be
546 dnl host dependent.  If build == host, we can check getconf LFS_CFLAGS.
547 LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
548 AC_SUBST(LFS_CFLAGS)
550 AC_CHECK_HEADERS(sys/mman.h)
551 AC_CHECK_FUNCS(chsize mmap link)
552 AC_REPLACE_FUNCS(pread ftruncate ffsll)
554 AC_CACHE_CHECK([mremap with MREMAP_MAYMOVE], [gold_cv_lib_mremap_maymove],
555 [AC_LINK_IFELSE([
556 AC_LANG_PROGRAM([[
557 #include <sys/mman.h>
558 void f() { mremap (0, 0, 0, MREMAP_MAYMOVE); }
559 ]])], [gold_cv_lib_mremap_maymove=yes], [gold_cv_lib_mremap_maymove=no])])
560 if test "$gold_cv_lib_mremap_maymove" = "yes"; then
561   AC_DEFINE(HAVE_MREMAP, 1,
562     [Define to 1 if you have the mremap function with MREMAP_MAYMOVE support])
563 else
564   AC_LIBOBJ(mremap)
567 # Link in zlib/zstd if we can.  This allows us to write compressed sections.
568 AM_ZLIB
569 AC_ZSTD
570 AM_CONDITIONAL(HAVE_ZSTD, test "$pkg_cv_ZSTD_LIBS" != "")
572 AC_ARG_ENABLE([threads],
573 [[  --enable-threads[=ARG]  multi-threaded linking [ARG={auto,yes,no}]]],
574 [case "${enableval}" in
575   yes | "") threads=yes ;;
576   no) threads=no ;;
577   auto) threads=auto ;;
578   *) threads=yes ;;
579  esac],
580 [threads=auto])
582 if test "$threads" = "yes"; then
583   AX_PTHREAD([threads=yes], AC_MSG_ERROR([pthread not found]))
584 elif test "$threads" = "auto"; then
585   AX_PTHREAD([threads=yes], [threads=no])
588 if test "$threads" = "yes"; then
589   AC_DEFINE(ENABLE_THREADS, 1,
590             [Define to do multi-threaded linking])
592 AM_CONDITIONAL(THREADS, test "$threads" = "yes")
594 # Used to validate --package-metadata= input. Disabled by default.
595 AC_ARG_ENABLE([jansson],
596   [AS_HELP_STRING([--enable-jansson],
597     [enable jansson [default=no]])],
598   [enable_jansson=$enableval],
599   [enable_jansson="no"])
601 if test "x$enable_jansson" != "xno"; then
602   PKG_PROG_PKG_CONFIG
603   AS_IF([test -n "$PKG_CONFIG"],
604     [
605       PKG_CHECK_MODULES(JANSSON, [jansson],
606         [
607           AC_DEFINE(HAVE_JANSSON, 1, [The jansson library is to be used])
608           AC_SUBST([JANSSON_CFLAGS])
609           AC_SUBST([JANSSON_LIBS])
610         ],
611         [
612           AC_MSG_ERROR([Cannot find jansson library])
613         ])
614     ],
615     [
616       AC_MSG_ERROR([Cannot find pkg-config])
617     ])
620 dnl We have to check these in C, not C++, because autoconf generates
621 dnl tests which have no type information, and current glibc provides
622 dnl multiple declarations of functions like basename when compiling
623 dnl with C++.
624 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp])
626 dnl Check if gcc supports the -gpubnames option.
627 dnl Use -Werror in case of compilers that make unknown -g options warnings.
628 dnl They would pass the test here, but fail in actual use when $WARN_CFLAGS
629 dnl gets set later by default Autoconf magic to include -Werror.  (We are
630 dnl assuming here that there is no compiler that groks -gpubnames
631 dnl but does not grok -Werror.)
632 save_CFLAGS="$CFLAGS"
633 CFLAGS="$CFLAGS -Werror -gpubnames"
634 AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], [have_pubnames=yes], [have_pubnames=no])
635 CFLAGS="$save_CFLAGS"
636 AM_CONDITIONAL(HAVE_PUBNAMES, test "$have_pubnames" = "yes")
638 dnl Check if gcc supports the -fno-use-linker-plugin option.
639 save_CFLAGS="$CFLAGS"
640 CFLAGS="$CFLAGS -Werror -fno-use-linker-plugin"
641 AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], [have_no_use_linker_plugin=yes], [have_no_use_linker_plugin=no])
642 CFLAGS="$save_CFLAGS"
643 AM_CONDITIONAL(HAVE_NO_USE_LINKER_PLUGIN, test "$have_no_use_linker_plugin" = "yes")
645 AC_LANG_PUSH(C++)
647 AC_CHECK_HEADERS(unordered_set unordered_map)
648 AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
649 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
650 AC_CHECK_HEADERS(byteswap.h)
652 dnl Check for bswap_{16,32,64}
653 AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]])
655 dnl When plugins enabled dynamic loader interface is required. Check headers
656 dnl which may provide this interface. Add the necessary library to link.
657 AC_CHECK_HEADERS(windows.h)
658 AC_CHECK_HEADERS(dlfcn.h)
659 AC_SEARCH_LIBS(dlopen, [dl dld])
660 case "$ac_cv_search_dlopen" in
661   no*) DLOPEN_LIBS="";;
662   *)   DLOPEN_LIBS="$ac_cv_search_dlopen";;
663 esac
664 AC_SUBST(DLOPEN_LIBS)
666 AC_CHECK_FUNCS(mallinfo mallinfo2 posix_fallocate fallocate readv sysconf times mkdtemp)
667 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
669 # Use of ::std::tr1::unordered_map::rehash causes undefined symbols
670 # at link time with some versions of GCC.
671 AC_CACHE_CHECK([whether ::std::tr1::unordered_map::rehash is usable.],
672 [gold_cv_unordered_map_rehash],
673 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
674 #include <tr1/unordered_map>
675 void bar() { ::std::tr1::unordered_map<int, int> x; x.rehash(10); }
676 ]])], [gold_cv_unordered_map_rehash=yes], [gold_cv_unordered_map_rehash=no])])
677 if test "$gold_cv_unordered_map_rehash" = "yes"; then
678   AC_DEFINE(HAVE_TR1_UNORDERED_MAP_REHASH, 1,
679             [Define if ::std::tr1::unordered_map::rehash is usable])
682 # Since 5e9091dab8858b25210a91d22fbbbfdee9c969ad gold now requires C++11
683 # So we need to check for it.
684 AX_CXX_COMPILE_STDCXX([11], [], [mandatory])
686 # Use of tr1/unordered_map with off_t as a key is not supported on GCC
687 # 4.1.xx when compiling in 32-bit mode with a 64-bit off_t type.
688 AC_CACHE_CHECK([whether std::tr1::hash<off_t> is defined],
689 [gold_cv_hash_off_t],
690 [CXXFLAGS_hold=$CXXFLAGS
691 CXXFLAGS="$CXXFLAGS $LFS_CFLAGS"
692 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
693 #include <sys/types.h>
694 #include <tr1/unordered_map>
695 std::tr1::hash<off_t> h;
696 ])],
697 [gold_cv_hash_off_t=yes],
698 [gold_cv_hash_off_t=no])
699 CXXFLAGS=$CXXFLAGS_hold])
700 if test "$gold_cv_hash_off_t" = "yes"; then
701    AC_DEFINE(HAVE_TR1_HASH_OFF_T, 1,
702              [Define if std::tr1::hash<off_t> is usable])
705 # gcc 4.3.0 doesn't recognize the printf attribute on a template
706 # function.  Check for that.  This is gcc bug 35546.  This test can
707 # probably be removed after the bug has been fixed for a while.
708 AC_CACHE_CHECK([whether we can use attributes with template functions],
709 [gold_cv_template_attribute],
710 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([
711 template<typename T> extern void foo(const char*, ...)
712   __attribute__ ((__format__ (__printf__, 1, 2)));
713 template<typename T> void foo(const char* format, ...) {}
714 void bar() { foo<int>("%s\n", "foo"); }
715 ])], [gold_cv_template_attribute=yes], [gold_cv_template_attribute=no])])
716 if test "$gold_cv_template_attribute" = "yes"; then
717   AC_DEFINE(HAVE_TEMPLATE_ATTRIBUTES, 1,
718             [Define if attributes work on C++ templates])
721 dnl Check if the system has struct stat::st_mtim.
722 AC_CACHE_CHECK([for struct stat::st_mtim.],
723 [gold_cv_stat_st_mtim],
724 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
725 #include <sys/stat.h>
726 long bar() { struct stat s; return (long)(s.st_mtim.tv_sec + s.st_mtim.tv_sec);}
727 ]])], [gold_cv_stat_st_mtim=yes], [gold_cv_stat_st_mtim=no])])
728 if test "$gold_cv_stat_st_mtim" = "yes"; then
729   AC_DEFINE(HAVE_STAT_ST_MTIM, 1,
730             [Define if struct stat has a field st_mtim with timespec for mtime])
733 AC_LANG_POP(C++)
735 AC_CHECK_HEADERS(locale.h)
736 AC_CHECK_FUNCS(setlocale)
737 AM_LC_MESSAGES
739 AM_MAINTAINER_MODE
741 AC_OUTPUT(Makefile testsuite/Makefile po/Makefile.in:po/Make-in)