All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <Ian.Campbell@XenSource.com>
To: Horms <horms@verge.net.au>
Cc: Jimi Xenidis <jimix@watson.ibm.com>,
	xen-devel <xen-devel@lists.xensource.com>,
	Alex Williamson <alex.williamson@hp.com>,
	Hollis Blanchard <hollisb@us.ibm.com>
Subject: Re: [POWERPC/IA64] Updates required due to loader changes
Date: Fri, 25 Aug 2006 10:42:25 +0100	[thread overview]
Message-ID: <1156498945.12949.180.camel@localhost.localdomain> (raw)
In-Reply-To: <20060825032151.C2647340AE@koto.vergenet.net>

On Fri, 2006-08-25 at 12:21 +0900, Horms wrote:
> On Thu, 24 Aug 2006 15:29:48 -0500, Hollis Blanchard wrote:
> > On Thu, 2006-08-24 at 14:16 -0600, Alex Williamson wrote:
> >> 
> >> diff -r d5eb5205ff35 tools/xcutils/readnotes.c
> >> --- a/tools/xcutils/readnotes.c       Thu Aug 24 16:25:49 2006 +0100
> >> +++ b/tools/xcutils/readnotes.c       Thu Aug 24 14:12:45 2006 -0600
> >> @@ -22,7 +22,7 @@ typedef Elf32_Nhdr Elf_Nhdr;
> >>  typedef Elf32_Nhdr Elf_Nhdr;
> >>  typedef Elf32_Half Elf_Half;
> >>  typedef Elf32_Word Elf_Word;
> >> -#elif defined(__x86_64__)
> >> +#elif defined(__x86_64__) || defined(__ia64__)
> >>  typedef Elf64_Ehdr Elf_Ehdr;
> >>  typedef Elf64_Nhdr Elf_Nhdr;
> >>  typedef Elf64_Half Elf_Half;
> > 
> > Are we doing this again? Ian, please use ELFSIZE, as seen in the
> > following files:
> >        tools/libxc/xg_private.h
> >        tools/libxc/xc_elf.h
> >        tools/libxc/xc_load_elf.c
> >        config/powerpc64.mk
> > 
> 
> Is the patch below what you had in mind?

Nearly, we need to define ELFSIZE if it isn't already since not all
architectures define it.

I checked in the below. I got rid of Elf_Ehdr while I was there since it
is only used the e_ident field which is unsigned char [] for both
ELFSIZEs. As it happens all the remaining types are the same on 32 and
64 but nevermind...

Ian.

changeset:   11256:9091331dfb353212781622f3c9020492cb049178
tag:         tip
user:        Ian Campbell <ian.campbell@xensource.com>
date:        Fri Aug 25 10:39:24 2006 +0100
files:       tools/xcutils/readnotes.c
description:
[TOOLS] Use ELFSIZE to pick the ELF structures to use in readnotes.c

We can remove Elf_Ehdr since it is only used for e_ident which is an
unsigned char array.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>


diff -r 23a0a408edb9f0675eaec0493c9063c19a14b9cb -r 9091331dfb353212781622f3c9020492cb049178 tools/xcutils/readnotes.c
--- a/tools/xcutils/readnotes.c	Fri Aug 25 10:06:24 2006 +0100
+++ b/tools/xcutils/readnotes.c	Fri Aug 25 10:39:24 2006 +0100
@@ -17,18 +17,25 @@
 #define ELFNOTE_DESC(_n_) (ELFNOTE_NAME(_n_) + (((_n_)->n_namesz+3)&~3))
 #define ELFNOTE_NEXT(_n_) (ELFNOTE_DESC(_n_) + (((_n_)->n_descsz+3)&~3))
 
-#if defined(__i386__)
-typedef Elf32_Ehdr Elf_Ehdr;
+#ifndef ELFSIZE
+#include <limits.h>
+#if UINT_MAX == ULONG_MAX
+#define ELFSIZE 32
+#else
+#define ELFSIZE 64
+#endif
+#endif
+
+#if (ELFSIZE == 32)
 typedef Elf32_Nhdr Elf_Nhdr;
 typedef Elf32_Half Elf_Half;
 typedef Elf32_Word Elf_Word;
-#elif defined(__x86_64__)
-typedef Elf64_Ehdr Elf_Ehdr;
+#elif (ELFSIZE == 64)
 typedef Elf64_Nhdr Elf_Nhdr;
 typedef Elf64_Half Elf_Half;
 typedef Elf64_Word Elf_Word;
 #else
-#error "Unknown architecture"
+#error "Unknown ELFSIZE"
 #endif
 
 static void print_string_note(const char *prefix, Elf_Nhdr *note)
@@ -54,18 +61,35 @@ static void print_numeric_note(const cha
 	}
 }
 
+static inline int is_elf(void *image)
+{
+	/*
+	 * Since we are only accessing the e_ident field we can
+	 * acccess the bytes directly without needing to figure out
+	 * which version of Elf*_Ehdr structure to use.
+	 */
+	const unsigned char *hdr = image;
+	return ( hdr[EI_MAG0] == ELFMAG0 &&
+		 hdr[EI_MAG1] == ELFMAG1 &&
+		 hdr[EI_MAG2] == ELFMAG2 &&
+		 hdr[EI_MAG3] == ELFMAG3 );
+}
+
 static inline unsigned char ehdr_class(void *image)
 {
-	Elf_Ehdr *ehdr = image;
-	switch (ehdr->e_ident[EI_CLASS])
-	{
-	case ELFCLASS32:
-	case ELFCLASS64:
-		return ehdr->e_ident[EI_CLASS];
-		break;
-	default:
-		fprintf(stderr, "Unknown ELF class %d\n",
-			ehdr->e_ident[EI_CLASS]);
+	/*
+	 * Since we are only accessing the e_ident field we can
+	 * acccess the bytes directly without needing to figure out
+	 * which version of Elf*_Ehdr structure to use.
+	 */
+	const unsigned char *hdr = image;
+	switch (hdr[EI_CLASS])
+	{
+	case ELFCLASS32:
+	case ELFCLASS64:
+		return hdr[EI_CLASS];
+	default:
+		fprintf(stderr, "Unknown ELF class %d\n", hdr[EI_CLASS]);
 		exit(1);
 	}
 }
@@ -198,7 +222,6 @@ int main(int argc, char **argv)
 	int fd,h;
 	void *image;
 	struct stat st;
-	Elf_Ehdr *ehdr;
 	Elf_Nhdr *note;
 
 	if (argc != 2)
@@ -228,11 +251,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ehdr = image;
-	if (ehdr->e_ident[EI_MAG0] != ELFMAG0 ||
-	    ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
-	    ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
-	    ehdr->e_ident[EI_MAG3] != ELFMAG3)
+	if ( !is_elf(image) )
 	{
 		fprintf(stderr, "File %s is not an ELF image\n", f);
 		return 1;

  reply	other threads:[~2006-08-25  9:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-23 14:00 [POWERPC/IA64] Updates required due to loader changes Ian Campbell
2006-08-23 14:36 ` Ian Campbell
2006-08-23 14:49   ` Tristan Gingold
2006-08-23 18:20     ` Ian Campbell
2006-08-23 17:44   ` Ian Campbell
2006-08-23 18:09     ` Hollis Blanchard
2006-08-23 18:20       ` Ian Campbell
2006-08-24 20:16       ` Alex Williamson
2006-08-24 20:29         ` Hollis Blanchard
2006-08-25  3:21           ` Horms
2006-08-25  9:42             ` Ian Campbell [this message]
2006-08-25 16:05               ` Hollis Blanchard
2006-08-26  8:56               ` Horms
2006-08-23 18:29 ` Hollis Blanchard
2006-08-24  2:17 ` Horms
2006-08-24  7:12   ` Ian Campbell
2006-08-24  8:11     ` Horms
2006-08-24 14:24       ` Ian Campbell

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=1156498945.12949.180.camel@localhost.localdomain \
    --to=ian.campbell@xensource.com \
    --cc=alex.williamson@hp.com \
    --cc=hollisb@us.ibm.com \
    --cc=horms@verge.net.au \
    --cc=jimix@watson.ibm.com \
    --cc=xen-devel@lists.xensource.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.