Advice on the prefered way to brand ELF binaries as needed on FreeBSD
David O'Brien
obrien@FreeBSD.org
Tue Apr 11 20:35:00 GMT 2000
FreeBSD brands all ELF files so the image loader knows what type of
binary it is and use the proper compatibility layer if the binary is not
a native FreeBSD one. Current we do it using the 1st patch below. I
have taken a slightly more general approach with the second patch below.
Is this patch OK, or is there another prefered way to do this?
--
-- David (obrien@NUXI.com)
Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.27
diff -u -r1.27 elf.c
--- elf.c 2000/03/27 08:39:12 1.27
+++ elf.c 2000/04/12 03:31:51
@@ -3211,6 +3211,14 @@
for (count = EI_PAD; count < EI_NIDENT; count++)
i_ehdrp->e_ident[count] = 0;
+#ifdef __FreeBSD__
+#define EI_BRAND_OFFSET 8
+ /* FreeBSD brands all ELF binaries so the image loader knows what system
+ call set, etc. to use. */
+ strncpy((char *) &i_ehdrp->e_ident[EI_BRAND_OFFSET], "FreeBSD",
+ EI_NIDENT-EI_BRAND_OFFSET);
+#endif
+
if ((abfd->flags & DYNAMIC) != 0)
i_ehdrp->e_type = ET_DYN;
else if ((abfd->flags & EXEC_P) != 0)
Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.27
diff -u -r1.27 elf.c
--- elf.c 2000/03/27 08:39:12 1.27
+++ elf.c 2000/04/12 03:34:17
@@ -38,6 +38,13 @@
#define ARCH_SIZE 0
#include "elf-bfd.h"
+#define EI_BRAND_OFFSET 8
+#if defined(__FreeBSD__)
+#define BRANDING "FreeBSD"
+#else
+#define BRANDING ""
+#endif
+
static INLINE struct elf_segment_map *make_mapping
PARAMS ((bfd *, asection **, unsigned int, unsigned int, boolean));
static boolean map_sections_to_segments PARAMS ((bfd *));
@@ -3210,6 +3217,11 @@
for (count = EI_PAD; count < EI_NIDENT; count++)
i_ehdrp->e_ident[count] = 0;
+
+ /* Some OS's brands all ELF binaries so the image loader knows what system
+ call set, etc. to use. */
+ strncpy((char *) &i_ehdrp->e_ident[EI_BRAND_OFFSET], BRANDING,
+ EI_NIDENT-EI_BRAND_OFFSET);
if ((abfd->flags & DYNAMIC) != 0)
i_ehdrp->e_type = ET_DYN;
More information about the Binutils
mailing list