>From eaf521601e7f75119e76c1037a68516844a1ae4a Mon Sep 17 00:00:00 2001
From: Rafal Krypa <[email protected]>
Date: Wed, 18 May 2011 16:58:54 +0200
Subject: [PATCH 9/9] external_patches: fix ldso-rpath-prefix patches to
 correctly support "$ORIGIN" in rpath.

Without this patch --rpath-prefix option applied to rpath starting with $ORIGIN
caused the prefix to be prepended twice - as rpath-prefix and as prefix of
$ORIGIN.
This commit, together with /proc/<PID>/exe bugfix, enables usage of JRE/JDK
(OpenJDK/GCJ/Sun) inside Scratchbox 2.

Change-Id: I14c31d9f4f753f48ee133dcddf9321f4113b466c
---
 .../glibc-2.10-ldso-rpath-prefix-option.2.patch    |  164 +++++++++++++++----
 .../glibc-2.5-ld.so-rpath-prefix-option.patch      |  166 ++++++++++++++++---
 .../glibc-2.8-ldso-rpath-prefix-option.patch       |  171 ++++++++++++++++----
 3 files changed, 416 insertions(+), 85 deletions(-)

diff --git a/external_patches/glibc-2.10-ldso-rpath-prefix-option.2.patch b/external_patches/glibc-2.10-ldso-rpath-prefix-option.2.patch
index 06c755d..3cca0f7 100644
--- a/external_patches/glibc-2.10-ldso-rpath-prefix-option.2.patch
+++ b/external_patches/glibc-2.10-ldso-rpath-prefix-option.2.patch
@@ -1,8 +1,49 @@
-Index: eglibc-2.10/elf/dl-load.c
+Index: libc/elf/dl-load.c
 ===================================================================
---- eglibc-2.10.orig/elf/dl-load.c	2009-10-12 21:30:00.000000000 +0300
-+++ eglibc-2.10/elf/dl-load.c	2010-04-16 12:56:31.000000000 +0300
-@@ -380,7 +380,8 @@
+--- libc/elf/dl-load.c	(revision 13883)
++++ libc/elf/dl-load.c	(working copy)
+@@ -237,7 +237,7 @@
+ 
+ char *
+ _dl_dst_substitute (struct link_map *l, const char *name, char *result,
+-		    int is_path)
++		    int is_path, const char *rpath_prefix)
+ {
+   const char *const start = name;
+   char *last_elem, *wp;
+@@ -273,6 +273,13 @@
+ 
+ 	  if (repl != NULL && repl != (const char *) -1)
+ 	    {
++	      if (__builtin_expect (rpath_prefix != NULL, 0))
++		{
++		  /* has rpath_prefix */
++		  size_t rpath_prefix_len = strlen (rpath_prefix);
++		  if (!strncmp (repl, rpath_prefix, rpath_prefix_len))
++		    repl += rpath_prefix_len;
++		}
+ 	      wp = __stpcpy (wp, repl);
+ 	      name += len;
+ 	    }
+@@ -310,7 +317,7 @@
+    belonging to the map is loaded.  In this case the path element
+    containing $ORIGIN is left out.  */
+ static char *
+-expand_dynamic_string_token (struct link_map *l, const char *s)
++expand_dynamic_string_token (struct link_map *l, const char *s, const char *rpath_prefix)
+ {
+   /* We make two runs over the string.  First we determine how large the
+      resulting string is and then we copy it over.  Since this is now
+@@ -335,7 +342,7 @@
+   if (result == NULL)
+     return NULL;
+ 
+-  return _dl_dst_substitute (l, s, result, 1);
++  return _dl_dst_substitute (l, s, result, 1, rpath_prefix);
+ }
+ 
+ 
+@@ -380,7 +387,8 @@
  
  static struct r_search_path_elem **
  fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
@@ -12,7 +53,7 @@ Index: eglibc-2.10/elf/dl-load.c
  {
    char *cp;
    size_t nelems = 0;
-@@ -436,9 +437,23 @@
+@@ -436,10 +444,24 @@
  	}
  
        /* See if this directory is already known.  */
@@ -23,7 +64,7 @@ Index: eglibc-2.10/elf/dl-load.c
 +	{
 +	  /* has rpath_prefix */
 +	  size_t rpath_prefix_len = strlen (rpath_prefix);
-+
+ 
 +	  for (dirp = GL(dl_all_dirs); dirp != NULL; dirp = dirp->next)
 +	    if (dirp->dirnamelen == (rpath_prefix_len+len) &&
 +		(memcmp (cp, rpath_prefix, rpath_prefix_len) == 0) &&
@@ -36,22 +77,23 @@ Index: eglibc-2.10/elf/dl-load.c
 +	    if (dirp->dirnamelen == len && memcmp (cp, dirp->dirname, len) == 0)
 +	      break;
 +	}
- 
++
        if (dirp != NULL)
  	{
-@@ -456,22 +471,43 @@
+ 	  /* It is available, see whether it's on our own list.  */
+@@ -456,23 +478,44 @@
  	  size_t cnt;
  	  enum r_dir_status init_val;
  	  size_t where_len = where ? strlen (where) + 1 : 0;
 +	  size_t rpath_prefix_len = 0;
-+
+ 
 +	  if (__builtin_expect (rpath_prefix != NULL, 0)
 +	      && !INTUSE(__libc_enable_secure))
 +	    {
 +		rpath_prefix_len = strlen (rpath_prefix);
 +		if (*cp != '/') rpath_prefix_len++; /* need to add a '/' */
 +	    }
- 
++
  	  /* It's a new directory.  Create an entry and add it.  */
  	  dirp = (struct r_search_path_elem *)
  	    malloc (sizeof (*dirp) + ncapstr * sizeof (enum r_dir_status)
@@ -72,7 +114,9 @@ Index: eglibc-2.10/elf/dl-load.c
 +	  else
 +	    {
 +		char *prefixend;
-+
+ 
+-	  if (len > max_dirnamelen)
+-	    max_dirnamelen = len;
 +		prefixend = (char *) __mempcpy ((char *) dirp->dirname,
 +				rpath_prefix, rpath_prefix_len);
 +		if (*cp != '/')
@@ -81,14 +125,13 @@ Index: eglibc-2.10/elf/dl-load.c
 +	    }
 +	  dirp->dirnamelen = len + rpath_prefix_len;
  
--	  if (len > max_dirnamelen)
--	    max_dirnamelen = len;
 +	  if ((len + rpath_prefix_len) > max_dirnamelen)
 +	    max_dirnamelen = len + rpath_prefix_len;
- 
++
  	  /* We have to make sure all the relative directories are
  	     never ignored.  The current directory might change and
-@@ -482,7 +518,8 @@
+ 	     all our saved information would be void.  */
+@@ -482,7 +525,8 @@
  
  	  dirp->what = what;
  	  if (__builtin_expect (where != NULL, 1))
@@ -98,7 +141,16 @@ Index: eglibc-2.10/elf/dl-load.c
  				  + (ncapstr * sizeof (enum r_dir_status)),
  				  where, where_len);
  	  else
-@@ -576,7 +613,7 @@
+@@ -551,7 +595,7 @@
+ 
+   /* Make a writable copy.  At the same time expand possible dynamic
+      string tokens.  */
+-  copy = expand_dynamic_string_token (l, rpath);
++  copy = expand_dynamic_string_token (l, rpath, GLRO(dl_rpath_prefix));
+   if (copy == NULL)
+     {
+       errstring = N_("cannot create RUNPATH/RPATH copy");
+@@ -576,7 +620,7 @@
        _dl_signal_error (ENOMEM, NULL, NULL, errstring);
      }
  
@@ -107,7 +159,16 @@ Index: eglibc-2.10/elf/dl-load.c
  
    /* Free the copied RPATH string.  `fillin_rpath' make own copies if
       necessary.  */
-@@ -775,7 +812,7 @@
+@@ -749,7 +793,7 @@
+ 
+ 	  /* Allocate the necessary memory.  */
+ 	  llp_tmp = (char *) alloca (total + 1);
+-	  llp_tmp = _dl_dst_substitute (l, llp, llp_tmp, 1);
++	  llp_tmp = _dl_dst_substitute (l, llp, llp_tmp, 1, NULL);
+ 	}
+ #else
+       llp_tmp = strdupa (llp);
+@@ -775,7 +819,7 @@
  
        (void) fillin_rpath (llp_tmp, env_path_list.dirs, ":;",
  			   INTUSE(__libc_enable_secure), "LD_LIBRARY_PATH",
@@ -116,10 +177,19 @@ Index: eglibc-2.10/elf/dl-load.c
  
        if (env_path_list.dirs[0] == NULL)
  	{
-Index: eglibc-2.10/elf/dl-support.c
+@@ -2167,7 +2211,7 @@
+     {
+       /* The path may contain dynamic string tokens.  */
+       realname = (loader
+-		  ? expand_dynamic_string_token (loader, name)
++		  ? expand_dynamic_string_token (loader, name, NULL)
+ 		  : local_strdup (name));
+       if (realname == NULL)
+ 	fd = -1;
+Index: libc/elf/dl-support.c
 ===================================================================
---- eglibc-2.10.orig/elf/dl-support.c	2009-10-12 21:30:00.000000000 +0300
-+++ eglibc-2.10/elf/dl-support.c	2010-04-16 12:56:31.000000000 +0300
+--- libc/elf/dl-support.c	(revision 13883)
++++ libc/elf/dl-support.c	(working copy)
 @@ -56,6 +56,9 @@
     ignored.  */
  const char *_dl_inhibit_rpath;
@@ -130,11 +200,11 @@ Index: eglibc-2.10/elf/dl-support.c
  /* The map for the object we will profile.  */
  struct link_map *_dl_profile_map;
  
-Index: eglibc-2.10/elf/rtld.c
+Index: libc/elf/rtld.c
 ===================================================================
---- eglibc-2.10.orig/elf/rtld.c	2010-04-16 12:56:31.000000000 +0300
-+++ eglibc-2.10/elf/rtld.c	2010-04-16 12:56:31.000000000 +0300
-@@ -979,6 +979,15 @@
+--- libc/elf/rtld.c	(revision 13883)
++++ libc/elf/rtld.c	(working copy)
+@@ -978,6 +978,15 @@
  	    _dl_argc -= 2;
  	    INTUSE(_dl_argv) += 2;
  	  }
@@ -150,18 +220,18 @@ Index: eglibc-2.10/elf/rtld.c
  	else if (! strcmp (INTUSE(_dl_argv)[1], "--audit") && _dl_argc > 2)
  	  {
  	    process_dl_audit (INTUSE(_dl_argv)[2]);
-@@ -1020,6 +1029,7 @@
+@@ -1011,6 +1020,7 @@
                          object we can handle\n\
    --library-path PATH   use given PATH instead of content of the environment\n\
                          variable LD_LIBRARY_PATH\n\
 +  --rpath-prefix PREFIX add PREFIX to every RUNPATH and RPATH component\n\
    --inhibit-rpath LIST  ignore RUNPATH and RPATH information in object names\n\
                          in LIST\n\
-                         in LIST\n\
-Index: eglibc-2.10/sysdeps/generic/ldsodefs.h
+   --audit LIST          use objects named in LIST as auditors\n");
+Index: libc/sysdeps/generic/ldsodefs.h
 ===================================================================
---- eglibc-2.10.orig/sysdeps/generic/ldsodefs.h	2009-10-12 21:29:18.000000000 +0300
-+++ eglibc-2.10/sysdeps/generic/ldsodefs.h	2010-04-16 12:56:31.000000000 +0300
+--- libc/sysdeps/generic/ldsodefs.h	(revision 13883)
++++ libc/sysdeps/generic/ldsodefs.h	(working copy)
 @@ -664,6 +664,12 @@
  
    /* 0 if internal pointer values should not be guarded, 1 if they should.  */
@@ -175,3 +245,39 @@ Index: eglibc-2.10/sysdeps/generic/ldsodefs.h
  };
  # define __rtld_global_attribute__
  # ifdef IS_IN_rtld
+@@ -1047,7 +1053,8 @@
+ 
+ /* Substitute DST values.  */
+ extern char *_dl_dst_substitute (struct link_map *l, const char *name,
+-				 char *result, int is_path) attribute_hidden;
++				 char *result, int is_path,
++				 const char *rpath_prefix) attribute_hidden;
+ 
+ /* Check validity of the caller.  */
+ extern int _dl_check_caller (const void *caller, enum allowmask mask)
+Index: libc/elf/dl-open.c
+===================================================================
+--- libc/elf/dl-open.c	(revision 13883)
++++ libc/elf/dl-open.c	(working copy)
+@@ -269,7 +269,7 @@
+       char *new_file = (char *) alloca (required + 1);
+ 
+       /* Generate the new file name.  */
+-      _dl_dst_substitute (call_map, file, new_file, 0);
++      _dl_dst_substitute (call_map, file, new_file, 0, NULL);
+ 
+       /* If the substitution failed don't try to load.  */
+       if (*new_file == '\0')
+Index: libc/elf/dl-deps.c
+===================================================================
+--- libc/elf/dl-deps.c	(revision 13883)
++++ libc/elf/dl-deps.c	(working copy)
+@@ -117,7 +117,7 @@
+ 	__newp = (char *) alloca (DL_DST_REQUIRED (l, __str, strlen (__str),  \
+ 						   __dst_cnt));		      \
+ 									      \
+-	__result = _dl_dst_substitute (l, __str, __newp, 0);		      \
++	__result = _dl_dst_substitute (l, __str, __newp, 0, NULL);	      \
+ 									      \
+ 	if (*__result == '\0')						      \
+ 	  {								      \
diff --git a/external_patches/glibc-2.5-ld.so-rpath-prefix-option.patch b/external_patches/glibc-2.5-ld.so-rpath-prefix-option.patch
index a5d6f9e..e483522 100644
--- a/external_patches/glibc-2.5-ld.so-rpath-prefix-option.patch
+++ b/external_patches/glibc-2.5-ld.so-rpath-prefix-option.patch
@@ -1,6 +1,49 @@
---- a/elf/dl-load.c	2007-09-25 17:20:30.000000000 +0300
-+++ b/elf/dl-load.c	2009-11-17 16:12:20.000000000 +0200
-@@ -388,7 +388,8 @@
+Index: libc/elf/dl-load.c
+===================================================================
+--- libc/elf/dl-load.c	(revision 13872)
++++ libc/elf/dl-load.c	(working copy)
+@@ -245,7 +245,7 @@
+ 
+ char *
+ _dl_dst_substitute (struct link_map *l, const char *name, char *result,
+-		    int is_path)
++		    int is_path, const char *rpath_prefix)
+ {
+   const char *const start = name;
+   char *last_elem, *wp;
+@@ -281,6 +281,13 @@
+ 
+ 	  if (repl != NULL && repl != (const char *) -1)
+ 	    {
++	      if (__builtin_expect (rpath_prefix != NULL, 0))
++		{
++		  /* has rpath_prefix */
++		  size_t rpath_prefix_len = strlen (rpath_prefix);
++		  if (!strncmp (repl, rpath_prefix, rpath_prefix_len))
++		    repl += rpath_prefix_len;
++		}
+ 	      wp = __stpcpy (wp, repl);
+ 	      name += len;
+ 	    }
+@@ -318,7 +325,7 @@
+    belonging to the map is loaded.  In this case the path element
+    containing $ORIGIN is left out.  */
+ static char *
+-expand_dynamic_string_token (struct link_map *l, const char *s)
++expand_dynamic_string_token (struct link_map *l, const char *s, const char *rpath_prefix)
+ {
+   /* We make two runs over the string.  First we determine how large the
+      resulting string is and then we copy it over.  Since this is now
+@@ -343,7 +350,7 @@
+   if (result == NULL)
+     return NULL;
+ 
+-  return _dl_dst_substitute (l, s, result, 1);
++  return _dl_dst_substitute (l, s, result, 1, rpath_prefix);
+ }
+ 
+ 
+@@ -388,7 +395,8 @@
  
  static struct r_search_path_elem **
  fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
@@ -10,7 +53,7 @@
  {
    char *cp;
    size_t nelems = 0;
-@@ -445,9 +445,23 @@
+@@ -444,10 +452,24 @@
  	}
  
        /* See if this directory is already known.  */
@@ -21,7 +64,7 @@
 +	{
 +	  /* has rpath_prefix */
 +	  size_t rpath_prefix_len = strlen (rpath_prefix);
-+
+ 
 +	  for (dirp = GL(dl_all_dirs); dirp != NULL; dirp = dirp->next)
 +	    if (dirp->dirnamelen == (rpath_prefix_len+len) &&
 +		(memcmp (cp, rpath_prefix, rpath_prefix_len) == 0) &&
@@ -34,22 +77,23 @@
 +	    if (dirp->dirnamelen == len && memcmp (cp, dirp->dirname, len) == 0)
 +	      break;
 +	}
- 
++
        if (dirp != NULL)
  	{
-@@ -464,22 +465,43 @@
+ 	  /* It is available, see whether it's on our own list.  */
+@@ -464,23 +486,44 @@
  	  size_t cnt;
  	  enum r_dir_status init_val;
  	  size_t where_len = where ? strlen (where) + 1 : 0;
 +	  size_t rpath_prefix_len = 0;
-+
+ 
 +	  if (__builtin_expect (rpath_prefix != NULL, 0)
 +	      && !INTUSE(__libc_enable_secure))
 +	    {
 +		rpath_prefix_len = strlen (rpath_prefix);
 +		if (*cp != '/') rpath_prefix_len++; /* need to add a '/' */
 +	    }
- 
++
  	  /* It's a new directory.  Create an entry and add it.  */
  	  dirp = (struct r_search_path_elem *)
  	    malloc (sizeof (*dirp) + ncapstr * sizeof (enum r_dir_status)
@@ -70,7 +114,9 @@
 +	  else
 +	    {
 +		char *prefixend;
-+
+ 
+-	  if (len > max_dirnamelen)
+-	    max_dirnamelen = len;
 +		prefixend = (char *) __mempcpy ((char *) dirp->dirname,
 +				rpath_prefix, rpath_prefix_len);
 +		if (*cp != '/')
@@ -79,14 +125,13 @@
 +	    }
 +	  dirp->dirnamelen = len + rpath_prefix_len;
  
--	  if (len > max_dirnamelen)
--	    max_dirnamelen = len;
 +	  if ((len + rpath_prefix_len) > max_dirnamelen)
 +	    max_dirnamelen = len + rpath_prefix_len;
- 
++
  	  /* We have to make sure all the relative directories are
  	     never ignored.  The current directory might change and
-@@ -490,7 +512,8 @@
+ 	     all our saved information would be void.  */
+@@ -490,7 +533,8 @@
  
  	  dirp->what = what;
  	  if (__builtin_expect (where != NULL, 1))
@@ -96,7 +141,16 @@
  				  + (ncapstr * sizeof (enum r_dir_status)),
  				  where, where_len);
  	  else
-@@ -583,7 +606,7 @@
+@@ -559,7 +603,7 @@
+ 
+   /* Make a writable copy.  At the same time expand possible dynamic
+      string tokens.  */
+-  copy = expand_dynamic_string_token (l, rpath);
++  copy = expand_dynamic_string_token (l, rpath, GLRO(dl_rpath_prefix));
+   if (copy == NULL)
+     {
+       errstring = N_("cannot create RUNPATH/RPATH copy");
+@@ -583,7 +627,7 @@
        _dl_signal_error (ENOMEM, NULL, NULL, errstring);
      }
  
@@ -105,7 +159,16 @@
  
    /* Free the copied RPATH string.  `fillin_rpath' make own copies if
       necessary.  */
-@@ -782,7 +805,7 @@
+@@ -756,7 +800,7 @@
+ 
+ 	  /* Allocate the necessary memory.  */
+ 	  llp_tmp = (char *) alloca (total + 1);
+-	  llp_tmp = _dl_dst_substitute (l, llp, llp_tmp, 1);
++	  llp_tmp = _dl_dst_substitute (l, llp, llp_tmp, 1, NULL);
+ 	}
+ #else
+       llp_tmp = strdupa (llp);
+@@ -782,7 +826,7 @@
  
        (void) fillin_rpath (llp_tmp, env_path_list.dirs, ":;",
  			   INTUSE(__libc_enable_secure), "LD_LIBRARY_PATH",
@@ -114,8 +177,19 @@
  
        if (env_path_list.dirs[0] == NULL)
  	{
---- a/elf/dl-support.c	2007-09-25 17:20:30.000000000 +0300
-+++ b/elf/dl-support.c	2009-10-22 14:51:01.000000000 +0300
+@@ -2164,7 +2208,7 @@
+     {
+       /* The path may contain dynamic string tokens.  */
+       realname = (loader
+-		  ? expand_dynamic_string_token (loader, name)
++		  ? expand_dynamic_string_token (loader, name, NULL)
+ 		  : local_strdup (name));
+       if (realname == NULL)
+ 	fd = -1;
+Index: libc/elf/dl-support.c
+===================================================================
+--- libc/elf/dl-support.c	(revision 13872)
++++ libc/elf/dl-support.c	(working copy)
 @@ -56,6 +56,9 @@
     ignored.  */
  const char *_dl_inhibit_rpath;
@@ -126,9 +200,11 @@
  /* The map for the object we will profile.  */
  struct link_map *_dl_profile_map;
  
---- a/elf/rtld.c	2009-10-22 14:40:05.000000000 +0300
-+++ b/elf/rtld.c	2009-10-22 14:50:47.000000000 +0300
-@@ -951,6 +951,15 @@
+Index: libc/elf/rtld.c
+===================================================================
+--- libc/elf/rtld.c	(revision 13872)
++++ libc/elf/rtld.c	(working copy)
+@@ -950,6 +950,15 @@
  	    _dl_argc -= 2;
  	    INTUSE(_dl_argv) += 2;
  	  }
@@ -144,16 +220,18 @@
  	else if (! strcmp (INTUSE(_dl_argv)[1], "--audit") && _dl_argc > 2)
  	  {
  	    process_dl_audit (INTUSE(_dl_argv)[2]);
-@@ -992,6 +1001,7 @@
+@@ -983,6 +992,7 @@
                          object we can handle\n\
    --library-path PATH   use given PATH instead of content of the environment\n\
                          variable LD_LIBRARY_PATH\n\
 +  --rpath-prefix PREFIX add PREFIX to every RUNPATH and RPATH component\n\
    --inhibit-rpath LIST  ignore RUNPATH and RPATH information in object names\n\
-                         in LIST\n\
-   --argv0 STRING        use STRING as argv[0]\n");
---- a/sysdeps/generic/ldsodefs.h	2007-09-25 17:19:58.000000000 +0300
-+++ b/sysdeps/generic/ldsodefs.h	2009-10-22 14:50:15.000000000 +0300
+                         in LIST\n");
+ 
+Index: libc/sysdeps/generic/ldsodefs.h
+===================================================================
+--- libc/sysdeps/generic/ldsodefs.h	(revision 13872)
++++ libc/sysdeps/generic/ldsodefs.h	(working copy)
 @@ -666,6 +666,12 @@
    /* List of auditing interfaces.  */
    struct audit_ifaces *_dl_audit;
@@ -167,3 +245,39 @@
  };
  # define __rtld_global_attribute__
  # ifdef IS_IN_rtld
+@@ -1050,7 +1056,8 @@
+ 
+ /* Substitute DST values.  */
+ extern char *_dl_dst_substitute (struct link_map *l, const char *name,
+-				 char *result, int is_path) attribute_hidden;
++				 char *result, int is_path,
++				 const char *rpath_prefix) attribute_hidden;
+ 
+ /* Check validity of the caller.  */
+ extern int _dl_check_caller (const void *caller, enum allowmask mask)
+Index: libc/elf/dl-open.c
+===================================================================
+--- libc/elf/dl-open.c	(revision 13872)
++++ libc/elf/dl-open.c	(working copy)
+@@ -229,7 +229,7 @@
+       new_file = (char *) alloca (required + 1);
+ 
+       /* Generate the new file name.  */
+-      _dl_dst_substitute (call_map, file, new_file, 0);
++      _dl_dst_substitute (call_map, file, new_file, 0, NULL);
+ 
+       /* If the substitution failed don't try to load.  */
+       if (*new_file == '\0')
+Index: libc/elf/dl-deps.c
+===================================================================
+--- libc/elf/dl-deps.c	(revision 13872)
++++ libc/elf/dl-deps.c	(working copy)
+@@ -115,7 +115,7 @@
+ 	__newp = (char *) alloca (DL_DST_REQUIRED (l, __str, strlen (__str),  \
+ 						   __dst_cnt));		      \
+ 									      \
+-	__result = _dl_dst_substitute (l, __str, __newp, 0);		      \
++	__result = _dl_dst_substitute (l, __str, __newp, 0, NULL);	      \
+ 									      \
+ 	if (*__result == '\0')						      \
+ 	  {								      \
diff --git a/external_patches/glibc-2.8-ldso-rpath-prefix-option.patch b/external_patches/glibc-2.8-ldso-rpath-prefix-option.patch
index 55d37b6..845a106 100644
--- a/external_patches/glibc-2.8-ldso-rpath-prefix-option.patch
+++ b/external_patches/glibc-2.8-ldso-rpath-prefix-option.patch
@@ -1,6 +1,49 @@
---- a/elf/dl-load.c	2009-05-21 00:47:14.000000000 +0300
-+++ b/elf/dl-load.c	2009-12-31 14:51:27.000000000 +0200
-@@ -388,7 +388,8 @@
+Index: libc/elf/dl-load.c
+===================================================================
+--- libc/elf/dl-load.c	(revision 13872)
++++ libc/elf/dl-load.c	(working copy)
+@@ -245,7 +245,7 @@
+ 
+ char *
+ _dl_dst_substitute (struct link_map *l, const char *name, char *result,
+-		    int is_path)
++		    int is_path, const char *rpath_prefix)
+ {
+   const char *const start = name;
+   char *last_elem, *wp;
+@@ -281,6 +281,13 @@
+ 
+ 	  if (repl != NULL && repl != (const char *) -1)
+ 	    {
++	      if (__builtin_expect (rpath_prefix != NULL, 0))
++		{
++		  /* has rpath_prefix */
++		  size_t rpath_prefix_len = strlen (rpath_prefix);
++		  if (!strncmp (repl, rpath_prefix, rpath_prefix_len))
++		    repl += rpath_prefix_len;
++		}
+ 	      wp = __stpcpy (wp, repl);
+ 	      name += len;
+ 	    }
+@@ -318,7 +325,7 @@
+    belonging to the map is loaded.  In this case the path element
+    containing $ORIGIN is left out.  */
+ static char *
+-expand_dynamic_string_token (struct link_map *l, const char *s)
++expand_dynamic_string_token (struct link_map *l, const char *s, const char *rpath_prefix)
+ {
+   /* We make two runs over the string.  First we determine how large the
+      resulting string is and then we copy it over.  Since this is now
+@@ -343,7 +350,7 @@
+   if (result == NULL)
+     return NULL;
+ 
+-  return _dl_dst_substitute (l, s, result, 1);
++  return _dl_dst_substitute (l, s, result, 1, rpath_prefix);
+ }
+ 
+ 
+@@ -388,7 +395,8 @@
  
  static struct r_search_path_elem **
  fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
@@ -10,7 +53,7 @@
  {
    char *cp;
    size_t nelems = 0;
-@@ -444,9 +445,23 @@
+@@ -444,10 +452,24 @@
  	}
  
        /* See if this directory is already known.  */
@@ -21,7 +64,7 @@
 +	{
 +	  /* has rpath_prefix */
 +	  size_t rpath_prefix_len = strlen (rpath_prefix);
-+
+ 
 +	  for (dirp = GL(dl_all_dirs); dirp != NULL; dirp = dirp->next)
 +	    if (dirp->dirnamelen == (rpath_prefix_len+len) &&
 +		(memcmp (cp, rpath_prefix, rpath_prefix_len) == 0) &&
@@ -34,22 +77,23 @@
 +	    if (dirp->dirnamelen == len && memcmp (cp, dirp->dirname, len) == 0)
 +	      break;
 +	}
- 
++
        if (dirp != NULL)
  	{
-@@ -464,22 +479,43 @@
+ 	  /* It is available, see whether it's on our own list.  */
+@@ -464,23 +486,44 @@
  	  size_t cnt;
  	  enum r_dir_status init_val;
  	  size_t where_len = where ? strlen (where) + 1 : 0;
 +	  size_t rpath_prefix_len = 0;
-+
+ 
 +	  if (__builtin_expect (rpath_prefix != NULL, 0)
 +	      && !INTUSE(__libc_enable_secure))
 +	    {
 +		rpath_prefix_len = strlen (rpath_prefix);
 +		if (*cp != '/') rpath_prefix_len++; /* need to add a '/' */
 +	    }
- 
++
  	  /* It's a new directory.  Create an entry and add it.  */
  	  dirp = (struct r_search_path_elem *)
  	    malloc (sizeof (*dirp) + ncapstr * sizeof (enum r_dir_status)
@@ -70,7 +114,9 @@
 +	  else
 +	    {
 +		char *prefixend;
-+
+ 
+-	  if (len > max_dirnamelen)
+-	    max_dirnamelen = len;
 +		prefixend = (char *) __mempcpy ((char *) dirp->dirname,
 +				rpath_prefix, rpath_prefix_len);
 +		if (*cp != '/')
@@ -79,14 +125,13 @@
 +	    }
 +	  dirp->dirnamelen = len + rpath_prefix_len;
  
--	  if (len > max_dirnamelen)
--	    max_dirnamelen = len;
 +	  if ((len + rpath_prefix_len) > max_dirnamelen)
 +	    max_dirnamelen = len + rpath_prefix_len;
- 
++
  	  /* We have to make sure all the relative directories are
  	     never ignored.  The current directory might change and
-@@ -490,7 +526,8 @@
+ 	     all our saved information would be void.  */
+@@ -490,7 +533,8 @@
  
  	  dirp->what = what;
  	  if (__builtin_expect (where != NULL, 1))
@@ -96,7 +141,16 @@
  				  + (ncapstr * sizeof (enum r_dir_status)),
  				  where, where_len);
  	  else
-@@ -584,7 +621,7 @@
+@@ -559,7 +603,7 @@
+ 
+   /* Make a writable copy.  At the same time expand possible dynamic
+      string tokens.  */
+-  copy = expand_dynamic_string_token (l, rpath);
++  copy = expand_dynamic_string_token (l, rpath, GLRO(dl_rpath_prefix));
+   if (copy == NULL)
+     {
+       errstring = N_("cannot create RUNPATH/RPATH copy");
+@@ -584,7 +628,7 @@
        _dl_signal_error (ENOMEM, NULL, NULL, errstring);
      }
  
@@ -105,7 +159,16 @@
  
    /* Free the copied RPATH string.  `fillin_rpath' make own copies if
       necessary.  */
-@@ -783,7 +820,7 @@
+@@ -757,7 +801,7 @@
+ 
+ 	  /* Allocate the necessary memory.  */
+ 	  llp_tmp = (char *) alloca (total + 1);
+-	  llp_tmp = _dl_dst_substitute (l, llp, llp_tmp, 1);
++	  llp_tmp = _dl_dst_substitute (l, llp, llp_tmp, 1, NULL);
+ 	}
+ #else
+       llp_tmp = strdupa (llp);
+@@ -783,7 +827,7 @@
  
        (void) fillin_rpath (llp_tmp, env_path_list.dirs, ":;",
  			   INTUSE(__libc_enable_secure), "LD_LIBRARY_PATH",
@@ -114,10 +177,20 @@
  
        if (env_path_list.dirs[0] == NULL)
  	{
-
---- a/elf/dl-support.c	2009-05-21 00:47:14.000000000 +0300
-+++ b/elf/dl-support.c	2009-12-31 14:51:27.000000000 +0200
-@@ -57,6 +57,9 @@
+@@ -2180,7 +2224,7 @@
+     {
+       /* The path may contain dynamic string tokens.  */
+       realname = (loader
+-		  ? expand_dynamic_string_token (loader, name)
++		  ? expand_dynamic_string_token (loader, name, NULL)
+ 		  : local_strdup (name));
+       if (realname == NULL)
+ 	fd = -1;
+Index: libc/elf/dl-support.c
+===================================================================
+--- libc/elf/dl-support.c	(revision 13872)
++++ libc/elf/dl-support.c	(working copy)
+@@ -56,6 +56,9 @@
     ignored.  */
  const char *_dl_inhibit_rpath;
  
@@ -127,9 +200,11 @@
  /* The map for the object we will profile.  */
  struct link_map *_dl_profile_map;
  
---- a/elf/rtld.c	2009-12-31 14:22:35.000000000 +0200
-+++ b/elf/rtld.c	2009-12-31 14:51:27.000000000 +0200
-@@ -978,6 +978,15 @@
+Index: libc/elf/rtld.c
+===================================================================
+--- libc/elf/rtld.c	(revision 13872)
++++ libc/elf/rtld.c	(working copy)
+@@ -977,6 +977,15 @@
  	    _dl_argc -= 2;
  	    INTUSE(_dl_argv) += 2;
  	  }
@@ -145,17 +220,18 @@
  	else if (! strcmp (INTUSE(_dl_argv)[1], "--audit") && _dl_argc > 2)
  	  {
  	    process_dl_audit (INTUSE(_dl_argv)[2]);
-@@ -1019,6 +1028,7 @@
+@@ -1010,6 +1019,7 @@
                          object we can handle\n\
    --library-path PATH   use given PATH instead of content of the environment\n\
                          variable LD_LIBRARY_PATH\n\
 +  --rpath-prefix PREFIX add PREFIX to every RUNPATH and RPATH component\n\
    --inhibit-rpath LIST  ignore RUNPATH and RPATH information in object names\n\
-                         in LIST\n\
-   --argv0 STRING        use STRING as argv[0]\n");
-
---- a/sysdeps/generic/ldsodefs.h	2009-05-21 00:46:48.000000000 +0300
-+++ b/sysdeps/generic/ldsodefs.h	2009-12-31 14:54:38.000000000 +0200
+                         in LIST\n");
+ 
+Index: libc/sysdeps/generic/ldsodefs.h
+===================================================================
+--- libc/sysdeps/generic/ldsodefs.h	(revision 13872)
++++ libc/sysdeps/generic/ldsodefs.h	(working copy)
 @@ -666,6 +666,12 @@
  
    /* 0 if internal pointer values should not be guarded, 1 if they should.  */
@@ -169,4 +245,39 @@
  };
  # define __rtld_global_attribute__
  # ifdef IS_IN_rtld
-
+@@ -1046,7 +1052,8 @@
+ 
+ /* Substitute DST values.  */
+ extern char *_dl_dst_substitute (struct link_map *l, const char *name,
+-				 char *result, int is_path) attribute_hidden;
++				 char *result, int is_path,
++				 const char *rpath_prefix) attribute_hidden;
+ 
+ /* Check validity of the caller.  */
+ extern int _dl_check_caller (const void *caller, enum allowmask mask)
+Index: libc/elf/dl-open.c
+===================================================================
+--- libc/elf/dl-open.c	(revision 13872)
++++ libc/elf/dl-open.c	(working copy)
+@@ -274,7 +274,7 @@
+       new_file = (char *) alloca (required + 1);
+ 
+       /* Generate the new file name.  */
+-      _dl_dst_substitute (call_map, file, new_file, 0);
++      _dl_dst_substitute (call_map, file, new_file, 0, NULL);
+ 
+       /* If the substitution failed don't try to load.  */
+       if (*new_file == '\0')
+Index: libc/elf/dl-deps.c
+===================================================================
+--- libc/elf/dl-deps.c	(revision 13872)
++++ libc/elf/dl-deps.c	(working copy)
+@@ -117,7 +117,7 @@
+ 	__newp = (char *) alloca (DL_DST_REQUIRED (l, __str, strlen (__str),  \
+ 						   __dst_cnt));		      \
+ 									      \
+-	__result = _dl_dst_substitute (l, __str, __newp, 0);		      \
++	__result = _dl_dst_substitute (l, __str, __newp, 0, NULL);	      \
+ 									      \
+ 	if (*__result == '\0')						      \
+ 	  {								      \
-- 
1.7.9.1


_______________________________________________
Scratchbox-devel mailing list
[email protected]
http://lists.scratchbox.org/cgi-bin/mailman/listinfo/scratchbox-devel

Reply via email to