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