diff mbox

Fix LTO handling of ELFOSABI_NONE vs. ELFOSABI_LINUX objects

Message ID 20100707181148.GF20208@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek July 7, 2010, 6:11 p.m. UTC
Hi!

As reported by Honza on IRC, lto fails when mixing ELFOSABI_LINUX *.o files
with ELFOSABI_NONE *.o files.
The latter is what has been used on Linux until recently, ELFOSABI_LINUX is
only used when the object uses some GNU specific ELF features like
STB_GNU_UNIQUE or STT_GNU_IFUNC.

The following patch allows merging those two, with the result being
ELFOSABI_LINUX.

Bootstrapped/regtested on x86_64-linux and i686-linux, tested by Honza on
Mozilla or where he was seeing the failure.  Ok for trunk?

2010-07-07  Jakub Jelinek  <jakub@redhat.com>

	* lto-elf.c (ELFOSABI_NONE, ELFOSABI_LINUX): Define if not defined.
	(validate_file): Allow merging of ELFOSABI_NONE with ELFOSABI_LINUX
	objects.


	Jakub

Comments

Diego Novillo July 7, 2010, 6:17 p.m. UTC | #1
On Wed, Jul 7, 2010 at 18:11, Jakub Jelinek <jakub@redhat.com> wrote:

> 2010-07-07  Jakub Jelinek  <jakub@redhat.com>
>
>        * lto-elf.c (ELFOSABI_NONE, ELFOSABI_LINUX): Define if not defined.
>        (validate_file): Allow merging of ELFOSABI_NONE with ELFOSABI_LINUX
>        objects.

OK with

> +  else
> +    {
> +      char elf_ident_buf[EI_NIDENT];
> +
> +      memcpy (elf_ident_buf, elf_ident,
> +             sizeof elf_ident_buf);

Can be merged into one line.


Diego.
diff mbox

Patch

--- gcc/lto/lto-elf.c.jj	2010-05-25 11:27:37.000000000 +0200
+++ gcc/lto/lto-elf.c	2010-07-06 18:25:43.000000000 +0200
@@ -38,6 +38,13 @@  along with GCC; see the file COPYING3.  
 # define EM_SPARC32PLUS 18
 #endif
 
+#ifndef ELFOSABI_NONE
+# define ELFOSABI_NONE 0
+#endif
+#ifndef ELFOSABI_LINUX
+# define ELFOSABI_LINUX 3
+#endif
+
 
 /* Handle opening elf files on hosts, such as Windows, that may use 
    text file handling that will break binary access.  */
@@ -519,10 +526,29 @@  validate_file (lto_elf_file *elf_file)
       memcpy (cached_file_attrs.elf_ident, elf_ident,
 	      sizeof cached_file_attrs.elf_ident);
     }
+  else
+    {
+      char elf_ident_buf[EI_NIDENT];
+
+      memcpy (elf_ident_buf, elf_ident,
+	      sizeof elf_ident_buf);
+
+      if (elf_ident_buf[EI_OSABI] != cached_file_attrs.elf_ident[EI_OSABI])
+	{
+	  /* Allow mixing ELFOSABI_NONE with ELFOSABI_LINUX, with the result
+	     ELFOSABI_LINUX.  */
+	  if (elf_ident_buf[EI_OSABI] == ELFOSABI_NONE
+	      && cached_file_attrs.elf_ident[EI_OSABI] == ELFOSABI_LINUX)
+	    elf_ident_buf[EI_OSABI] = cached_file_attrs.elf_ident[EI_OSABI];
+	  else if (elf_ident_buf[EI_OSABI] == ELFOSABI_LINUX
+		   && cached_file_attrs.elf_ident[EI_OSABI] == ELFOSABI_NONE)
+	    cached_file_attrs.elf_ident[EI_OSABI] = elf_ident_buf[EI_OSABI];
+	}
 
-  if (memcmp (elf_ident, cached_file_attrs.elf_ident,
-	      sizeof cached_file_attrs.elf_ident))
-    return false;
+      if (memcmp (elf_ident_buf, cached_file_attrs.elf_ident,
+		  sizeof cached_file_attrs.elf_ident))
+	return false;
+    }
 
   /* Check that the input file is a relocatable object file with the correct
      architecture.  */