Bug 3826

Summary: elf_object_p can't tell freebsd object file from standard ELF object file
Product: binutils Reporter: Petr.Salinger
Component: binutilsAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: bug-binutils, hjl.tools
Priority: P2    
Version: 2.18   
Target Milestone: ---   
Host: x86_64-kfreebsd-gnu Target:
Build: Last reconfirmed:

Description Petr.Salinger 2007-01-04 11:42:09 UTC
Hi,

please could  you fixup targ_selvecs for amd64 for freebsd/kfreebsd targets.

As turned out, current targ_selvecs  causes trouble for bi-arch (32/64) toolchain:
" File format is ambiguous. Matching formats:elf32-i386-freebsd elf32-i386.".
So please, could you just drop  "bfd_elf32_i386_vec bfd_elf64_x86_64_vec" from
targ_selvecs.
The extraneous targets have been introduced by (my) patch in bz#2983.

Thanks in advance.

Petr


--- bfd/config.bfd~ 2007-01-04 12:33:27.000000000 +0100
+++ bfd/config.bfd  2007-01-04 12:33:27.000000000 +0100
@@ -577,7 +577,7 @@
     ;;
   x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
     targ_defvec=bfd_elf64_x86_64_freebsd_vec
-    targ_selvecs="bfd_elf32_i386_freebsd_vec i386coff_vec bfd_efi_app_ia32_vec
bfd_elf32_i386_vec bfd_elf64_x86_64_vec"
+    targ_selvecs="bfd_elf32_i386_freebsd_vec i386coff_vec bfd_efi_app_ia32_vec"
     want64=true
     ;;
   x86_64-*-netbsd* | x86_64-*-openbsd*)
Comment 1 H.J. Lu 2007-01-04 14:50:50 UTC
It is a bug in elf_object_p. Since there are

lake:pts/3[29]> readelf -h dump.o
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 09 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - FreeBSD
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          192 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         8
  Section header string table index: 5

elf_object_p should check EI_OSABI.
Comment 2 H.J. Lu 2007-01-04 15:32:33 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2007-01/msg00045.html
Comment 3 Petr.Salinger 2007-01-04 16:34:17 UTC
The extraneous targets might be deleted anyway, they should not be needed.

But the fix for elf_object_p is really welcomed as it allows to create proper
multitarget binutils.

> http://sourceware.org/ml/binutils/2007-01/msg00045.html:
> This patch implements EI_OSABI checking for i386, x86-64 and ia64. 
> I can add it to other arches.

The candidates due to ELFOSABI_FREEBSD  marking would be alpha (same as i386)
and sparc64 (same as x86-64).

Thanks

Petr
Comment 4 H.J. Lu 2007-01-04 16:51:08 UTC
I t(In reply to comment #3)
> The extraneous targets might be deleted anyway, they should not be needed.
> 

I think we should keep the stanard ELF targets by default.
Comment 5 Petr.Salinger 2007-01-04 17:10:44 UTC
> I think we should keep the standard ELF targets by default.

I originally thought in the same way, so I included them in bz#2983.
But currently  alpha, sparc64,  i386  on (k)FreeBSD does not have them,
they are only in x86_64 due to bz#2983.
Comment 6 H.J. Lu 2007-01-04 17:34:39 UTC
(In reply to comment #5)
> > I think we should keep the standard ELF targets by default.
> 
> I originally thought in the same way, so I included them in bz#2983.
> But currently  alpha, sparc64,  i386  on (k)FreeBSD does not have them,
> they are only in x86_64 due to bz#2983.
> 

The standard ELF target is always built. ld/configure.tgt has

i[3-7]86-*-freebsd* | i[3-7]86-*-kfreebsd*-gnu)
                        targ_emul=elf_i386_fbsd
                        targ_extra_emuls="elf_i386 i386bsd" ;;
                                          ^^^^^^^^

Comment 7 Petr.Salinger 2007-01-04 19:14:54 UTC
> The standard ELF target is always built. ld/configure.tgt has

I have been refering to bfd/config.bfd, file where I wanted to modify 
targ_selvecs. It contains

i[3-7]86-*-freebsd* | i[3-7]86-*-kfreebsd*-gnu)
    targ_defvec=bfd_elf32_i386_freebsd_vec
    targ_selvecs=i386coff_vec
Comment 8 H.J. Lu 2007-01-04 19:52:06 UTC
(In reply to comment #7)
> > The standard ELF target is always built. ld/configure.tgt has
> 
> I have been refering to bfd/config.bfd, file where I wanted to modify 
> targ_selvecs. It contains
> 
> i[3-7]86-*-freebsd* | i[3-7]86-*-kfreebsd*-gnu)
>     targ_defvec=bfd_elf32_i386_freebsd_vec
>     targ_selvecs=i386coff_vec

It doesn't work due to ld. I got

[hjl@gnu-2 ld]$ ./ld-new -V
GNU ld version 2.17.50 20070104
  Supported emulations:
   elf_x86_64_fbsd
   elf_i386_fbsd
   elf_x86_64
   elf_i386
[hjl@gnu-2 ld]$ ./ld-new -r -m elf_x86_64 mri.o
./ld-new: target elf64-x86-64 not found
[hjl@gnu-2 ld]$ 

In anycase, it doesn't hurt to ENABLE elf_x86_64 and elf_i386.
Comment 9 Petr.Salinger 2007-01-17 10:27:10 UTC
> In anycase, it doesn't hurt to ENABLE elf_x86_64 and elf_i386.

Currently, it unfortunately hurts "gcc -m32" :-(.

Please, could be possible to either apply patch from
http://sourceware.org/ml/binutils/2007-01/msg00050.html
or delete "bfd_elf32_i386_vec bfd_elf64_x86_64_vec" in bfd/config.bfd.

Thanks

Petr
Comment 10 Aurelien Jarno 2007-03-05 17:07:44 UTC
I have just tried again with the current CVS version. It seems the patch posted 
on http://sourceware.org/ml/binutils/2007-01/msg00045.html has not been 
applied, thus objdump and nm are not working correctly:

  /usr/bin/nm: Matching formats: elf32-i386-freebsd elf32-i386
  /usr/bin/nm: libgcc/32/_lshrdi3_s.o: File format is ambiguous

or

  objdump: /lib32/libpthread.so.0: File format is ambiguous
  objdump: Matching formats: elf32-i386-freebsd elf32-i386

It is actually only necessary to remove elf32-i386. Please find a patch below 
to fix that. I have been able to build a full gcc 4.1 and a full glibc with it. 

Would it be possible to apply it, at least until elf_object_p is fixed?

--- binutils-2.17.20070210cvs.orig/bfd/config.bfd
+++ binutils-2.17.20070210cvs/bfd/config.bfd
@@ -577,7 +577,7 @@
     ;;
   x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
     targ_defvec=bfd_elf64_x86_64_freebsd_vec
-    targ_selvecs="bfd_elf32_i386_freebsd_vec i386coff_vec bfd_efi_app_ia32_vec 
bfd_elf32_i386_vec bfd_elf64_x86_64_vec"
+    targ_selvecs="bfd_elf32_i386_freebsd_vec i386coff_vec bfd_efi_app_ia32_vec 
bfd_elf64_x86_64_vec"
     want64=true
     ;;
   x86_64-*-netbsd* | x86_64-*-openbsd*)


Comment 11 H.J. Lu 2007-03-14 02:53:06 UTC
Fixed by

http://sourceware.org/ml/binutils/2007-03/msg00129.html