This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Take advantage of ld --sysroot
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 27 Apr 2005 13:41:47 -0700
- Subject: PATCH: Take advantage of ld --sysroot
- Reply-to: mark at codesourcery dot com
Richard Sandiford added --sysroot support to GNU ld a while back.
This patch (originally developed for csl-arm-branch) makes GCC
automatically pass --sysroot to the linker when that makes sense.
Tested on x86_64-unknonwn-linux-gnu, with a linker that had sysroot
support and one without. Applied on the mainline.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2005-04-27 Mark Mitchell <mark@codesourcery.com>
* configure.ac: Check for ld --sysroot support.
* gcc.c: Document %R specifier for specs.
(SYSROOT_SPEC): New macro.
(sysroot_spec): New variable.
(static_specs): Add sysroot_spec.
(main): Pass the sysroot spec to the linker if appropriate.
* configure: Regenerated.
* config.in: Likewise.
Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/gcc/configure.ac,v
retrieving revision 2.105
diff -c -5 -p -r2.105 configure.ac
*** configure.ac 13 Apr 2005 09:13:27 -0000 2.105
--- configure.ac 27 Apr 2005 20:15:49 -0000
*************** EOF
*** 3022,3031 ****
--- 3022,3048 ----
[Define if your PowerPC64 linker only needs function descriptor syms.])
fi
;;
esac
+ AC_CACHE_CHECK(linker --sysroot support,
+ gcc_cv_ld_sysroot,
+ [gcc_cv_ld_sysroot=no
+ if test $in_tree_ld = yes ; then
+ if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 16 -o "$gcc_cv_gld_major_version" -gt 2 ; then
+ gcc_cv_ld_sysroot = yes
+ fi
+ elif test x$gcc_cv_ld != x; then
+ if $gcc_cv_ld --help 2>/dev/null | grep sysroot > /dev/null; then
+ gcc_cv_ld_sysroot=yes
+ fi
+ fi])
+ if test x"$gcc_cv_ld_sysroot" = xyes; then
+ AC_DEFINE(HAVE_LD_SYSROOT, 1,
+ [Define if your linker supports --sysroot.])
+ fi
+
if test x$with_sysroot = x && test x$host = x$target \
&& test "$prefix" != "/usr" && test "x$prefix" != "x$local_prefix" ; then
AC_DEFINE_UNQUOTED(PREFIX_INCLUDE_DIR, "$prefix/include",
[Define to PREFIX/include if cpp should also search that directory.])
fi
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.455
diff -c -5 -p -r1.455 gcc.c
*** gcc.c 26 Apr 2005 00:23:52 -0000 1.455
--- gcc.c 27 Apr 2005 20:15:49 -0000
*************** or with constant text in a single argume
*** 458,467 ****
--- 458,469 ----
%D Dump out a -L option for each directory in startfile_prefixes.
If multilib_dir is set, extra entries are generated with it affixed.
%l process LINK_SPEC as a spec.
%L process LIB_SPEC as a spec.
%G process LIBGCC_SPEC as a spec.
+ %R Output the concatenation of target_system_root and
+ target_sysroot_suffix.
%S process STARTFILE_SPEC as a spec. A capital S is actually used here.
%E process ENDFILE_SPEC as a spec. A capital E is actually used here.
%C process CPP_SPEC as a spec.
%1 process CC1_SPEC as a spec.
%2 process CC1PLUS_SPEC as a spec.
*************** proper position among the other output f
*** 699,708 ****
--- 701,714 ----
#ifndef STARTFILE_PREFIX_SPEC
# define STARTFILE_PREFIX_SPEC ""
#endif
+ #ifndef SYSROOT_SPEC
+ # define SYSROOT_SPEC "--sysroot=%R"
+ #endif
+
#ifndef SYSROOT_SUFFIX_SPEC
# define SYSROOT_SUFFIX_SPEC ""
#endif
#ifndef SYSROOT_HEADERS_SUFFIX_SPEC
*************** static const char *startfile_spec = STAR
*** 726,735 ****
--- 732,742 ----
static const char *switches_need_spaces = SWITCHES_NEED_SPACES;
static const char *linker_name_spec = LINKER_NAME;
static const char *link_command_spec = LINK_COMMAND_SPEC;
static const char *link_libgcc_spec = LINK_LIBGCC_SPEC;
static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC;
+ static const char *sysroot_spec = SYSROOT_SPEC;
static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC;
static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC;
/* Standard options to cpp, cc1, and as, to reduce duplication in specs.
There should be no need to override these in target dependent files,
*************** static struct spec_list static_specs[] =
*** 1530,1539 ****
--- 1537,1547 ----
INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec),
INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix),
INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix),
INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1),
INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec),
+ INIT_STATIC_SPEC ("sysroot_spec", &sysroot_spec),
INIT_STATIC_SPEC ("sysroot_suffix_spec", &sysroot_suffix_spec),
INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec", &sysroot_hdrs_suffix_spec),
};
#ifdef EXTRA_SPECS /* additional specs needed */
*************** main (int argc, const char **argv)
*** 6146,6155 ****
--- 6154,6176 ----
error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC.");
else if (argbuf_index == 1)
target_sysroot_suffix = xstrdup (argbuf[argbuf_index -1]);
}
+ #ifdef HAVE_LD_SYSROOT
+ /* Pass the --sysroot option to the linker, if it supports that. If
+ there is a sysroot_suffix_spec, it has already been processed by
+ this point, so target_system_root really is the system root we
+ should be using. */
+ if (target_system_root)
+ {
+ obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) "));
+ obstack_grow0 (&obstack, link_spec, strlen (link_spec));
+ set_spec ("link", obstack_finish (&obstack));
+ }
+ #endif
+
/* Process sysroot_hdrs_suffix_spec. */
if (*sysroot_hdrs_suffix_spec != 0
&& do_spec_2 (sysroot_hdrs_suffix_spec) == 0)
{
if (argbuf_index > 1)