This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch to recognize the new ARM ELF_OSABI value...


1999-08-09  Scott Bambrough  <scottb@netwinder.org>

	* elf/elf.h: Added definition of ELFOSABI_ARM.
        * elf/dl-load.c (_dl_map_object_from_fd): Use VALID_ELF_HEADER, 
	VALID_ELF_OSABI, VALID_ELF_ABIVERSION to decide whether an 
	object's header and ABI values are acceptable.
        (VALID_ELF_HEADER): New macro; provide default definition.
        (VALID_ELF_OSABI): New macro; provide default definition.
        (VALID_ELF_ABIVERSION): New macro; provide default definition.
        * sysdeps/arm/dl-machine.h Define ARM specific versions of 
	VALID_ELF_HEADER, VALID_ELF_OSABI, VALID_ELF_ABIVERSION.

These patches are similar to the one Phil submitted.  They don't
penalize other platforms at runtime, since the checks are almost the
same for other platforms.  A default version is provided as well, so
every platform is not required to define these values.
Index: elf/dl-load.c
===================================================================
RCS file: /glibc/cvsfiles/libc/elf/dl-load.c,v
retrieving revision 1.103.2.1
diff -u -r1.103.2.1 dl-load.c
--- dl-load.c	1999/06/17 10:41:12	1.103.2.1
+++ dl-load.c	1999/08/09 21:13:09
@@ -655,6 +655,11 @@
   /* This is the expected ELF header.  */
 #define ELF32_CLASS ELFCLASS32
 #define ELF64_CLASS ELFCLASS64
+#if !defined VALID_ELF_HEADER
+#  define VALID_ELF_HEADER(hdr,exp,size) (memcmp(hdr,exp,size) == 0) 
+#  define VALID_ELF_OSABI(osabi) (osabi == ELFOSABI_SYSV) 
+#  define VALID_ELF_ABIVERSION(ver) (ver == 0) 
+#endif
   static const unsigned char expected[EI_PAD] =
   {
     [EI_MAG0] = ELFMAG0,
@@ -721,7 +726,7 @@
   header = (void *) readbuf;
 
   /* Check the header for basic validity.  */
-  if (memcmp (header->e_ident, expected, EI_PAD) != 0)
+  if (!VALID_ELF_HEADER(header->e_ident, expected, EI_PAD))
     {
       /* Something is wrong.  */
       if (*(Elf32_Word *) &header->e_ident !=
@@ -746,10 +751,10 @@
 	LOSE (0, "ELF file version ident not " STRING(EV_CURRENT));
       /* XXX We should be able so set system specific versions which are
 	 allowed here.  */
-      if (header->e_ident[EI_OSABI] != ELFOSABI_SYSV)
-	LOSE (0, "ELF file OS ABI not " STRING(ELFOSABI_SYSV));
-      if (header->e_ident[EI_ABIVERSION] != 0)
-	LOSE (0, "ELF file ABI version not 0");
+      if (!VALID_ELF_OSABI(header->e_ident[EI_OSABI]))
+	LOSE (0, "ELF file OS ABI invalid.");
+      if (!VALID_ELF_ABIVERSION(header->e_ident[EI_ABIVERSION]))
+	LOSE (0, "ELF file ABI version invalid.");
       LOSE (0, "internal error");
     }
 
Index: elf/elf.h
===================================================================
RCS file: /glibc/cvsfiles/libc/elf/elf.h,v
retrieving revision 1.47
diff -u -r1.47 elf.h
--- elf.h	1999/04/12 09:01:08	1.47
+++ elf.h	1999/08/09 21:13:10
@@ -140,6 +140,7 @@
 #define EI_OSABI	7		/* OS ABI identification */
 #define ELFOSABI_SYSV		0	/* UNIX System V ABI */
 #define ELFOSABI_HPUX		1	/* HP-UX */
+#define ELFOSABI_ARM		97	/* ARM */
 #define ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
 
 #define EI_ABIVERSION	8		/* ABI version */
Index: sysdeps/arm/dl-machine.h
===================================================================
RCS file: /glibc/cvsfiles/libc/sysdeps/arm/dl-machine.h,v
retrieving revision 1.12.2.1
diff -u -r1.12.2.1 dl-machine.h
--- dl-machine.h	1999/06/13 09:23:47	1.12.2.1
+++ dl-machine.h	1999/08/09 21:13:23
@@ -26,6 +26,15 @@
 
 #include <assert.h>
 
+#define VALID_ELF_ABIVERSION(ver)	(ver == 0) 
+#define VALID_ELF_OSABI(osabi) \
+  ((osabi == ELFOSABI_SYSV) || (osabi == ELFOSABI_ARM)) 
+#define VALID_ELF_HEADER(hdr,exp,size) ( \
+  memcmp(hdr,exp,size-2) == 0 && \
+  VALID_ELF_OSABI(hdr[EI_OSABI]) && \
+  VALID_ELF_ABIVERSION(hdr[EI_ABIVERSION]) \
+)
+
 /* Return nonzero iff E_MACHINE is compatible with the running host.  */
 static inline int __attribute__ ((unused))
 elf_machine_matches_host (Elf32_Half e_machine)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]