This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: PATCH: --sysroot-suffix
Mark Mitchell <mark@codesourcery.com> writes:
> Daniel Jacobowitz wrote:
>> Would a --sysroot option work for you instead? I can't think of any
>> realistic configurations where GCC and LD would have different
>> sysroots, so passing it down from gcc makes some sense.
Sounds like this changeable sysroot thing is a hotter topic than
I'd realised. As mentioned on gcc@:
http://gcc.gnu.org/ml/gcc/2004-12/msg00099.html
I've got some patches to add the --sysroot option that Daniel suggests,
but I've been sitting on them waiting for gcc to enter stage 1 (or for
the 2.16 release process to kick off, whichever was sooner).
FWIW, the patches are attached. They were developed against slightly
older versions of the tools and I haven't tested whether they still
work. There are no docs yet either. Still, I thought it might be
worth throw ingthem into this thread to see what you folks think.
I can update them, test them, and document them if it's thought
to be way to go.
The patches were originally tested on a mips64-linux-gnu cross.
Due to the wonders of gcc's option mangling, the gcc part will
accept both --sysroot=/path and -fsysroot=/path.
> To do what you suggest, I would have to make more invasive changes to
> the GCC driver. Because the driver can't assume that binutils supports
> the new option, I was just modifying the linker spec for the target in
> question.
Might be missing the point here, but in the patches below, gcc will only
handle --sysroot=/-fsysroot= correctly if the linker also understands
--sysroot=. It seemed like a reasonable restriction at the time
but I'd be interested to know what others think.
Richard
ld/
* ldmain.h (ld_sysroot): Change type to a constant string.
* ldmain.c (ld_sysroot): Likewise.
(get_relative_sysroot, get_sysroot): New functions, adding command-line
support for changing the sysroot.
(main): Call the new functions.
* lexsup.c (OPTION_SYSROOT): New.
(ld_options): Add --sysroot.
(parse_args): Add a dummy handler for it.
Index: ld/ldmain.h
===================================================================
RCS file: /cvs/src/src/ld/ldmain.h,v
retrieving revision 1.9
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.9 ldmain.h
*** ld/ldmain.h 19 Jul 2004 16:40:52 -0000 1.9
--- ld/ldmain.h 17 Jan 2005 10:27:02 -0000
***************
*** 23,29 ****
#define LDMAIN_H
extern char *program_name;
! extern char *ld_sysroot;
extern char *ld_canon_sysroot;
extern int ld_canon_sysroot_len;
extern bfd *output_bfd;
--- 23,29 ----
#define LDMAIN_H
extern char *program_name;
! extern const char *ld_sysroot;
extern char *ld_canon_sysroot;
extern int ld_canon_sysroot_len;
extern bfd *output_bfd;
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.90
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.90 ldmain.c
*** ld/ldmain.c 20 Dec 2004 15:16:06 -0000 1.90
--- ld/ldmain.c 17 Jan 2005 10:27:04 -0000
*************** const char *output_filename = "a.out";
*** 68,74 ****
char *program_name;
/* The prefix for system library directories. */
! char *ld_sysroot;
/* The canonical representation of ld_sysroot. */
char * ld_canon_sysroot;
--- 68,74 ----
char *program_name;
/* The prefix for system library directories. */
! const char *ld_sysroot;
/* The canonical representation of ld_sysroot. */
char * ld_canon_sysroot;
*************** ld_config_type config;
*** 110,115 ****
--- 110,117 ----
sort_type sort_section;
+ static const char *get_sysroot
+ (int, char **);
static char *get_emulation
(int, char **);
static void set_scripts_dir
*************** main (int argc, char **argv)
*** 201,247 ****
xatexit (remove_output);
! #ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
! ld_sysroot = make_relative_prefix (program_name, BINDIR,
! TARGET_SYSTEM_ROOT);
!
! if (ld_sysroot)
! {
! struct stat s;
! int res = stat (ld_sysroot, &s) == 0 && S_ISDIR (s.st_mode);
!
! if (!res)
! {
! free (ld_sysroot);
! ld_sysroot = NULL;
! }
! }
!
! if (! ld_sysroot)
{
! ld_sysroot = make_relative_prefix (program_name, TOOLBINDIR,
! TARGET_SYSTEM_ROOT);
!
! if (ld_sysroot)
{
! struct stat s;
! int res = stat (ld_sysroot, &s) == 0 && S_ISDIR (s.st_mode);
!
! if (!res)
! {
! free (ld_sysroot);
! ld_sysroot = NULL;
! }
}
}
-
- if (! ld_sysroot)
- #endif
- ld_sysroot = TARGET_SYSTEM_ROOT;
-
- if (ld_sysroot && *ld_sysroot)
- ld_canon_sysroot = lrealpath (ld_sysroot);
-
if (ld_canon_sysroot)
ld_canon_sysroot_len = strlen (ld_canon_sysroot);
else
--- 203,220 ----
xatexit (remove_output);
! /* Set up the sysroot directory. */
! ld_sysroot = get_sysroot (argc, argv);
! if (*ld_sysroot)
{
! if (*TARGET_SYSTEM_ROOT == 0)
{
! einfo ("%P%F: this linker was not configured to use sysroots");
! ld_sysroot = "";
}
+ else
+ ld_canon_sysroot = lrealpath (ld_sysroot);
}
if (ld_canon_sysroot)
ld_canon_sysroot_len = strlen (ld_canon_sysroot);
else
*************** main (int argc, char **argv)
*** 587,592 ****
--- 560,610 ----
return 0;
}
+ /* If the configured sysroot is relocatable, try relocating it based on
+ default prefix FROM. Return the relocated directory if it exists,
+ otherwise return null. */
+
+ static char *
+ get_relative_sysroot (const char *from ATTRIBUTE_UNUSED)
+ {
+ #ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
+ char *path;
+ struct stat s;
+
+ path = make_relative_prefix (program_name, from, TARGET_SYSTEM_ROOT);
+ if (path)
+ {
+ if (stat (path, &s) == 0 && S_ISDIR (s.st_mode))
+ return path;
+ free (path);
+ }
+ #endif
+ return 0;
+ }
+
+ /* Return the sysroot directory. Return "" if no sysroot is being used. */
+
+ static const char *
+ get_sysroot (int argc, char **argv)
+ {
+ int i;
+ const char *path;
+
+ for (i = 1; i < argc; i++)
+ if (strncmp (argv[i], "--sysroot=", strlen ("--sysroot=")) == 0)
+ return argv[i] + strlen ("--sysroot=");
+
+ path = get_relative_sysroot (BINDIR);
+ if (path)
+ return path;
+
+ path = get_relative_sysroot (TOOLBINDIR);
+ if (path)
+ return path;
+
+ return TARGET_SYSTEM_ROOT;
+ }
+
/* We need to find any explicitly given emulation in order to initialize the
state that's needed by the lex&yacc argument parser (parse_args). */
Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.81
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.81 lexsup.c
*** ld/lexsup.c 15 Nov 2004 23:21:27 -0000 1.81
--- ld/lexsup.c 17 Jan 2005 10:27:06 -0000
*************** enum option_values
*** 71,76 ****
--- 71,77 ----
OPTION_DEFSYM,
OPTION_DEMANGLE,
OPTION_DYNAMIC_LINKER,
+ OPTION_SYSROOT,
OPTION_EB,
OPTION_EL,
OPTION_EMBEDDED_RELOCS,
*************** static const struct ld_option ld_options
*** 233,238 ****
--- 234,241 ----
{ {"library-path", required_argument, NULL, 'L'},
'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
TWO_DASHES },
+ { {"sysroot", required_argument, NULL, OPTION_SYSROOT},
+ '\0', N_("PATH"), N_("Change the configured sysroot"), TWO_DASHES },
{ {NULL, required_argument, NULL, '\0'},
'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
{ {"print-map", no_argument, NULL, 'M'},
*************** parse_args (unsigned argc, char **argv)
*** 747,752 ****
--- 750,758 ----
case OPTION_DYNAMIC_LINKER:
command_line.interpreter = optarg;
break;
+ case OPTION_SYSROOT:
+ /* Already handled in ldmain.c. */
+ break;
case OPTION_EB:
command_line.endian = ENDIAN_BIG;
break;
gcc/
* gcc.c (process_command): Handle -fsysroot=. Bypass relocatable
sysroot handling if the sysroot has been set on the command line.
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.444
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.444 gcc.c
*** gcc.c 7 Jan 2005 01:05:37 -0000 1.444
--- gcc.c 17 Jan 2005 10:14:59 -0000
*************** warranty; not even for MERCHANTABILITY o
*** 3449,3454 ****
--- 3449,3467 ----
add_assembler_option ("--target-help", 13);
add_linker_option ("--target-help", 13);
}
+ else if (! strncmp (argv[i], "-fsysroot=", strlen ("-fsysroot=")))
+ {
+ if (target_system_root == 0)
+ error ("warning: this compiler was not configured "
+ "to use sysroots");
+ else
+ {
+ target_system_root = argv[i] + strlen ("-fsysroot=");
+ target_system_root_changed = 1;
+ add_linker_option (concat ("--", argv[i] + 2, NULL),
+ strlen (argv[i]));
+ }
+ }
else if (! strcmp (argv[i], "-pass-exit-codes"))
{
pass_exit_codes = 1;
*************** warranty; not even for MERCHANTABILITY o
*** 3869,3875 ****
then consider it to relocate with the rest of the GCC installation
if GCC_EXEC_PREFIX is set.
``make_relative_prefix'' is not compiled for VMS, so don't call it. */
! if (target_system_root && gcc_exec_prefix)
{
char *tmp_prefix = make_relative_prefix (argv[0],
standard_bindir_prefix,
--- 3882,3888 ----
then consider it to relocate with the rest of the GCC installation
if GCC_EXEC_PREFIX is set.
``make_relative_prefix'' is not compiled for VMS, so don't call it. */
! if (target_system_root && gcc_exec_prefix && !target_system_root_changed)
{
char *tmp_prefix = make_relative_prefix (argv[0],
standard_bindir_prefix,
*************** warranty; not even for MERCHANTABILITY o
*** 3915,3920 ****
--- 3928,3935 ----
;
else if (! strncmp (argv[i], "-Wp,", 4))
;
+ else if (! strncmp (argv[i], "-fsysroot=", strlen ("-fsysroot=")))
+ ;
else if (! strcmp (argv[i], "-pass-exit-codes"))
;
else if (! strcmp (argv[i], "-print-search-dirs"))