This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfc patch] pass --build-id to linker


The --build-id switch is a new GNU ld feature for ELF targets.  Using it
in every final link of an executable or DSO contributes to improving
debuggability.  This will become the new default for all GNU systems, at
least.  I think it is univerally worthwhile, and might as well be the
default for every target where the linker supports it.  There is nothing
especially GNU-specific about it, it just adds a little data in normal
ELF formats.  (I also prefer this to touching all the config/*.h files
required to cover each and every GNU/Linux and GNU/* target, which are
far less unified for the shared details like this than one might hope.)

The most similar example of a linker switch used in similar criteria I
found is --eh-frame-hdr.  So the insertion is modelled on that.
Is this the right way to do it?

Thanks,
Roland


2007-08-14  Roland McGrath  <roland@redhat.com>

	* configure.ac (HAVE_LD_BUILDID): New check for ld --build-id support.
	* gcc.c [HAVE_LD_BUILDID] (LINK_BUILDID_SPEC): New macro.
	(init_spec): If defined, prepend it between LINK_EH_SPEC and link_spec.

Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c	(revision 127405)
+++ gcc/gcc.c	(working copy)
@@ -702,6 +702,13 @@ proper position among the other output f
 #endif
 #endif
 
+#ifndef LINK_BUILDID_SPEC
+# ifdef HAVE_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.  */
@@ -1816,9 +1823,16 @@ init_spec (void)
     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/configure.ac
===================================================================
--- gcc/configure.ac	(revision 127405)
+++ gcc/configure.ac	(working copy)
@@ -3316,6 +3316,27 @@ EOF
     ;;
 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])
+GCC_TARGET_TEMPLATE([HAVE_LD_BUILDID])
+if test x"$gcc_cv_ld_buildid" = xyes; then
+  AC_DEFINE(HAVE_LD_BUILDID, 1,
+  [Define if your linker supports --build-id.])
+fi
+
 AC_CACHE_CHECK(linker --sysroot support,
   gcc_cv_ld_sysroot,
   [gcc_cv_ld_sysroot=no


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]