File binutils-skip-rpaths.patch of Package binutils

Index: binutils-2.45/ld/emultempl/elf.em
===================================================================
--- binutils-2.45.orig/ld/emultempl/elf.em	2025-07-27 01:00:00.000000000 +0200
+++ binutils-2.45/ld/emultempl/elf.em	2025-10-14 15:49:40.360481868 +0200
@@ -162,6 +162,8 @@ if test x"$LDEMUL_BEFORE_ALLOCATION" !=
   if test x"${ELF_INTERPRETER_NAME}" = x; then
     ELF_INTERPRETER_NAME=NULL
   fi
+
+  libpath_nl=`echo ${NATIVE_LIB_DIRS// /\\\n}`
 fragment <<EOF
 
 /* This is called after the sections have been attached to output
Index: binutils-2.45/ld/ldelf.c
===================================================================
--- binutils-2.45.orig/ld/ldelf.c	2025-07-27 01:00:00.000000000 +0200
+++ binutils-2.45/ld/ldelf.c	2025-10-14 15:49:40.360481868 +0200
@@ -1746,6 +1746,31 @@ ldelf_append_to_separated_string (char *
     }
 }
 
+static int
+ldelf_is_contained (const char *path, const char *dc)
+{
+  while (*dc)
+    {
+      const char *pc = path;
+
+      while (*dc && *pc && *dc == *pc && *dc != '\n'
+            && *pc != ':' && *dc != '=')
+       {
+         dc++;
+         pc++;
+       }
+      if ((*pc == 0 || *pc == ':') && (*dc == '\n' || *dc == '=' || *dc == 0))
+       return 1;
+
+      while (*dc && *dc != '\n')
+       dc++;
+      if (*dc == '\n')
+       dc++;
+    }
+
+  return 0;
+}
+
 /* This is called after the sections have been attached to output
    sections, but before any sizes or addresses have been set.  */
 
@@ -1753,7 +1778,7 @@ void
 ldelf_before_allocation (char **audit, char **depaudit,
 			 const char *default_interpreter_name)
 {
-  const char *rpath;
+  char *rpath;
   asection *sinterp;
   bfd *abfd;
   struct bfd_link_hash_entry *ehdr_start = NULL;
@@ -1807,7 +1832,67 @@ ldelf_before_allocation (char **audit, c
      by dynamic linking.  */
   rpath = command_line.rpath;
   if (rpath == NULL)
-    rpath = (const char *) getenv ("LD_RUN_PATH");
+    rpath = getenv ("LD_RUN_PATH");
+
+  if (rpath != NULL && getenv ("SUSE_IGNORED_RPATHS"))
+    {
+      char *dirs = 0;
+      FILE *ldso = fopen (getenv ("SUSE_IGNORED_RPATHS"), "r");
+      if (ldso)
+       {
+         off_t endcur = 0;
+         fseek (ldso, 0, SEEK_END);
+         endcur = ftell (ldso);
+         fseek (ldso, 0, SEEK_SET);
+         dirs = xmalloc (endcur + 1);
+         if (fread (dirs, 1, endcur, ldso) != (size_t) endcur)
+           {
+             free (dirs);
+             dirs = NULL;
+           }
+	 else
+	   dirs[endcur] = '\0';
+       }
+      if (dirs)
+       {
+         char *cr;
+         rpath = xstrdup (rpath);
+         cr = rpath; /* cursor read */
+
+         while (*cr)
+            {
+             if (ldelf_is_contained (cr, dirs)
+                 || ldelf_is_contained (cr, "$libpath_nl"))
+               {
+                 char *cc = cr, *cw = cr;
+                 while (*cc && *cc != ':')
+                   cc++;
+                 if (*cc == ':')
+                    {
+                     cc++;
+                     for (; *cc; cc++, cw++)
+                       *cw = *cc;
+                    }
+                  else if (cw > rpath)
+                     cw[-1] = 0;
+
+                 *cw = 0;
+               }
+             else
+               {
+                 while (*cr && *cr != ':')
+                   cr++;
+                 if (*cr == ':')
+                   cr++;
+               }
+           }
+         if (*rpath == '\0')
+           {
+             free (rpath);
+             rpath = NULL;
+           }
+       }
+    }
 
   for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
     if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
openSUSE Build Service is sponsored by