1dnl Process this file with autoconf to produce a configure script.
2dnl
3dnl   Copyright (C) 2006-2024 Free Software Foundation, Inc.
4dnl
5dnl This file is free software; you can redistribute it and/or modify
6dnl it under the terms of the GNU General Public License as published by
7dnl the Free Software Foundation; either version 3 of the License, or
8dnl (at your option) any later version.
9dnl
10dnl This program is distributed in the hope that it will be useful,
11dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13dnl GNU General Public License for more details.
14dnl
15dnl You should have received a copy of the GNU General Public License
16dnl along with this program; see the file COPYING3.  If not see
17dnl <http://www.gnu.org/licenses/>.
18dnl
19
20AC_INIT(gold, 0.1)
21AC_CONFIG_SRCDIR(gold.cc)
22
23AC_CANONICAL_TARGET
24
25AM_INIT_AUTOMAKE([no-dist parallel-tests])
26AM_SILENT_RULES([yes])
27
28AM_CONFIG_HEADER(config.h:config.in)
29
30AC_USE_SYSTEM_EXTENSIONS
31
32# PR 14072
33AH_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])
40
41AC_ARG_WITH(sysroot,
42[  --with-sysroot[=DIR]    search for usr/lib et al within DIR],
43[sysroot=$withval], [sysroot=no])
44
45if test "$sysroot" = "yes"; then
46  sysroot='${exec_prefix}/${target_alias}/sys-root'
47elif test "$sysroot" = "no"; then
48  sysroot=
49fi
50
51sysroot_relocatable=0
52if 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
61fi
62
63AC_DEFINE_UNQUOTED(TARGET_SYSTEM_ROOT, "$sysroot",
64  [System root for target files])
65AC_DEFINE_UNQUOTED(TARGET_SYSTEM_ROOT_RELOCATABLE, $sysroot_relocatable,
66  [Whether the system root can be relocated])
67
68dnl "install_as_default" is true if the linker to be installed as the
69dnl default linker, ld.
70dnl "installed_linker" is the installed gold linker name.
71
72installed_linker=ld.gold
73AC_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])
86AC_SUBST(install_as_default)
87AC_SUBST(installed_linker)
88
89AC_PLUGINS
90if test "$plugins" = "yes"; then
91  AC_DEFINE(ENABLE_PLUGINS, 1,
92	    [Define to enable linker plugins])
93fi
94AM_CONDITIONAL(PLUGINS, test "$plugins" = "yes")
95
96# Decide if -z relro should be enabled in ELF linker by default.
97ac_default_ld_z_relro=unset
98# Provide a configure time option to override our default.
99AC_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 ;;
105esac])dnl
106if test "${ac_default_ld_z_relro}" = unset; then
107  ac_default_ld_z_relro=1
108fi
109AC_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.])
112
113AC_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    ;;
125esac],
126[# For now, enable all targets by default
127 enable_targets=all
128])
129
130# Canonicalize the enabled targets.
131if 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
141fi
142
143# Decide which "--hash-style" to use by default
144# Provide a configure time option to override our default.
145AC_ARG_ENABLE([default-hash-style],
146AS_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]) ;;
151esac],
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 ;;
157esac])
158
159AC_DEFINE_UNQUOTED([DEFAULT_HASH_STYLE],
160  ["${enable_default_hash_style}"],
161  [Set the default --hash-style value])
162
163# See which specific instantiations we need.
164targetobjs=
165all_targets=
166default_machine=
167default_size=
168default_big_endian=
169default_osabi=ELFOSABI_NONE
170targ_32_little=
171targ_32_big=
172targ_64_little=
173targ_64_big=
174for 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
183
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
211
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
217
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
248done
249
250# Remove any duplicates.
251to=""
252for t in $targetobjs; do
253  case " $to " in
254  *" $t "*) ;;
255  *) to="$to $t" ;;
256  esac
257done
258targetobjs=$to
259
260if test -n "$targ_32_little"; then
261  AC_DEFINE(HAVE_TARGET_32_LITTLE, 1,
262	      [Define to support 32-bit little-endian targets])
263fi
264if test -n "$targ_32_big"; then
265  AC_DEFINE(HAVE_TARGET_32_BIG, 1,
266	      [Define to support 32-bit big-endian targets])
267fi
268if test -n "$targ_64_little"; then
269  AC_DEFINE(HAVE_TARGET_64_LITTLE, 1,
270	      [Define to support 64-bit little-endian targets])
271fi
272if test -n "$targ_64_big"; then
273  AC_DEFINE(HAVE_TARGET_64_BIG, 1,
274	      [Define to support 64-bit big-endian targets])
275fi
276
277if test -n "$all_targets"; then
278  TARGETOBJS='$(ALL_TARGETOBJS)'
279else
280  TARGETOBJS="$targetobjs"
281fi
282AC_SUBST(TARGETOBJS)
283
284AC_DEFINE_UNQUOTED(GOLD_DEFAULT_MACHINE, $default_machine,
285		   [Default machine code])
286AC_DEFINE_UNQUOTED(GOLD_DEFAULT_SIZE, $default_size,
287		   [Default size (32 or 64)])
288AC_DEFINE_UNQUOTED(GOLD_DEFAULT_BIG_ENDIAN, $default_big_endian,
289		   [Default big endian (true or false)])
290AC_DEFINE_UNQUOTED(GOLD_DEFAULT_OSABI, $default_osabi,
291		   [Default OSABI code])
292
293AC_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::"'])
301AC_DEFINE_UNQUOTED(LIB_PATH, $LIB_PATH,
302		   [Default library search path])
303if 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])
305fi
306
307AC_CHECK_TOOL(NM, nm)
308
309AC_PROG_CC
310AC_PROG_CXX
311AC_PROG_YACC
312AC_PROG_RANLIB
313AC_PROG_INSTALL
314AC_PROG_LN_S
315
316AC_GNU_SOURCE
317
318ZW_GNU_GETTEXT_SISTER_DIR
319AM_PO_SUBDIRS
320
321AC_C_BIGENDIAN
322
323AC_EXEEXT
324
325AM_CONDITIONAL(NATIVE_LINKER,
326  test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias")
327AM_CONDITIONAL(GCC, test "$GCC" = yes)
328
329AM_CONDITIONAL(NATIVE_OR_CROSS_LINKER,
330  test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias" -o "x$host_alias" = "x$build_alias")
331
332dnl Test for whether static linking is supported.  Some systems do not
333dnl install static libraries.  This only affects the set of tests that
334dnl we run.
335AC_CACHE_CHECK([whether static linking works], [gold_cv_lib_static],
336[LDFLAGS_hold=$LDFLAGS
337LDFLAGS="$LDFLAGS -static"
338AC_LINK_IFELSE([
339AC_LANG_PROGRAM([[void f() { }]])],
340[gold_cv_lib_static=yes], [gold_cv_lib_static=no])
341LDFLAGS=$LDFLAGS_hold])
342AM_CONDITIONAL(HAVE_STATIC, test "$gold_cv_lib_static" = "yes")
343
344dnl Some architectures do not support taking pointers of functions
345dnl defined in shared libraries except in -fPIC mode.  We need to
346dnl tell the unittest framework if we're compiling for one of those
347dnl targets, so it doesn't try to run the tests that do that.
348AM_CONDITIONAL(FN_PTRS_IN_SO_WITHOUT_PIC, [
349  case $target_cpu in
350    powerpc*) false;;
351    x86_64) false;;
352    sparc64) false;;
353    s390x) false;;
354    *) true;;
355  esac])
356
357dnl Test for gcc 4.1 or later.  Full support for -mcmodel=medium is
358dnl only available in gcc 4.1.
359AC_CACHE_CHECK([for gcc >= 4.1], [gold_cv_prog_gcc41],
360[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
361#if !defined __GNUC__
362error
363#elif __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1)
364error
365#endif
366])], [gold_cv_prog_gcc41=yes], [gold_cv_prog_gcc41=no])])
367
368save_CFLAGS="$CFLAGS"
369CFLAGS="$CFLAGS -mcmodel=medium"
370AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], [have_mcmodel_medium=yes], [have_mcmodel_medium=no])
371CFLAGS="$save_CFLAGS"
372dnl Whether we can test -mcmodel=medium.
373AM_CONDITIONAL(MCMODEL_MEDIUM,
374[test "$target_cpu" = "x86_64" -a "$have_mcmodel_medium" = "yes" -a "$gold_cv_prog_gcc41" = "yes"])
375
376dnl Test for gcc 9 or later.  Some incremental tests fail with GCC 9 or
377dnl later.
378AC_CACHE_CHECK([for gcc >= 9], [gold_cv_prog_gcc9],
379[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
380#if !defined __GNUC__ || __GNUC__ < 9
381error
382#endif
383])], [gold_cv_prog_gcc9=yes], [gold_cv_prog_gcc9=no])])
384AM_CONDITIONAL(GCC9, [test "$gold_cv_prog_gcc9" = "yes"])
385
386dnl Test for -fcf-protection on x86-64.  Some incremental tests fail with
387dnl -fcf-protection.
388AC_CACHE_CHECK([for -fcf-protection], [gold_cv_cflags_cf_protection],
389[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
390#if !defined __x86_64__ || !defined __CET__
391error
392#endif
393])], [gold_cv_cflags_cf_protection=yes], [gold_cv_cflags_cf_protection=no])])
394AM_CONDITIONAL(CFLAGS_CF_PROTECTION, [test "$gold_cv_cflags_cf_protection" = "yes"])
395
396AC_CACHE_CHECK([whether $CC supports -fmerge-constants],
397	       [gold_cv_merge_constants], [
398save_CFLAGS="$CFLAGS"
399CFLAGS="$CFLAGS -fmerge-constants"
400AC_COMPILE_IFELSE([AC_LANG_SOURCE([const char *s = "foo";])],
401		  [gold_cv_merge_constants=yes],
402		  [gold_cv_merge_constants=no])
403CFLAGS="$save_CFLAGS"])
404AC_SUBST([MERGE_CONSTANTS_FLAG])
405AS_IF([test "$gold_cv_merge_constants" = yes],
406      [MERGE_CONSTANTS_FLAG=-fmerge-constants],
407      [MERGE_CONSTANTS_FLAG=])
408
409dnl Test for __thread support.
410AC_CACHE_CHECK([for thread support], [gold_cv_c_thread],
411[AC_COMPILE_IFELSE([AC_LANG_SOURCE([__thread int i = 1;])],
412[gold_cv_c_thread=yes], [gold_cv_c_thread=no])])
413
414AM_CONDITIONAL(TLS, test "$gold_cv_c_thread" = "yes")
415
416dnl On GNU/Linux TLS in static programs only works when using glibc
417dnl 2.4 or later.
418AC_CACHE_CHECK([for glibc >= 2.4], [gold_cv_lib_glibc24],
419[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
420#include <features.h>
421#if !defined __GLIBC__
422error
423#elif __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4)
424error
425#endif
426])], [gold_cv_lib_glibc24=yes], [gold_cv_lib_glibc24=no])])
427
428AM_CONDITIONAL(STATIC_TLS, test "$gold_cv_lib_glibc24" = "yes")
429
430dnl Test for #pragma omp threadprivate
431AC_CACHE_CHECK([for omp support], [gold_cv_c_threadprivate],
432[save_CFLAGS="$CFLAGS"
433CFLAGS="$CFLAGS -fopenmp"
434AC_COMPILE_IFELSE([AC_LANG_SOURCE([
435#include <omp.h>
436int i;
437#pragma omp threadprivate (i)
438])], [gold_cv_c_threadprivate=yes], [gold_cv_c_threadprivate=no])
439CFLAGS="$save_CFLAGS"])
440if test "$gold_cv_c_threadprivate" = "yes"; then
441  AC_DEFINE(HAVE_OMP_SUPPORT, 1,
442	    [Define if compiler supports #pragma omp threadprivate])
443fi
444AM_CONDITIONAL(OMP_SUPPORT, test "$gold_cv_c_threadprivate" = "yes")
445
446dnl Test for the -ftls-dialect=gnu2 option.
447dnl Use -Werror in case of compilers that make unknown -m options warnings.
448dnl They would pass the test here, but fail in actual use when $WARN_CFLAGS
449dnl gets set later by default Autoconf magic to include -Werror.  (We are
450dnl assuming here that there is no compiler that groks -mtls-dialect=gnu2
451dnl but does not grok -Werror.)
452save_CFLAGS="$CFLAGS"
453CFLAGS="$CFLAGS -Werror -fpic -mtls-dialect=gnu2"
454AC_COMPILE_IFELSE([AC_LANG_SOURCE([
455__thread int i;
456void foo (void)
457{
458  i = 10;
459}
460])], [have_tls_gnu2=yes], [have_tls_gnu2=no])
461CFLAGS="$save_CFLAGS"
462AM_CONDITIONAL(TLS_GNU2_DIALECT, test "$have_tls_gnu2" = "yes")
463
464dnl On GNU/Linux TLS descriptors are supported by the dynamic loader
465dnl only with glibc 2.9 or later.
466AC_CACHE_CHECK([for glibc >= 2.9], [gold_cv_lib_glibc29],
467[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
468#include <features.h>
469#if !defined __GLIBC__
470error
471#elif __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 9)
472error
473#endif
474])], [gold_cv_lib_glibc29=yes], [gold_cv_lib_glibc29=no])])
475
476AM_CONDITIONAL(TLS_DESCRIPTORS, test "$gold_cv_lib_glibc29" = "yes")
477
478dnl Test for the -frandom-seed option.
479AC_CACHE_CHECK([for -frandom-seed support], [gold_cv_c_random_seed],
480[save_CFLAGS="$CFLAGS"
481CFLAGS="$CFLAGS -frandom-seed=foo"
482AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], [gold_cv_c_random_seed=yes],
483[gold_cv_c_random_seed=no])
484CFLAGS="$save_CFLAGS"])
485if test "$gold_cv_c_random_seed" = "yes"; then
486  # In Makefile, '$@' will be expanded to be the name of the file
487  # being built, providing a unique seed for each file.
488  RANDOM_SEED_CFLAGS=-frandom-seed=\$@
489fi
490AC_SUBST(RANDOM_SEED_CFLAGS)
491
492dnl On GNU/Linux ifunc is supported by the dynamic linker in glibc
493dnl 2.11 or later, and by binutils 2.20.1 or later.
494AC_CACHE_CHECK([for glibc ifunc support], [gold_cv_lib_glibc_ifunc],
495[save_LDFLAGS="$LDFLAGS"
496LDFLAGS="$LDFLAGS -static"
497AC_LINK_IFELSE([AC_LANG_PROGRAM([[
498#include <features.h>
499#if !defined __GLIBC__
500error
501#elif __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 11)
502error
503#endif
504void func (void) { }
505void invoke (void);
506__asm__(".type invoke, %gnu_indirect_function");
507typedef void (*funcptr) (void);
508funcptr dispatch (void) __asm__ ("invoke");
509funcptr dispatch (void) { return &func; }]],
510[[invoke();]])
511], [
512if ${NM} conftest$EXEEXT | grep "__rela\?_iplt_start" >/dev/null 2>&1; then
513  gold_cv_lib_glibc_ifunc=both
514else
515  gold_cv_lib_glibc_ifunc=dyn
516fi], [gold_cv_lib_glibc_ifunc=no])
517LDFLAGS="$save_LDFLAGS"])
518
519AM_CONDITIONAL(IFUNC, test "$gold_cv_lib_glibc_ifunc" != "no")
520AM_CONDITIONAL(IFUNC_STATIC, test "$gold_cv_lib_glibc_ifunc" = "both")
521
522AM_BINUTILS_WARNINGS
523
524WARN_CXXFLAGS=`echo ${WARN_CFLAGS} | sed -e 's/-Wstrict-prototypes//' -e 's/-Wmissing-prototypes//' -e 's/-Wshadow//'`
525AC_SUBST(WARN_CXXFLAGS)
526
527AC_ARG_WITH(gold-ldflags,
528[  --with-gold-ldflags=FLAGS  additional link flags for gold],
529[if test "$withval" = "no" -o "$withval" = "yes"; then
530   GOLD_LDFLAGS=
531 else
532   GOLD_LDFLAGS=$withval
533 fi],
534[GOLD_LDFLAGS=])
535AC_SUBST(GOLD_LDFLAGS)
536
537AC_ARG_WITH(gold-ldadd,
538[  --with-gold-ldadd=LIBS     additional libraries for gold],
539[if test "$withval" = "no" -o "$withval" = "yes"; then
540   GOLD_LDADD=
541 else
542   GOLD_LDADD=$withval
543 fi],
544[GOLD_LDADD=])
545AC_SUBST(GOLD_LDADD)
546
547dnl Force support for large files by default.  This may need to be
548dnl host dependent.  If build == host, we can check getconf LFS_CFLAGS.
549LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
550AC_SUBST(LFS_CFLAGS)
551
552AC_CHECK_HEADERS(sys/mman.h)
553AC_CHECK_FUNCS(chsize mmap link)
554AC_REPLACE_FUNCS(pread ftruncate ffsll)
555
556AC_CACHE_CHECK([mremap with MREMAP_MAYMOVE], [gold_cv_lib_mremap_maymove],
557[AC_LINK_IFELSE([
558AC_LANG_PROGRAM([[
559#include <sys/mman.h>
560void f() { mremap (0, 0, 0, MREMAP_MAYMOVE); }
561]])], [gold_cv_lib_mremap_maymove=yes], [gold_cv_lib_mremap_maymove=no])])
562if test "$gold_cv_lib_mremap_maymove" = "yes"; then
563  AC_DEFINE(HAVE_MREMAP, 1,
564    [Define to 1 if you have the mremap function with MREMAP_MAYMOVE support])
565else
566  AC_LIBOBJ(mremap)
567fi
568
569# Link in zlib/zstd if we can.  This allows us to write compressed sections.
570AM_ZLIB
571AC_ZSTD
572AM_CONDITIONAL(HAVE_ZSTD, test "$pkg_cv_ZSTD_LIBS" != "")
573
574AC_ARG_ENABLE([threads],
575[[  --enable-threads[=ARG]  multi-threaded linking [ARG={auto,yes,no}]]],
576[case "${enableval}" in
577  yes | "") threads=yes ;;
578  no) threads=no ;;
579  auto) threads=auto ;;
580  *) threads=yes ;;
581 esac],
582[threads=auto])
583
584if test "$threads" = "yes"; then
585  AX_PTHREAD([threads=yes], AC_MSG_ERROR([pthread not found]))
586elif test "$threads" = "auto"; then
587  AX_PTHREAD([threads=yes], [threads=no])
588fi
589
590if test "$threads" = "yes"; then
591  AC_DEFINE(ENABLE_THREADS, 1,
592	    [Define to do multi-threaded linking])
593fi
594AM_CONDITIONAL(THREADS, test "$threads" = "yes")
595
596# Used to validate --package-metadata= input. Disabled by default.
597AC_ARG_ENABLE([jansson],
598  [AS_HELP_STRING([--enable-jansson],
599    [enable jansson [default=no]])],
600  [enable_jansson=$enableval],
601  [enable_jansson="no"])
602
603if test "x$enable_jansson" != "xno"; then
604  PKG_PROG_PKG_CONFIG
605  AS_IF([test -n "$PKG_CONFIG"],
606    [
607      PKG_CHECK_MODULES(JANSSON, [jansson],
608	[
609	  AC_DEFINE(HAVE_JANSSON, 1, [The jansson library is to be used])
610	  AC_SUBST([JANSSON_CFLAGS])
611	  AC_SUBST([JANSSON_LIBS])
612	],
613	[
614	  AC_MSG_ERROR([Cannot find jansson library])
615	])
616    ],
617    [
618      AC_MSG_ERROR([Cannot find pkg-config])
619    ])
620fi
621
622dnl We have to check these in C, not C++, because autoconf generates
623dnl tests which have no type information, and current glibc provides
624dnl multiple declarations of functions like basename when compiling
625dnl with C++.
626AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp])
627
628dnl Check if gcc supports the -gpubnames option.
629dnl Use -Werror in case of compilers that make unknown -g options warnings.
630dnl They would pass the test here, but fail in actual use when $WARN_CFLAGS
631dnl gets set later by default Autoconf magic to include -Werror.  (We are
632dnl assuming here that there is no compiler that groks -gpubnames
633dnl but does not grok -Werror.)
634save_CFLAGS="$CFLAGS"
635CFLAGS="$CFLAGS -Werror -gpubnames"
636AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], [have_pubnames=yes], [have_pubnames=no])
637CFLAGS="$save_CFLAGS"
638AM_CONDITIONAL(HAVE_PUBNAMES, test "$have_pubnames" = "yes")
639
640dnl Check if gcc supports the -fno-use-linker-plugin option.
641save_CFLAGS="$CFLAGS"
642CFLAGS="$CFLAGS -Werror -fno-use-linker-plugin"
643AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], [have_no_use_linker_plugin=yes], [have_no_use_linker_plugin=no])
644CFLAGS="$save_CFLAGS"
645AM_CONDITIONAL(HAVE_NO_USE_LINKER_PLUGIN, test "$have_no_use_linker_plugin" = "yes")
646
647AC_LANG_PUSH(C++)
648
649AC_CHECK_HEADERS(unordered_set unordered_map)
650AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
651AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
652AC_CHECK_HEADERS(byteswap.h)
653
654dnl Check for bswap_{16,32,64}
655AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]])
656
657dnl When plugins enabled dynamic loader interface is required. Check headers
658dnl which may provide this interface. Add the necessary library to link.
659AC_CHECK_HEADERS(windows.h)
660AC_CHECK_HEADERS(dlfcn.h)
661AC_SEARCH_LIBS(dlopen, [dl dld])
662case "$ac_cv_search_dlopen" in
663  no*) DLOPEN_LIBS="";;
664  *)   DLOPEN_LIBS="$ac_cv_search_dlopen";;
665esac
666AC_SUBST(DLOPEN_LIBS)
667
668AC_CHECK_FUNCS(mallinfo mallinfo2 posix_fallocate fallocate readv sysconf times mkdtemp)
669AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
670
671# Use of ::std::tr1::unordered_map::rehash causes undefined symbols
672# at link time with some versions of GCC.
673AC_CACHE_CHECK([whether ::std::tr1::unordered_map::rehash is usable.],
674[gold_cv_unordered_map_rehash],
675[AC_LINK_IFELSE([AC_LANG_PROGRAM([[
676#include <tr1/unordered_map>
677void bar() { ::std::tr1::unordered_map<int, int> x; x.rehash(10); }
678]])], [gold_cv_unordered_map_rehash=yes], [gold_cv_unordered_map_rehash=no])])
679if test "$gold_cv_unordered_map_rehash" = "yes"; then
680  AC_DEFINE(HAVE_TR1_UNORDERED_MAP_REHASH, 1,
681	    [Define if ::std::tr1::unordered_map::rehash is usable])
682fi
683
684# Since 5e9091dab8858b25210a91d22fbbbfdee9c969ad gold now requires C++11
685# So we need to check for it.
686AX_CXX_COMPILE_STDCXX([11], [], [mandatory])
687
688# Use of tr1/unordered_map with off_t as a key is not supported on GCC
689# 4.1.xx when compiling in 32-bit mode with a 64-bit off_t type.
690AC_CACHE_CHECK([whether std::tr1::hash<off_t> is defined],
691[gold_cv_hash_off_t],
692[CXXFLAGS_hold=$CXXFLAGS
693CXXFLAGS="$CXXFLAGS $LFS_CFLAGS"
694AC_COMPILE_IFELSE([AC_LANG_SOURCE([
695#include <sys/types.h>
696#include <tr1/unordered_map>
697std::tr1::hash<off_t> h;
698])],
699[gold_cv_hash_off_t=yes],
700[gold_cv_hash_off_t=no])
701CXXFLAGS=$CXXFLAGS_hold])
702if test "$gold_cv_hash_off_t" = "yes"; then
703   AC_DEFINE(HAVE_TR1_HASH_OFF_T, 1,
704	     [Define if std::tr1::hash<off_t> is usable])
705fi
706
707# gcc 4.3.0 doesn't recognize the printf attribute on a template
708# function.  Check for that.  This is gcc bug 35546.  This test can
709# probably be removed after the bug has been fixed for a while.
710AC_CACHE_CHECK([whether we can use attributes with template functions],
711[gold_cv_template_attribute],
712[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
713template<typename T> extern void foo(const char*, ...)
714  __attribute__ ((__format__ (__printf__, 1, 2)));
715template<typename T> void foo(const char* format, ...) {}
716void bar() { foo<int>("%s\n", "foo"); }
717])], [gold_cv_template_attribute=yes], [gold_cv_template_attribute=no])])
718if test "$gold_cv_template_attribute" = "yes"; then
719  AC_DEFINE(HAVE_TEMPLATE_ATTRIBUTES, 1,
720	    [Define if attributes work on C++ templates])
721fi
722
723dnl Check if the system has struct stat::st_mtim.
724AC_CACHE_CHECK([for struct stat::st_mtim.],
725[gold_cv_stat_st_mtim],
726[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
727#include <sys/stat.h>
728long bar() { struct stat s; return (long)(s.st_mtim.tv_sec + s.st_mtim.tv_sec);}
729]])], [gold_cv_stat_st_mtim=yes], [gold_cv_stat_st_mtim=no])])
730if test "$gold_cv_stat_st_mtim" = "yes"; then
731  AC_DEFINE(HAVE_STAT_ST_MTIM, 1,
732	    [Define if struct stat has a field st_mtim with timespec for mtime])
733fi
734
735AC_LANG_POP(C++)
736
737AC_CHECK_HEADERS(locale.h)
738AC_CHECK_FUNCS(setlocale)
739AM_LC_MESSAGES
740
741AM_MAINTAINER_MODE
742
743AC_OUTPUT(Makefile testsuite/Makefile po/Makefile.in:po/Make-in)
744