This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] Add FreeBSD header to elf64-sparc
- From: Roy Marples <uberlord at gentoo dot org>
- To: binutils at sourceware dot org
- Date: Mon, 16 Oct 2006 08:00:58 +0100
- Subject: [PATCH] Add FreeBSD header to elf64-sparc
Hi List
While making Gentoo/FreeBSD on Sparc64 I noticed that vanilla binutils does
not add FreeBSD to the ELF header. Attached is a patch that enables this for
FreeBSD targets.
Not sure if kfreebsd belongs there too, but it seemed sensible.
Thanks
--
Roy Marples <uberlord@gentoo.org>
Gentoo/Linux/FreeBSD Developer (baselayout, networking)
diff -ur binutils-2.17.orig/bfd/config.bfd binutils-2.17/bfd/config.bfd
--- binutils-2.17.orig/bfd/config.bfd 2006-10-11 22:42:43 +0100
+++ binutils-2.17/bfd/config.bfd 2006-10-11 22:47:07 +0100
@@ -173,7 +173,11 @@
targ_defvec=bfd_elf32_ia64_hpux_big_vec
targ_selvecs="bfd_elf64_ia64_hpux_big_vec"
;;
- sparc64-*-freebsd* | sparc64-*-netbsd* | sparc64-*-openbsd* | sparc64-*-kfreebsd*-gnu)
+ sparc64-*-freebsd* | sparc64-*-kfreebsd*-gnu)
+ targ_defvec=bfd_elf64_sparc_freebsd_vec
+ targ_selvecs="bfd_elf32_sparc_vec sunos_big_vec"
+ ;;
+ sparc64-*-netbsd* | sparc64-*-openbsd*)
targ_defvec=bfd_elf64_sparc_vec
targ_selvecs="bfd_elf32_sparc_vec sunos_big_vec"
;;
diff -ur binutils-2.17.orig/bfd/configure binutils-2.17/bfd/configure
--- binutils-2.17.orig/bfd/configure 2006-10-11 22:42:43 +0100
+++ binutils-2.17/bfd/configure 2006-10-11 22:45:31 +0100
@@ -13192,6 +13192,7 @@
bfd_elf64_sh64lnbsd_vec) tb="$tb elf64-sh64.lo elf64.lo $elf" target_size=64 ;;
bfd_elf64_sh64nbsd_vec) tb="$tb elf64-sh64.lo elf64.lo $elf" target_size=64 ;;
bfd_elf64_sparc_vec) tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
+ bfd_elf64_sparc_freebsd_vec) tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
bfd_elf64_tradbigmips_vec) tb="$tb elf64-mips.lo elf64.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
bfd_elf64_tradlittlemips_vec) tb="$tb elf64-mips.lo elf64.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
bfd_elf64_x86_64_vec) tb="$tb elf64-x86-64.lo elf64.lo $elf"; target_size=64 ;;
diff -ur binutils-2.17.orig/bfd/configure.in binutils-2.17/bfd/configure.in
--- binutils-2.17.orig/bfd/configure.in 2006-10-11 22:42:43 +0100
+++ binutils-2.17/bfd/configure.in 2006-10-11 22:45:31 +0100
@@ -705,6 +705,7 @@
bfd_elf64_sh64lnbsd_vec) tb="$tb elf64-sh64.lo elf64.lo $elf" target_size=64 ;;
bfd_elf64_sh64nbsd_vec) tb="$tb elf64-sh64.lo elf64.lo $elf" target_size=64 ;;
bfd_elf64_sparc_vec) tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
+ bfd_elf64_sparc_freebsd_vec) tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
bfd_elf64_tradbigmips_vec) tb="$tb elf64-mips.lo elf64.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
bfd_elf64_tradlittlemips_vec) tb="$tb elf64-mips.lo elf64.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
bfd_elf64_x86_64_vec) tb="$tb elf64-x86-64.lo elf64.lo $elf"; target_size=64 ;;
diff -ur binutils-2.17.orig/bfd/elf64-sparc.c binutils-2.17/bfd/elf64-sparc.c
--- binutils-2.17.orig/bfd/elf64-sparc.c 2006-10-11 22:42:43 +0100
+++ binutils-2.17/bfd/elf64-sparc.c 2006-10-11 22:45:31 +0100
@@ -901,3 +901,32 @@
#define elf_backend_plt_alignment 8
#include "elf64-target.h"
+
+/* FreeBSD support */
+#undef TARGET_BIG_SYM
+#define TARGET_BIG_SYM bfd_elf64_sparc_freebsd_vec
+#undef TARGET_BIG_NAME
+#define TARGET_BIG_NAME "elf64-sparc-freebsd"
+
+/* The kernel recognizes executables as valid only if they carry a
+ "FreeBSD" label in the ELF header. So we put this label on all
+ executables and (for simplicity) also all other object files. */
+static void
+elf_sparc_fbsd_post_process_headers (bfd *abfd,
+ struct bfd_link_info *info ATTRIBUTE_UNUSED)
+{
+ Elf_Internal_Ehdr *i_ehdrp;
+
+ i_ehdrp = elf_elfheader (abfd);
+
+ /* Put an ABI label supported by FreeBSD >= 4.1 */
+ i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
+}
+
+#undef elf_backend_post_process_headers
+#define elf_backend_post_process_headers elf_sparc_fbsd_post_process_headers
+#undef elf64_bed
+#define elf64_bed elf64_sparc_fbsd_bed
+
+#include "elf64-target.h"
+
diff -ur binutils-2.17.orig/bfd/targets.c binutils-2.17/bfd/targets.c
--- binutils-2.17.orig/bfd/targets.c 2006-10-11 22:42:43 +0100
+++ binutils-2.17/bfd/targets.c 2006-10-11 22:45:31 +0100
@@ -666,6 +666,7 @@
extern const bfd_target bfd_elf64_sh64lnbsd_vec;
extern const bfd_target bfd_elf64_sh64nbsd_vec;
extern const bfd_target bfd_elf64_sparc_vec;
+extern const bfd_target bfd_elf64_sparc_freebsd_vec;
extern const bfd_target bfd_elf64_tradbigmips_vec;
extern const bfd_target bfd_elf64_tradlittlemips_vec;
extern const bfd_target bfd_elf64_x86_64_vec;
@@ -982,6 +983,7 @@
&bfd_elf64_sh64lin_vec,
&bfd_elf64_sh64blin_vec,
&bfd_elf64_sparc_vec,
+ &bfd_elf64_sparc_freebsd_vec,
&bfd_elf64_tradbigmips_vec,
&bfd_elf64_tradlittlemips_vec,
&bfd_elf64_x86_64_vec,
diff -ur binutils-2.17.orig/gas/config/tc-sparc.c binutils-2.17/gas/config/tc-sparc.c
--- binutils-2.17.orig/gas/config/tc-sparc.c 2006-10-11 22:42:43 +0100
+++ binutils-2.17/gas/config/tc-sparc.c 2006-10-11 22:45:31 +0100
@@ -339,7 +339,7 @@
#endif
#ifdef OBJ_ELF
- return sparc_arch_size == 64 ? "elf64-sparc" : "elf32-sparc";
+ return sparc_arch_size == 64 ? ELF64_TARGET_FORMAT : ELF_TARGET_FORMAT;
#endif
abort ();
@@ -547,12 +547,12 @@
{
if (sparc_arch_size == 32)
{
- if (strcmp (*l, "elf32-sparc") == 0)
+ if (strcmp (*l, ELF_TARGET_FORMAT) == 0)
break;
}
else
{
- if (strcmp (*l, "elf64-sparc") == 0)
+ if (strcmp (*l, ELF64_TARGET_FORMAT) == 0)
break;
}
}
diff -ur binutils-2.17.orig/gas/config/tc-sparc.h binutils-2.17/gas/config/tc-sparc.h
--- binutils-2.17.orig/gas/config/tc-sparc.h 2006-10-11 22:42:43 +0100
+++ binutils-2.17/gas/config/tc-sparc.h 2006-10-11 22:45:31 +0100
@@ -31,6 +31,18 @@
#define TARGET_ARCH bfd_arch_sparc
+#ifdef TE_FreeBSD
+#define ELF_TARGET_FORMAT "elf32-sparc-freebsd"
+#define ELF64_TARGET_FORMAT "elf64-sparc-freebsd"
+#endif
+
+#ifndef ELF_TARGET_FORMAT
+#define ELF_TARGET_FORMAT "elf32-sparc"
+#endif
+#ifndef ELF64_TARGET_FORMAT
+#define ELF64_TARGET_FORMAT "elf64-sparc"
+#endif
+
extern const char *sparc_target_format PARAMS ((void));
#define TARGET_FORMAT sparc_target_format ()
diff -ur binutils-2.17.orig/ld/emulparams/elf64_sparc_fbsd.sh binutils-2.17/ld/emulparams/elf64_sparc_fbsd.sh
--- binutils-2.17.orig/ld/emulparams/elf64_sparc_fbsd.sh 2006-10-11 22:42:43 +0100
+++ binutils-2.17/ld/emulparams/elf64_sparc_fbsd.sh 2006-10-11 22:45:31 +0100
@@ -1,2 +1,4 @@
. ${srcdir}/emulparams/elf64_sparc.sh
. ${srcdir}/emulparams/elf_fbsd.sh
+
+OUTPUT_FORMAT="elf64-sparc-freebsd"