This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

Use ';' as the RPATH separator on VxWorks


VxWorks uses ';' rather than ':' as the RPATH separator.  Quite a few
places in the linker are hard-coded to use ':', so this patches replaces
them with uses of a new config.rpath_separator variable.  I deliberately
left aix.em and sunos.em alone though; those ports will always use ':'.

As far as the elf.em parts go, gld${EMULATION_NAME}_search_needed
and gld${EMULATION_NAME}_add_sysroot are always used for RPATH-style
paths, so should use rpath_separator unconditionally.  I changed the
hard-coded use of ':' in gld${EMULATION_NAME}_parse_ld_so_conf
for consistency (this function builds an RPATH-style path from
individual filenames).  The BSD code reads a path from a configuration
file, but again, the configuration file will always use ':' on
those targets.

vxworks.em can't unconditionally define LDEMUL_BEFORE_PARSE to
vxworks_before_parse because armelf.em (for one) wants to suppress
the elf.em version.  I've therefore used a more general override
mechanism (described in the comments) and made the existing
LDEMUL_AFTER_OPEN code use it too.

Tested on:

    arm-elf
    arm-wrs-vxworks
    i386-freebsd
    i386-linux-gnu
    i586-wrs-vxworks
    mips-wrs-vxworks
    powerpc-wrs-vxworks
    sh-wrs-vxworks
    sparc64-linux-gnu
    sparc-linux-gnu
    sparc-netbsdelf
    sparc-sun-solaris2.6
    sparc-sun-solaris2.8
    sparc-wrs-vxworks
    x86_64-linux-gnu

OK to install?

Richard


ld/
	* ld.h (ld_config_type): Add rpath_separator.
	* ldmain.c (main): Initialize it.
	* lexsup.c (parse_args): Honor config.rpath_separator.
	* emultempl/elf32.em (gld${EMULATION_NAME}_search_needed): Likewise.
	(gld${EMULATION_NAME}_add_sysroot): Likewise.
	(gld${EMULATION_NAME}_parse_ld_so_conf): Use config.rpath_separator
	rather than ':' when building the path.
	* emultempl/vxworks.em (vxworks_before_parse): New function.
	Override config.rpath_separator.
	(LDEMUL_AFTER_OPEN): Do not change if EXTRA_EM_FILE has been
	set to gld${EMULATION_NAME}_after_open; #define that identifier
	to vxworks_foo instead.
	(LDEMUL_BEFORE_PARSE): Override in the same way as LDEMUL_AFTER_OPEN.

ld/testsuite/
	* ld-vxworks/rpath-1.s, ld-vxworks/rpath-1.d,
	* ld-vxworks/vxworks.exp: New files.

Index: ld/ld.h
===================================================================
RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.36
diff -u -p -r1.36 ld.h
--- ld/ld.h	17 Feb 2007 13:33:57 -0000	1.36
+++ ld/ld.h	28 Mar 2007 09:42:49 -0000
@@ -277,6 +277,9 @@ typedef struct {
   unsigned int split_by_reloc;
   bfd_size_type split_by_file;
 
+  /* The rpath separation character.  Usually ':'.  */
+  char rpath_separator;
+
   /* If set, only search library directories explicitly selected
      on the command line.  */
   bfd_boolean only_cmd_line_lib_dirs;
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.118
diff -u -p -r1.118 ldmain.c
--- ld/ldmain.c	21 Feb 2007 16:43:50 -0000	1.118
+++ ld/ldmain.c	28 Mar 2007 09:42:49 -0000
@@ -247,6 +247,7 @@ main (int argc, char **argv)
   config.build_constructors = TRUE;
   config.dynamic_link = FALSE;
   config.has_shared = FALSE;
+  config.rpath_separator = ':';
   config.split_by_reloc = (unsigned) -1;
   config.split_by_file = (bfd_size_type) -1;
   config.hash_table_size = 0;
Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.97
diff -u -p -r1.97 lexsup.c
--- ld/lexsup.c	15 Mar 2007 14:17:20 -0000	1.97
+++ ld/lexsup.c	28 Mar 2007 09:42:49 -0000
@@ -1045,17 +1045,14 @@ parse_args (unsigned argc, char **argv)
 	      /* First see whether OPTARG is already in the path.  */
 	      do
 		{
-		  size_t idx = 0;
-
-		  while (optarg[idx] != '\0' && optarg[idx] == cp[idx])
-		    ++idx;
-		  if (optarg[idx] == '\0'
-		      && (cp[idx] == '\0' || cp[idx] == ':'))
+		  if (strncmp (optarg, cp, optarg_len) == 0
+		      && (cp[optarg_len] == 0
+			  || cp[optarg_len] == config.rpath_separator))
 		    /* We found it.  */
 		    break;
 
 		  /* Not yet found.  */
-		  cp = strchr (cp, ':');
+		  cp = strchr (cp, config.rpath_separator);
 		  if (cp != NULL)
 		    ++cp;
 		}
@@ -1064,7 +1061,8 @@ parse_args (unsigned argc, char **argv)
 	      if (cp == NULL)
 		{
 		  buf = xmalloc (rpath_len + optarg_len + 2);
-		  sprintf (buf, "%s:%s", command_line.rpath, optarg);
+		  sprintf (buf, "%s%c%s", command_line.rpath,
+			   config.rpath_separator, optarg);
 		  free (command_line.rpath);
 		  command_line.rpath = buf;
 		}
@@ -1080,7 +1078,8 @@ parse_args (unsigned argc, char **argv)
 	      buf = xmalloc (strlen (command_line.rpath_link)
 			     + strlen (optarg)
 			     + 2);
-	      sprintf (buf, "%s:%s", command_line.rpath_link, optarg);
+	      sprintf (buf, "%s%c%s", command_line.rpath_link,
+		       config.rpath_separator, optarg);
 	      free (command_line.rpath_link);
 	      command_line.rpath_link = buf;
 	    }
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.176
diff -u -p -r1.176 elf32.em
--- ld/emultempl/elf32.em	19 Jan 2007 15:06:27 -0000	1.176
+++ ld/emultempl/elf32.em	28 Mar 2007 09:42:50 -0000
@@ -459,7 +459,7 @@ gld${EMULATION_NAME}_search_needed (cons
     {
       char *filename, *sset;
 
-      s = strchr (path, ':');
+      s = strchr (path, config.rpath_separator);
       if (s == NULL)
 	s = path + strlen (path);
 
@@ -492,7 +492,8 @@ EOF
 if [ "x${USE_LIBPATH}" = xyes ] ; then
   cat >>e${EMULATION_NAME}.c <<EOF
 
-/* Add the sysroot to every entry in a colon-separated path.  */
+/* Add the sysroot to every entry in a path separated by
+   config.rpath_separator.  */
 
 static char *
 gld${EMULATION_NAME}_add_sysroot (const char *path)
@@ -504,7 +505,7 @@ gld${EMULATION_NAME}_add_sysroot (const 
   colons = 0;
   i = 0;
   while (path[i])
-    if (path[i++] == ':')
+    if (path[i++] == config.rpath_separator)
       colons++;
 
   if (path[i])
@@ -516,7 +517,7 @@ gld${EMULATION_NAME}_add_sysroot (const 
   p = ret + strlen (ret);
   i = 0;
   while (path[i])
-    if (path[i] == ':')
+    if (path[i] == config.rpath_separator)
       {
 	*p++ = path[i++];
 	strcpy (p, ld_sysroot);
@@ -745,7 +746,7 @@ gld${EMULATION_NAME}_parse_ld_so_conf
 		  info->alloc += p - dir + 256;
 		  info->path = xrealloc (info->path, info->alloc);
 		}
-	      info->path[info->len++] = ':';
+	      info->path[info->len++] = config.rpath_separator;
 	    }
 	  memcpy (info->path + info->len, dir, p - dir);
 	  info->len += p - dir;
Index: ld/emultempl/vxworks.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/vxworks.em,v
retrieving revision 1.2
diff -u -p -r1.2 vxworks.em
--- ld/emultempl/vxworks.em	4 Aug 2006 13:13:56 -0000	1.2
+++ ld/emultempl/vxworks.em	28 Mar 2007 09:42:50 -0000
@@ -7,6 +7,13 @@ cat >>e${EMULATION_NAME}.c <<EOF
 static int force_dynamic;
 
 static void
+vxworks_before_parse (void)
+{
+  ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse} ();
+  config.rpath_separator = ';';
+}
+
+static void
 vxworks_after_open (void)
 {
   ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open} ();
@@ -48,4 +55,27 @@ PARSE_AND_LIST_ARGS_CASES=$PARSE_AND_LIS
       break;
 '
 
-LDEMUL_AFTER_OPEN=vxworks_after_open
+# Hook in our routines above.  There are three possibilities:
+#
+#   (1) VXWORKS_BASE_EM_FILE did not set the hook's LDEMUL_FOO variable.
+#	We want to define the LDEMUL_FOO to vxworks_foo in that case,
+#
+#   (2) VXWORKS_BASE_EM_FILE set the hook's LDEMUL_FOO variable to
+#	gld${EMULATION_NAME}_foo.  This means that the file has
+#	replaced elf32.em's default definition, so we simply #define
+#	the current value of LDEMUL_FOO to vxworks_foo.
+#
+#   (3) VXWORKS_BASE_EM_FILE set the hook's LDEMUL_FOO variable to
+#	something other than gld${EMULATION_NAME}_foo.  We handle
+#	this case in the same way as (1).
+for override in before_parse after_open; do
+  var="LDEMUL_`echo ${override} | tr a-z A-Z`"
+  eval value=\$${var}
+  if test "${value}" = "gld${EMULATION_NAME}_${override}"; then
+    cat >>e${EMULATION_NAME}.c <<EOF
+#define ${value} vxworks_${override}
+EOF
+  else
+    eval $var=vxworks_${override}
+  fi
+done
Index: ld/testsuite/ld-vxworks/rpath-1.s
===================================================================
--- ld/testsuite/ld-vxworks/rpath-1.s.1	1970-01-01 01:00:00.000000000 +0100
+++ ld/testsuite/ld-vxworks/rpath-1.s	2007-03-27 12:54:06.000000000 +0100
@@ -0,0 +1,2 @@
+	.global	foo
+foo:
Index: ld/testsuite/ld-vxworks/rpath-1.d
===================================================================
--- ld/testsuite/ld-vxworks/rpath-1.d.1	1970-01-01 01:00:00.000000000 +0100
+++ ld/testsuite/ld-vxworks/rpath-1.d	2007-03-28 10:42:29.000000000 +0100
@@ -0,0 +1,6 @@
+# source: rpath-1.s
+# ld: --entry foo --rpath /dir1 --rpath /dir2 --rpath net:/dir4 --rpath /dir2 --rpath /dir1 --rpath /dir3 --force-dynamic -q
+# readelf: -d
+#...
+ 0x0+f \(RPATH\).*Library rpath: \[/dir1;/dir2;net:/dir4;/dir3\]
+#pass
Index: ld/testsuite/ld-vxworks/vxworks.exp
===================================================================
--- ld/testsuite/ld-vxworks/vxworks.exp.1	1970-01-01 01:00:00.000000000 +0100
+++ ld/testsuite/ld-vxworks/vxworks.exp	2007-03-28 09:51:35.000000000 +0100
@@ -0,0 +1,24 @@
+# Expect script for VxWorks tests
+#   Copyright 2007 Free Software Foundation, Inc.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+
+if { [istarget *-*-vxworks*] } {
+    foreach test [lsort [glob -nocomplain $srcdir/$subdir/*.d]] {
+	if { [runtest_file_p $runtests $test] } {
+	    run_dump_test [file rootname $test]
+	}
+    }
+}


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