From 62d33e59ff8e61281f731414abbbe7462ee0a5d6 Mon Sep 17 00:00:00 2001 From: eeh Date: Mon, 22 May 2000 19:15:33 +0000 Subject: [PATCH] Align things pessimistically so a 64-bit kernel will accept symbols from a 32-bit loader. --- sys/arch/sparc64/stand/ofwboot/elfXX_exec.c | 22 ++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/sys/arch/sparc64/stand/ofwboot/elfXX_exec.c b/sys/arch/sparc64/stand/ofwboot/elfXX_exec.c index 7e3bc1590c1b..48b95cf0b859 100644 --- a/sys/arch/sparc64/stand/ofwboot/elfXX_exec.c +++ b/sys/arch/sparc64/stand/ofwboot/elfXX_exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: elfXX_exec.c,v 1.5 2000/03/06 01:29:04 eeh Exp $ */ +/* $NetBSD: elfXX_exec.c,v 1.6 2000/05/22 19:15:33 eeh Exp $ */ /* * Copyright (c) 1998-2000 Eduardo Horvath. All rights reserved. @@ -50,6 +50,13 @@ #if 0 int CAT3(elf,ELFSIZE,_exec) __P((int, CAT3(Elf,ELFSIZE,_Ehdr) *, u_int64_t *, void **, void **)); #endif +#if defined(ELFSIZE) && (ELFSIZE == 32) +#define ELF_ALIGN(x) (((x)+3)&(~3)) +#elif defined(ELFSIZE) && (ELFSIZE == 64) +#define ELF_ALIGN(x) (((x)+7)&(~7)) +#else +#error ELFSIZE must be either 32 or 64! +#endif int CAT3(elf, ELFSIZE, _exec)(fd, elf, entryp, ssymp, esymp) @@ -168,8 +175,11 @@ CAT3(elf, ELFSIZE, _exec)(fd, elf, entryp, ssymp, esymp) * Now load the symbol sections themselves. */ shp = addr + sizeof(CAT3(Elf,ELFSIZE,_Ehdr)); - addr += sizeof(CAT3(Elf,ELFSIZE,_Ehdr)) + (elf->e_shnum * sizeof(CAT3(Elf,ELFSIZE,_Shdr))); - off = sizeof(CAT3(Elf,ELFSIZE,_Ehdr)) + (elf->e_shnum * sizeof(CAT3(Elf,ELFSIZE,_Shdr))); + size = sizeof(CAT3(Elf,ELFSIZE,_Ehdr)) + + (elf->e_shnum * sizeof(CAT3(Elf,ELFSIZE,_Shdr))); + size = ELF_ALIGN(size); + addr += size; + off = size; for (first = 1, i = 0; i < elf->e_shnum; i++, shp++) { if (shp->sh_type == SHT_SYMTAB || shp->sh_type == SHT_STRTAB) { @@ -181,9 +191,9 @@ CAT3(elf, ELFSIZE, _exec)(fd, elf, entryp, ssymp, esymp) printf("read symbols: %s\n", strerror(errno)); return (1); } - addr += (shp->sh_size+3)&(~3); + addr += ELF_ALIGN(shp->sh_size); shp->sh_offset = off; - off += (shp->sh_size+3)&(~3); + off += ELF_ALIGN(shp->sh_size); first = 0; } } @@ -192,3 +202,5 @@ CAT3(elf, ELFSIZE, _exec)(fd, elf, entryp, ssymp, esymp) *entryp = elf->e_entry; return (0); } + +#undef ELF_ALIGN