* Binary format output
@ 2006-07-14 18:44 Victor Roman Archidona
2006-07-15 6:32 ` Mike Frysinger
0 siblings, 1 reply; 4+ messages in thread
From: Victor Roman Archidona @ 2006-07-14 18:44 UTC (permalink / raw)
To: binutils
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
I'm porting FreeBSD to Gentoo for the Summer of Code project
"Gentoo/FreeBSD for Amd64", and I need a little help about gcc binary
output when compiling files. I was pointed here from gcc-help mailing
list.
I compiled by hand GCC and binutils (2.17), and when I compile some
file the output format is "UNIX - System V". I got this with
`readelf -h program`.
The problem is that I need the default binary output must be "UNIX -
FreeBSD" and for now I can't fix it without help.
BTW, If the output is "UNIX - System V" I can't run static compiled
files, it shall be fixed changing the output behaviour. For example
with the following small C program:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
printf("it works!\n");
exit(EXIT_SUCCESS);
}
root@localhost ~ # gcc -static test.c -o test
root@localhost ~ # readelf -h test | grep "OS/ABI"
OS/ABI: UNIX - System V
root@localhost ~ # ./test
ELF binary type "0" not known.
- - -su: ./test: cannot execute binary file
root@localhost ~ #
If any information is required tell me (such gcc config line, binutils
config line, emulations or BFDs compiled).
As I posted here in other list before pointed to this one, I included
the links for reference:
FreeBSD-Hackers:
http://lists.freebsd.org/pipermail/freebsd-hackers/2006-July/017123.html
GCC-Help: http://gcc.gnu.org/ml/gcc-help/2006-07/msg00134.html
Any input in this topic will be very apreciated.
Thanks for all in advance,
- - --
Victor Roman Archidona
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
iD8DBQFEt+YXQ/ddYKMfqaARAoQjAJ4iI6n8wsjhqR6f1/TwW2LI9LVhiQCfUoZT
OHxLkFfMHYEMSxhwl9m7Npo=
=LrTh
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Binary format output
2006-07-14 18:44 Binary format output Victor Roman Archidona
@ 2006-07-15 6:32 ` Mike Frysinger
2006-07-18 5:01 ` Victor Roman Archidona
0 siblings, 1 reply; 4+ messages in thread
From: Mike Frysinger @ 2006-07-15 6:32 UTC (permalink / raw)
To: binutils; +Cc: Victor Roman Archidona
[-- Attachment #1.1: Type: text/plain, Size: 728 bytes --]
On Friday 14 July 2006 14:44, Victor Roman Archidona wrote:
> I compiled by hand GCC and binutils (2.17), and when I compile some
> file the output format is "UNIX - System V". I got this with
> `readelf -h program`.
>
> The problem is that I need the default binary output must be "UNIX -
> FreeBSD" and for now I can't fix it without help.
freebsd tweaks the stock bfd elf64 code to change the EI_OSABI to
ELFOSABI_FREEBSD ... that way the default 'elf-x86-64' target on
amd64/freebsd systems actually outputs freebsd objects
find attached a patch against cvs head to do this right (i think) ... note
that ive never done any real bfd/gas hacking before, so this could be pretty
wrong/incomplete ;)
-mike
[-- Attachment #1.2: Type: application/pgp-signature, Size: 827 bytes --]
[-- Attachment #2: binutils-x86-64-freebsd.patch --]
[-- Type: text/x-diff, Size: 4200 bytes --]
--- bfd/config.bfd
+++ bfd/config.bfd
@@ -564,8 +564,8 @@ case "${targ}" in
want64=true
;;
x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
- targ_defvec=bfd_elf64_x86_64_vec
- targ_selvecs="bfd_elf32_i386_vec i386coff_vec bfd_efi_app_ia32_vec"
+ targ_defvec=bfd_elf64_x86_64_freebsd_vec
+ targ_selvecs="bfd_elf32_i386_freebsd_vec i386coff_vec bfd_efi_app_ia32_vec"
want64=true
;;
x86_64-*-netbsd* | x86_64-*-openbsd*)
--- bfd/configure.in
+++ bfd/configure.in
@@ -709,6 +709,7 @@ do
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 ;;
+ bfd_elf64_x86_64_freebsd_vec) tb="$tb elf64-x86-64.lo elf64.lo $elf"; target_size=64 ;;
bfd_mmo_vec) tb="$tb mmo.lo" target_size=64 ;;
bfd_powerpc_pe_vec) tb="$tb pe-ppc.lo peigen.lo cofflink.lo" ;;
bfd_powerpc_pei_vec) tb="$tb pei-ppc.lo peigen.lo cofflink.lo" ;;
--- bfd/elf64-x86-64.c
+++ bfd/elf64-x86-64.c
@@ -3710,3 +3710,33 @@ static const struct bfd_elf_special_sect
elf64_x86_64_hash_symbol
#include "elf64-target.h"
+
+/* FreeBSD support. */
+
+#undef TARGET_LITTLE_SYM
+#define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
+#undef TARGET_LITTLE_NAME
+#define TARGET_LITTLE_NAME "elf64-x86-64-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_x86_64_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_x86_64_post_process_headers
+#undef elf64_bed
+#define elf64_bed elf64_x86_64_fbsd_bed
+
+#include "elf64-target.h"
--- bfd/targets.c
+++ bfd/targets.c
@@ -669,6 +669,7 @@ extern const bfd_target bfd_elf64_sparc_
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;
+extern const bfd_target bfd_elf64_x86_64_freebsd_vec;
extern const bfd_target bfd_mmo_vec;
extern const bfd_target bfd_powerpc_pe_vec;
extern const bfd_target bfd_powerpc_pei_vec;
@@ -985,6 +986,7 @@ static const bfd_target * const _bfd_tar
&bfd_elf64_tradbigmips_vec,
&bfd_elf64_tradlittlemips_vec,
&bfd_elf64_x86_64_vec,
+ &bfd_elf64_x86_64_freebsd_vec,
&bfd_mmo_vec,
#endif
&bfd_powerpc_pe_vec,
--- gas/config/tc-i386.c
+++ gas/config/tc-i386.c
@@ -5822,7 +5822,7 @@ md_parse_option (int c, char *arg)
list = bfd_target_list ();
for (l = list; *l != NULL; l++)
- if (strcmp (*l, "elf64-x86-64") == 0)
+ if (strcmp (*l, ELF64_TARGET_FORMAT) == 0)
{
default_arch = "x86_64";
break;
@@ -5978,7 +5978,7 @@ i386_target_format ()
object_64bit = 1;
use_rela_relocations = 1;
}
- return flag_code == CODE_64BIT ? "elf64-x86-64" : ELF_TARGET_FORMAT;
+ return flag_code == CODE_64BIT ? ELF64_TARGET_FORMAT : ELF_TARGET_FORMAT;
}
#endif
default:
--- gas/config/tc-i386.h
+++ gas/config/tc-i386.h
@@ -55,6 +55,7 @@ extern unsigned long i386_mach (void);
#ifdef TE_FreeBSD
#define ELF_TARGET_FORMAT "elf32-i386-freebsd"
+#define ELF64_TARGET_FORMAT "elf64-x86-64-freebsd"
#elif defined (TE_VXWORKS)
#define ELF_TARGET_FORMAT "elf32-i386-vxworks"
#endif
@@ -63,6 +64,10 @@ extern unsigned long i386_mach (void);
#define ELF_TARGET_FORMAT "elf32-i386"
#endif
+#ifndef ELF64_TARGET_FORMAT
+#define ELF64_TARGET_FORMAT "elf64-x86-64"
+#endif
+
#if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
|| defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF))
extern const char *i386_target_format PARAMS ((void));
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Binary format output
2006-07-15 6:32 ` Mike Frysinger
@ 2006-07-18 5:01 ` Victor Roman Archidona
2006-08-09 0:49 ` Mike Frysinger
0 siblings, 1 reply; 4+ messages in thread
From: Victor Roman Archidona @ 2006-07-18 5:01 UTC (permalink / raw)
To: Mike Frysinger; +Cc: binutils
[-- Attachment #1: Type: text/plain, Size: 641 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> Mike Frysinger escribió:
>
> find attached a patch against cvs head to do this right (i think)
> ... note that ive never done any real bfd/gas hacking before, so
> this could be pretty wrong/incomplete ;)
I modified it a bit to set "elf64-x86-64-freebsd" as default ld output
format when using it. The modified patch is attached and the change is
in top of it.
Regards,
- --
Victor Roman Archidona
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
iD8DBQFEvGsGQ/ddYKMfqaARAsMGAJ9rNMXQLo2+ivNNDqpX8XO84mX0wACgjWfz
h5muXGBLLPsxJcK4id5rZhc=
=sR4v
-----END PGP SIGNATURE-----
[-- Attachment #2: binutils-x86-64-freebsd.patch --]
[-- Type: text/plain, Size: 4404 bytes --]
--- ld/emulparams/elf_x86_64_fbsd.sh
+++ ld/emulparams/elf_x86_64_fbsd.sh
@@ -1,2 +1,4 @@
. ${srcdir}/emulparams/elf_x86_64.sh
. ${srcdir}/emulparams/elf_fbsd.sh
+
+OUTPUT_FORMAT="elf64-x86-64-freebsd"
--- bfd/config.bfd
+++ bfd/config.bfd
@@ -564,8 +564,8 @@ case "${targ}" in
want64=true
;;
x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
- targ_defvec=bfd_elf64_x86_64_vec
- targ_selvecs="bfd_elf32_i386_vec i386coff_vec bfd_efi_app_ia32_vec"
+ targ_defvec=bfd_elf64_x86_64_freebsd_vec
+ targ_selvecs="bfd_elf32_i386_freebsd_vec i386coff_vec bfd_efi_app_ia32_vec"
want64=true
;;
x86_64-*-netbsd* | x86_64-*-openbsd*)
--- bfd/configure.in
+++ bfd/configure.in
@@ -709,6 +709,7 @@ do
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 ;;
+ bfd_elf64_x86_64_freebsd_vec) tb="$tb elf64-x86-64.lo elf64.lo $elf"; target_size=64 ;;
bfd_mmo_vec) tb="$tb mmo.lo" target_size=64 ;;
bfd_powerpc_pe_vec) tb="$tb pe-ppc.lo peigen.lo cofflink.lo" ;;
bfd_powerpc_pei_vec) tb="$tb pei-ppc.lo peigen.lo cofflink.lo" ;;
--- bfd/elf64-x86-64.c
+++ bfd/elf64-x86-64.c
@@ -3710,3 +3710,33 @@ static const struct bfd_elf_special_sect
elf64_x86_64_hash_symbol
#include "elf64-target.h"
+
+/* FreeBSD support. */
+
+#undef TARGET_LITTLE_SYM
+#define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
+#undef TARGET_LITTLE_NAME
+#define TARGET_LITTLE_NAME "elf64-x86-64-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_x86_64_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_x86_64_post_process_headers
+#undef elf64_bed
+#define elf64_bed elf64_x86_64_fbsd_bed
+
+#include "elf64-target.h"
--- bfd/targets.c
+++ bfd/targets.c
@@ -669,6 +669,7 @@ extern const bfd_target bfd_elf64_sparc_
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;
+extern const bfd_target bfd_elf64_x86_64_freebsd_vec;
extern const bfd_target bfd_mmo_vec;
extern const bfd_target bfd_powerpc_pe_vec;
extern const bfd_target bfd_powerpc_pei_vec;
@@ -985,6 +986,7 @@ static const bfd_target * const _bfd_tar
&bfd_elf64_tradbigmips_vec,
&bfd_elf64_tradlittlemips_vec,
&bfd_elf64_x86_64_vec,
+ &bfd_elf64_x86_64_freebsd_vec,
&bfd_mmo_vec,
#endif
&bfd_powerpc_pe_vec,
--- gas/config/tc-i386.c
+++ gas/config/tc-i386.c
@@ -5822,7 +5822,7 @@ md_parse_option (int c, char *arg)
list = bfd_target_list ();
for (l = list; *l != NULL; l++)
- if (strcmp (*l, "elf64-x86-64") == 0)
+ if (strcmp (*l, ELF64_TARGET_FORMAT) == 0)
{
default_arch = "x86_64";
break;
@@ -5978,7 +5978,7 @@ i386_target_format ()
object_64bit = 1;
use_rela_relocations = 1;
}
- return flag_code == CODE_64BIT ? "elf64-x86-64" : ELF_TARGET_FORMAT;
+ return flag_code == CODE_64BIT ? ELF64_TARGET_FORMAT : ELF_TARGET_FORMAT;
}
#endif
default:
--- gas/config/tc-i386.h
+++ gas/config/tc-i386.h
@@ -55,6 +55,7 @@ extern unsigned long i386_mach (void);
#ifdef TE_FreeBSD
#define ELF_TARGET_FORMAT "elf32-i386-freebsd"
+#define ELF64_TARGET_FORMAT "elf64-x86-64-freebsd"
#elif defined (TE_VXWORKS)
#define ELF_TARGET_FORMAT "elf32-i386-vxworks"
#endif
@@ -63,6 +64,10 @@ extern unsigned long i386_mach (void);
#define ELF_TARGET_FORMAT "elf32-i386"
#endif
+#ifndef ELF64_TARGET_FORMAT
+#define ELF64_TARGET_FORMAT "elf64-x86-64"
+#endif
+
#if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
|| defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF))
extern const char *i386_target_format PARAMS ((void));
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Binary format output
2006-07-18 5:01 ` Victor Roman Archidona
@ 2006-08-09 0:49 ` Mike Frysinger
0 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2006-08-09 0:49 UTC (permalink / raw)
To: binutils; +Cc: Victor Roman Archidona
[-- Attachment #1: Type: text/plain, Size: 568 bytes --]
On Tuesday 18 July 2006 01:01, Victor Roman Archidona wrote:
> > Mike Frysinger escribió:
> >
> > find attached a patch against cvs head to do this right (i think)
> > ... note that ive never done any real bfd/gas hacking before, so
> > this could be pretty wrong/incomplete ;)
>
> I modified it a bit to set "elf64-x86-64-freebsd" as default ld output
> format when using it. The modified patch is attached and the change is
> in top of it.
looks like this patch was submitted/merged for us ;)
http://sourceware.org/bugzilla/show_bug.cgi?id=2983
-mike
[-- Attachment #2: Type: application/pgp-signature, Size: 827 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-08-09 0:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-14 18:44 Binary format output Victor Roman Archidona
2006-07-15 6:32 ` Mike Frysinger
2006-07-18 5:01 ` Victor Roman Archidona
2006-08-09 0:49 ` Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).