binutils problem? WAS [Re: static linking error: ELF binary type "0" not known. Exec format error. Binary file not executable.]

Dimitry Andric dim at FreeBSD.org
Fri Dec 3 23:52:54 UTC 2010


On 2010-12-03 10:58, Anton Shterenlikht wrote:
>>> a.out: ELF 64-bit LSB executable, IA-64, version 1 (SYSV), statically linked, not stripped
...
>> The branding on ia64 is wrong. The executable is not marked as being
>> a FreeBSD executable. It's declared as SYSV, whereas on amd64 it's
>> properly declared as FreeBSD.
>>
>> This is a binutils problem.
...
> Anybody here can explain better what Marcel means
> by "binutils problem", and how to fix it?
>
> I've binutils-2.20.1_3 installed from devel/binutils.

The problem is that our base binutils's BFD library has a custom hack to
'brand' the produced executables, e.g. set the ELF_OSABI field in the
ELF header to ELFOSABI_FREEBSD.

Other arches such as i386, amd64 (x86_64 in binutils land), sparc and
even alpha (!) have had patches sent upstream to do the right thing for
FreeBSD, but not ia64.

If you can, please try the attached patch, which resolves the problem on
the ia64 machine I have tried it on.  It should really be sent upstream
to the binutils people, if there is some interest.

Alternatively, we can shove a similar patch into the binutils port, but
I'm not sure how much the ports people will like that. :)

I think I will apply the same approach to my projects/binutils-2.17
branch (aimed at importing the last GPLv2 binutils version into head).
Having target names clearly defined as elfXX-archname-freebsd is much
easier to deal with.
-------------- next part --------------
diff --git a/bfd/config.bfd b/bfd/config.bfd
index 9b719d8..d2fe23e 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -182,7 +182,12 @@ case "${targ}" in
     targ_defvec=ecoffalpha_little_vec
     want64=true
     ;;
-  ia64*-*-freebsd* | ia64*-*-netbsd* | ia64*-*-linux-* | ia64*-*-elf* | ia64*-*-kfreebsd*-gnu)
+  ia64*-*-freebsd* | ia64*-*-kfreebsd*-gnu)
+    targ_defvec=bfd_elf64_ia64_freebsd_vec
+    targ_selvecs="bfd_elf64_ia64_little_vec bfd_elf64_ia64_big_vec bfd_pei_ia64_vec"
+    want64=true
+    ;;
+  ia64*-*-netbsd* | ia64*-*-linux-* | ia64*-*-elf*)
     targ_defvec=bfd_elf64_ia64_little_vec
     targ_selvecs="bfd_elf64_ia64_big_vec bfd_pei_ia64_vec"
     want64=true
diff --git a/bfd/configure b/bfd/configure
index 278cc1d..ad9dcc9 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -15169,6 +15169,7 @@ do
     bfd_elf64_hppa_linux_vec)	tb="$tb elf64-hppa.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_hppa_vec)		tb="$tb elf64-hppa.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_big_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
+    bfd_elf64_ia64_freebsd_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_hpux_big_vec) tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_little_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_vms_vec)	tb="$tb elf64-ia64.lo elf64.lo vms-lib.lo vms-misc.lo $elf"; target_size=64 ;;
diff --git a/bfd/elfxx-ia64.c b/bfd/elfxx-ia64.c
index d42ad89..5625c44 100644
--- a/bfd/elfxx-ia64.c
+++ b/bfd/elfxx-ia64.c
@@ -6077,6 +6077,26 @@ elfNN_vms_close_and_cleanup (bfd *abfd)
 
 #include "elfNN-target.h"
 
+/* FreeBSD support.  */
+
+#undef  TARGET_LITTLE_SYM
+#define TARGET_LITTLE_SYM		bfd_elfNN_ia64_freebsd_vec
+#undef  TARGET_LITTLE_NAME
+#define TARGET_LITTLE_NAME		"elfNN-ia64-freebsd"
+#undef  TARGET_BIG_SYM
+#undef  TARGET_BIG_NAME
+
+#undef  ELF_OSABI
+#define ELF_OSABI			ELFOSABI_FREEBSD
+
+#undef  elf_backend_post_process_headers
+#define elf_backend_post_process_headers _bfd_elf_set_osabi
+
+#undef  elfNN_bed
+#define elfNN_bed elfNN_ia64_fbsd_bed
+
+#include "elfNN-target.h"
+
 /* HPUX-specific vectors.  */
 
 #undef  TARGET_LITTLE_SYM
diff --git a/bfd/targets.c b/bfd/targets.c
index 3e99754..a642a8d 100644
--- a/bfd/targets.c
+++ b/bfd/targets.c
@@ -697,6 +697,7 @@ extern const bfd_target bfd_elf64_bigmips_vec;
 extern const bfd_target bfd_elf64_hppa_linux_vec;
 extern const bfd_target bfd_elf64_hppa_vec;
 extern const bfd_target bfd_elf64_ia64_big_vec;
+extern const bfd_target bfd_elf64_ia64_freebsd_vec;
 extern const bfd_target bfd_elf64_ia64_hpux_big_vec;
 extern const bfd_target bfd_elf64_ia64_little_vec;
 extern const bfd_target bfd_elf64_ia64_vms_vec;
diff --git a/ld/emulparams/elf64_ia64_fbsd.sh b/ld/emulparams/elf64_ia64_fbsd.sh
index ab7e78f..a7e2675 100644
--- a/ld/emulparams/elf64_ia64_fbsd.sh
+++ b/ld/emulparams/elf64_ia64_fbsd.sh
@@ -4,3 +4,4 @@ unset DATA_ADDR
 unset SMALL_DATA_CTOR
 unset SMALL_DATA_DTOR
 . ${srcdir}/emulparams/elf_fbsd.sh
+OUTPUT_FORMAT="elf64-ia64-freebsd"


More information about the freebsd-current mailing list