Index: gcc/configure.ac =================================================================== --- gcc/configure.ac (revision 145385) +++ gcc/configure.ac (working copy) @@ -3473,6 +3473,41 @@ ;; esac +AC_CACHE_CHECK(linker --build-id support, + gcc_cv_ld_buildid, + [gcc_cv_ld_buildid=no + if test $in_tree_ld = yes ; then + if test "$gcc_cv_gld_major_version" -eq 2 -a \ + "$gcc_cv_gld_minor_version" -ge 18 -o \ + "$gcc_cv_gld_major_version" -gt 2 \ + && test $in_tree_ld_is_elf = yes; then + gcc_cv_ld_buildid=yes + fi + elif test x$gcc_cv_ld != x; then + if $gcc_cv_ld --help 2>/dev/null | grep build-id > /dev/null; then + gcc_cv_ld_buildid=yes + fi + fi]) +if test x"$gcc_cv_ld_buildid" = xyes; then + AC_DEFINE(HAVE_LD_BUILDID, 1, + [Define if your linker supports --build-id.]) +fi + +AC_ARG_ENABLE(linker-build-id, +[ --enable-linker-build-id + compiler will always pass --build-id to linker], +[], +enable_linker_build_id=no) + +if test x"$enable_linker_build_id" = xyes; then + if test x"$gcc_cv_ld_buildid" = xyes; then + AC_DEFINE(ENABLE_LD_BUILDID, 1, + [Define if gcc should always pass --build-id to linker.]) + else + AC_MSG_WARN(--build-id is not supported by your linker; --enable-linker-build-id ignored) + fi +fi + AC_CACHE_CHECK(linker --sysroot support, gcc_cv_ld_sysroot, [gcc_cv_ld_sysroot=no Index: gcc/gcc.c =================================================================== --- gcc/gcc.c (revision 145385) +++ gcc/gcc.c (working copy) @@ -717,6 +717,13 @@ #endif #endif +#ifndef LINK_BUILDID_SPEC +# if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID) +# define LINK_BUILDID_SPEC "%{!r:--build-id} " +# endif +#endif + + /* -u* was put back because both BSD and SysV seem to support it. */ /* %{static:} simply prevents an error message if the target machine doesn't handle -static. */ @@ -1831,9 +1838,16 @@ asm_spec = XOBFINISH (&obstack, const char *); } #endif -#ifdef LINK_EH_SPEC + +#if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC +# ifdef LINK_BUILDID_SPEC + /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */ + obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof(LINK_BUILDID_SPEC) - 1); +# endif +# ifdef LINK_EH_SPEC /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */ obstack_grow (&obstack, LINK_EH_SPEC, sizeof(LINK_EH_SPEC) - 1); +# endif obstack_grow0 (&obstack, link_spec, strlen (link_spec)); link_spec = XOBFINISH (&obstack, const char *); #endif Index: gcc/doc/install.texi =================================================================== --- gcc/doc/install.texi (revision 145385) +++ gcc/doc/install.texi (working copy) @@ -1490,6 +1490,13 @@ building runtime libraries. @samp{@var{map}} is a space-separated list of maps of the form @samp{@var{old}=@var{new}}. +@item --enable-linker-build-id +Tells GCC to pass @option{--build-id} option to the linker for all final +links (links performed without the @option{-r} or @option{--relocatable} +option), if the linker supports it. A warning is issued and the option +is ignored, if you specify @option{--enable-linker-build-id}, but your +linker does not support @option{--build-id} option. The default is off. + @end table @subheading Cross-Compiler-Specific Options Index: gcc/configure =================================================================== --- gcc/configure (revision 145385) +++ gcc/configure (working copy) @@ -1078,6 +1078,8 @@ --enable-fast-install[=PKGS] optimize for fast installation [default=yes] --disable-libtool-lock avoid locking (might break parallel builds) + --enable-linker-build-id + compiler will always pass --build-id to linker --enable-maintainer-mode enable make rules and dependencies not useful (and sometimes confusing) to the casual installer @@ -14348,13 +14350,13 @@ else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext - (eval echo "\"\$as_me:14351: $ac_compile\"" >&5) + (eval echo "\"\$as_me:14353: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 - (eval echo "\"\$as_me:14354: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval echo "\"\$as_me:14356: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 - (eval echo "\"\$as_me:14357: output\"" >&5) + (eval echo "\"\$as_me:14359: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" @@ -15511,7 +15513,7 @@ ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 15514 "configure"' > conftest.$ac_ext + echo '#line 15516 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -16810,11 +16812,11 @@ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:16813: $lt_compile\"" >&5) + (eval echo "\"\$as_me:16815: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:16817: \$? = $ac_status" >&5 + echo "$as_me:16819: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -17149,11 +17151,11 @@ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:17152: $lt_compile\"" >&5) + (eval echo "\"\$as_me:17154: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:17156: \$? = $ac_status" >&5 + echo "$as_me:17158: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -17254,11 +17256,11 @@ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:17257: $lt_compile\"" >&5) + (eval echo "\"\$as_me:17259: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:17261: \$? = $ac_status" >&5 + echo "$as_me:17263: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -17309,11 +17311,11 @@ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:17312: $lt_compile\"" >&5) + (eval echo "\"\$as_me:17314: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:17316: \$? = $ac_status" >&5 + echo "$as_me:17318: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -20121,7 +20123,7 @@ lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 20124 "configure" +#line 20126 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -20217,7 +20219,7 @@ lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 20220 "configure" +#line 20222 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -24053,6 +24055,56 @@ ;; esac +echo "$as_me:$LINENO: checking linker --build-id support" >&5 +echo $ECHO_N "checking linker --build-id support... $ECHO_C" >&6 +if test "${gcc_cv_ld_buildid+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + gcc_cv_ld_buildid=no + if test $in_tree_ld = yes ; then + if test "$gcc_cv_gld_major_version" -eq 2 -a \ + "$gcc_cv_gld_minor_version" -ge 18 -o \ + "$gcc_cv_gld_major_version" -gt 2 \ + && test $in_tree_ld_is_elf = yes; then + gcc_cv_ld_buildid=yes + fi + elif test x$gcc_cv_ld != x; then + if $gcc_cv_ld --help 2>/dev/null | grep build-id > /dev/null; then + gcc_cv_ld_buildid=yes + fi + fi +fi +echo "$as_me:$LINENO: result: $gcc_cv_ld_buildid" >&5 +echo "${ECHO_T}$gcc_cv_ld_buildid" >&6 +if test x"$gcc_cv_ld_buildid" = xyes; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_LD_BUILDID 1 +_ACEOF + +fi + +# Check whether --enable-linker-build-id or --disable-linker-build-id was given. +if test "${enable_linker_build_id+set}" = set; then + enableval="$enable_linker_build_id" + +else + enable_linker_build_id=no +fi; + +if test x"$enable_linker_build_id" = xyes; then + if test x"$gcc_cv_ld_buildid" = xyes; then + +cat >>confdefs.h <<\_ACEOF +#define ENABLE_LD_BUILDID 1 +_ACEOF + + else + { echo "$as_me:$LINENO: WARNING: --build-id is not supported by your linker; --enable-linker-build-id ignored" >&5 +echo "$as_me: WARNING: --build-id is not supported by your linker; --enable-linker-build-id ignored" >&2;} + fi +fi + echo "$as_me:$LINENO: checking linker --sysroot support" >&5 echo $ECHO_N "checking linker --sysroot support... $ECHO_C" >&6 if test "${gcc_cv_ld_sysroot+set}" = set; then Index: gcc/config.in =================================================================== --- gcc/config.in (revision 145385) +++ gcc/config.in (working copy) @@ -101,6 +101,12 @@ #endif +/* Define if gcc should always pass --build-id to linker. */ +#ifndef USED_FOR_TARGET +#undef ENABLE_LD_BUILDID +#endif + + /* Define to 1 if translation of program messages to the user's native language is requested. */ #ifndef USED_FOR_TARGET @@ -1013,6 +1019,12 @@ #endif +/* Define if your linker supports --build-id. */ +#ifndef USED_FOR_TARGET +#undef HAVE_LD_BUILDID +#endif + + /* Define if your linker supports --demangle option. */ #ifndef USED_FOR_TARGET #undef HAVE_LD_DEMANGLE