public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: scottb <scottb@netwinder.org>
To: libc-hacker@sourceware.cygnus.com
Subject: Patch to recognize the new ARM ELF_OSABI value...
Date: Mon, 09 Aug 1999 14:31:00 -0000	[thread overview]
Message-ID: <37AF4858.18C1A6A@netwinder.org> (raw)

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)

             reply	other threads:[~1999-08-09 14:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-09 14:31 scottb [this message]
1999-08-09 22:13 ` Ulrich Drepper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=37AF4858.18C1A6A@netwinder.org \
    --to=scottb@netwinder.org \
    --cc=libc-hacker@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).