PATCH: --sysroot-suffix
Richard Sandiford
rsandifo@redhat.com
Tue Jan 18 15:54:00 GMT 2005
OK, the concensus seemed to be that a --sysroot flag was worth having,
and that it would be nice to support it on non-sysrooted linkers too,
but that it wasn't necessary for the first cut.
Here's a cleaned-up version of the patch, this time with docs and
NEWS item. Tested on mips-linux-gnu. OK to install?
Richard
* 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.
* ld.texinfo (--sysroot): Document.
* NEWS: Mention the new --sysroot option.
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 18 Jan 2005 15:40:10 -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 18 Jan 2005 15:40:12 -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 18 Jan 2005 15:40:13 -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=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT},
+ '\0', NULL, N_("Override the default sysroot location"), 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;
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.133
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.133 ld.texinfo
*** ld/ld.texinfo 26 Nov 2004 09:42:03 -0000 1.133
--- ld/ld.texinfo 18 Jan 2005 15:40:22 -0000
*************** many relocations. @var{count} defaults
*** 1504,1509 ****
--- 1504,1515 ----
Compute and display statistics about the operation of the linker, such
as execution time and memory usage.
+ @kindex --sysroot
+ @item --sysroot=@var{directory}
+ Use @var{directory} as the location of the sysroot, overriding the
+ configure-time default. This option is only supported by linkers
+ that were configured using @option{--with-sysroot}.
+
@kindex --traditional-format
@cindex traditional format
@item --traditional-format
Index: ld/NEWS
===================================================================
RCS file: /cvs/src/src/ld/NEWS,v
retrieving revision 1.55
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.55 NEWS
*** ld/NEWS 19 Nov 2004 09:31:53 -0000 1.55
--- ld/NEWS 18 Jan 2005 15:40:22 -0000
***************
*** 1,5 ****
--- 1,9 ----
-*- text -*-
+ * A new command-line option, --sysroot, can be used to override the
+ default sysroot location. It only applies to toolchains that were
+ configured using --with-sysroot.
+
* New linker script functions: ORIGIN() and LENGTH() which return information
about a specified memory region.
More information about the Binutils
mailing list