From 73ecf6f6a1f327c9fa3af1fc924d152321aac801 Mon Sep 17 00:00:00 2001
From: Romain Naour <romain.naour@gmail.com>
Date: Fri, 25 Dec 2015 11:42:48 +0100
Subject: [PATCH] add sysroot fix from bug #3049

Always try to prepend the sysroot prefix to absolute filenames first.

http://bugs.gentoo.org/275666
http://sourceware.org/bugzilla/show_bug.cgi?id=10340

Signed-off-by: Sven Rebhan <odinshorse@googlemail.com>
[Romain: rebase on top of 2.26]
Signed-off-by: Romain Naour <romain.naour@gmail.com>
---
 ld/ldfile.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

--- ld/ldfile.c
+++ ld/ldfile.c
@@ -340,18 +340,24 @@
      directory first.  */
   if (!entry->flags.maybe_archive)
     {
-      if (entry->flags.sysrooted && IS_ABSOLUTE_PATH (entry->filename))
+     /* For absolute pathnames, try to always open the file in the
+	 sysroot first. If this fails, try to open the file at the
+	 given location.  */
+     entry->flags.sysrooted = is_sysrooted_pathname (entry->filename);
+     if (!entry->flags.sysrooted && IS_ABSOLUTE_PATH (entry->filename)
+     && ld_sysroot)
 	{
 	  char *name = concat (ld_sysroot, entry->filename,
 			       (const char *) NULL);
 	  if (ldfile_try_open_bfd (name, entry))
 	    {
 	      entry->filename = name;
+	      entry->flags.sysrooted = TRUE;
 	      return TRUE;
 	    }
 	  free (name);
 	}
-      else if (ldfile_try_open_bfd (entry->filename, entry))
+      if (ldfile_try_open_bfd (entry->filename, entry))
 	return TRUE;
 
       if (IS_ABSOLUTE_PATH (entry->filename))
