diff options
author | marcel <marcel@FreeBSD.org> | 1999-12-16 17:25:01 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 1999-12-16 17:25:01 +0000 |
commit | 6db98885a563ab8ab2853b6991b22cdb71acb7e3 (patch) | |
tree | d25a3b7316b07f5e4413b452f755fcc68357489a | |
parent | db701263c188f477549acf3d2ea91304faa1e0cc (diff) | |
download | FreeBSD-src-6db98885a563ab8ab2853b6991b22cdb71acb7e3.zip FreeBSD-src-6db98885a563ab8ab2853b6991b22cdb71acb7e3.tar.gz |
Don't build gensetdefs when we can use /usr/bin/gensetdefs. The latter
also creates setdef{0|1}.c so there's no need to have those in the
repository. Using /usr/bin/gensetdefs has no consequences for the
output.
-rw-r--r-- | sys/boot/alpha/common/Makefile.common | 21 | ||||
-rw-r--r-- | sys/boot/alpha/common/setdef0.c | 48 | ||||
-rw-r--r-- | sys/boot/alpha/common/setdef1.c | 41 | ||||
-rw-r--r-- | sys/boot/arc/loader/Makefile | 29 | ||||
-rw-r--r-- | sys/boot/arc/loader/setdef0.c | 48 | ||||
-rw-r--r-- | sys/boot/arc/loader/setdef1.c | 41 | ||||
-rw-r--r-- | sys/boot/common/gensetdefs.c | 321 |
7 files changed, 17 insertions, 532 deletions
diff --git a/sys/boot/alpha/common/Makefile.common b/sys/boot/alpha/common/Makefile.common index 8ba498a..3467d8f 100644 --- a/sys/boot/alpha/common/Makefile.common +++ b/sys/boot/alpha/common/Makefile.common @@ -19,9 +19,8 @@ CFLAGS+= -I${.CURDIR}/../../.. -I. CFLAGS+= -DPRIMARY_LOAD_ADDRESS=${PRIMARY_LOAD_ADDRESS} \ -DSECONDARY_LOAD_ADDRESS=${SECONDARY_LOAD_ADDRESS} -CLEANFILES+= vers.c vers.o gensetdefs.o gensetdefs setdef0.o setdef1.o \ - setdefs.h start.o -CLEANFILES+= ${BASE} ${BASE}.sym ${BASE}.list +CLEANFILES+= setdef0.c setdef0.o setdef1.c setdef1.o setdefs.h start.o \ + vers.c vers.o ${BASE} ${BASE}.sym ${BASE}.list CFLAGS+= -Wall @@ -42,8 +41,9 @@ ${BASE}: ${BASE}.sym ${BASE}.help ${BASE}.sym: ${OBJS} ${LIBSTAND} ${LIBALPHA} ${CRT} vers.o setdef0.o setdef1.o ${LD} -o ${BASE}.sym -M -e start -N -Ttext ${LOAD_ADDRESS} \ - ${CRT} setdef0.o ${OBJS} setdef1.o \ - vers.o ${LIBSTAND} ${LIBALPHA} ${LIBSTAND} >${.OBJDIR}/${BASE}.list + ${CRT} setdef0.o ${OBJS} setdef1.o vers.o \ + -L${DESTDIR}${LIBDIR} ${LIBSTAND} ${LIBALPHA} ${LIBSTAND} \ + > ${.OBJDIR}/${BASE}.list ${BASE}.help: help.common help.alpha cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET} @@ -73,14 +73,9 @@ CLEANFILES+= machine .include <bsd.prog.mk> -setdefs.h: gensetdefs ${OBJS} +.ORDER: setdefs.h setdef0.c setdef1.c +setdefs.h setdef0.c setdef1.c: ${OBJS} @echo Generating linker sets - @./gensetdefs ${OBJS} >setdefs.h - -gensetdefs: gensetdefs.o - ${CC} -static gensetdefs.o -o $@ - -gensetdefs.o: gensetdefs.c - ${CC} -c $< + @gensetdefs ${OBJS} beforedepend ${OBJS}: machine diff --git a/sys/boot/alpha/common/setdef0.c b/sys/boot/alpha/common/setdef0.c deleted file mode 100644 index 942b90e..0000000 --- a/sys/boot/alpha/common/setdef0.c +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * Copyright (c) 1997 John D. Polstra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifdef __ELF__ - -#include <sys/param.h> - -/* - * DEFINE_SET creates the section and label for a set, and emits the - * count word at the front of it. - */ -#define DEFINE_SET(set, count) \ - __asm__(".section .set." #set ",\"aw\""); \ - __asm__(".globl " #set); \ - __asm__(".type " #set ",@object"); \ - __asm__(".p2align 3"); \ - __asm__(#set ":"); \ - __asm__(".quad " #count); \ - __asm__(".previous") - -#include "setdefs.h" /* Contains a `DEFINE_SET' for each set */ - -#endif /* __ELF__ */ diff --git a/sys/boot/alpha/common/setdef1.c b/sys/boot/alpha/common/setdef1.c deleted file mode 100644 index 13668f0..0000000 --- a/sys/boot/alpha/common/setdef1.c +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * Copyright (c) 1997 John D. Polstra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifdef __ELF__ - -/* - * DEFINE_SET emits the NULL terminator for a set. - */ -#define DEFINE_SET(set, count) \ - __asm__(".section .set." #set ",\"aw\""); \ - __asm__(".quad 0"); \ - __asm__(".previous") - -#include "setdefs.h" /* Contains a `DEFINE_SET' for each set */ - -#endif /* __ELF__ */ diff --git a/sys/boot/arc/loader/Makefile b/sys/boot/arc/loader/Makefile index acbb066..a12c182 100644 --- a/sys/boot/arc/loader/Makefile +++ b/sys/boot/arc/loader/Makefile @@ -19,9 +19,10 @@ CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR} CFLAGS+= -I${.CURDIR}/../../.. -I. CFLAGS+= -DLOADER -CLEANFILES+= vers.c vers.o gensetdefs.o gensetdefs setdef0.o setdef1.o \ - setdefs.h start.o -CLEANFILES+= ${BASE} ${BASE}.sym ${BASE}.list +CLEANFILES+= setdef0.c setdef0.o setdef1.c setdef1.o setdefs.h start.o \ + vers.c vers.o ${BASE} ${BASE}.exe ${BASE}.sym ${BASE}.list +CLEANFILES+= loader.help +CLEANFILES+= machine CFLAGS+= -Wall @@ -41,15 +42,10 @@ vers.o: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${BASE}.exe: ${BASE} ${BASE}.help elf2exe ${BASE}.sym ${BASE}.exe -#${BASE}: ${OBJS} ${LIBSTAND} ${LIBARC} ${CRT} vers.o setdef0.o setdef1.o -# ${LD} -o ${BASE}.sym -M -e __start -N -Ttext ${LOAD_ADDRESS} \ -# ${CRT} setdef0.o ${OBJS} setdef1.o \ -# vers.o ${LIBSTAND} ${LIBARC} ${LIBSTAND} >${.OBJDIR}/${BASE}.list - ${BASE}: ${OBJS} ${LIBSTAND} ${LIBARC} ${CRT} vers.o setdef0.o setdef1.o ${LD} -o ${BASE}.sym -M -N -Ttext ${LOAD_ADDRESS} \ - ${CRT} setdef0.o ${OBJS} setdef1.o \ - vers.o ${LIBSTAND} ${LIBARC} ${LIBSTAND} >${.OBJDIR}/${BASE}.list + ${CRT} setdef0.o ${OBJS} setdef1.o vers.o -L${DESTDIR}${LIBDIR} \ + ${LIBSTAND} ${LIBARC} ${LIBSTAND} >${.OBJDIR}/${BASE}.list ${BASE}.help: help.common help.alpha cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET} @@ -74,18 +70,11 @@ setdef1.o: setdefs.h machine: ln -sf ${.CURDIR}/../../../alpha/include machine -CLEANFILES+= machine setdefs.h gensetdefs ${BASE} ${BASE}.exe loader.help - .include <bsd.prog.mk> -setdefs.h: gensetdefs ${OBJS} +.ORDER: setdefs.h setdef0.c setdef1.c +setdefs.h setdef0.c setdef1.c: ${OBJS} @echo Generating linker sets - @./gensetdefs ${OBJS} >setdefs.h - -gensetdefs: gensetdefs.o - ${CC} -static gensetdefs.o -o $@ - -gensetdefs.o: gensetdefs.c - ${CC} -c $< + @gensetdefs ${OBJS} beforedepend ${OBJS}: machine diff --git a/sys/boot/arc/loader/setdef0.c b/sys/boot/arc/loader/setdef0.c deleted file mode 100644 index 942b90e..0000000 --- a/sys/boot/arc/loader/setdef0.c +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * Copyright (c) 1997 John D. Polstra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifdef __ELF__ - -#include <sys/param.h> - -/* - * DEFINE_SET creates the section and label for a set, and emits the - * count word at the front of it. - */ -#define DEFINE_SET(set, count) \ - __asm__(".section .set." #set ",\"aw\""); \ - __asm__(".globl " #set); \ - __asm__(".type " #set ",@object"); \ - __asm__(".p2align 3"); \ - __asm__(#set ":"); \ - __asm__(".quad " #count); \ - __asm__(".previous") - -#include "setdefs.h" /* Contains a `DEFINE_SET' for each set */ - -#endif /* __ELF__ */ diff --git a/sys/boot/arc/loader/setdef1.c b/sys/boot/arc/loader/setdef1.c deleted file mode 100644 index 13668f0..0000000 --- a/sys/boot/arc/loader/setdef1.c +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * Copyright (c) 1997 John D. Polstra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifdef __ELF__ - -/* - * DEFINE_SET emits the NULL terminator for a set. - */ -#define DEFINE_SET(set, count) \ - __asm__(".section .set." #set ",\"aw\""); \ - __asm__(".quad 0"); \ - __asm__(".previous") - -#include "setdefs.h" /* Contains a `DEFINE_SET' for each set */ - -#endif /* __ELF__ */ diff --git a/sys/boot/common/gensetdefs.c b/sys/boot/common/gensetdefs.c deleted file mode 100644 index a78e456..0000000 --- a/sys/boot/common/gensetdefs.c +++ /dev/null @@ -1,321 +0,0 @@ -/*- - * Copyright (c) 1997 John D. Polstra. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <sys/types.h> -#include <machine/elf.h> - -#include <err.h> -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#define HASHSIZE 1009u /* Number of hash chains. */ -#define PREFIX ".set." /* Section name prefix for linker sets. */ - -#if __ELF_WORD_SIZE == 64 -# define Elf_Shdr Elf64_Shdr -# define Elf_Ehdr Elf64_Ehdr -#else -# define Elf_Shdr Elf32_Shdr -# define Elf_Ehdr Elf32_Ehdr -#endif - -/* One entry in the hash table. */ -typedef struct hashent { - struct hashent *next; /* Next entry with the same hash. */ - char *name; /* Name of the linker set. */ - size_t size; /* Size in bytes. */ -} hashent; - -/* Allocate storage for "count" objects of type "type". */ -#define NEW(type, count) ((type *) xmalloc((count) * sizeof(type))) - -static hashent *hashtab[HASHSIZE]; /* Hash chain heads. */ - -static void enter(const char *, size_t); -static int enter_sets(const char *); -static unsigned int hash(const char *); -static hashent *merge(void); -static int my_byte_order(void); -static void *xmalloc(size_t); -static char *xstrdup(const char *); - -/* - * This is a special-purpose program to generate the linker set definitions - * needed when building an ELF kernel. Its arguments are the names of - * ELF object files. It scans the section names of the object files, - * building a table of those that begin with ".set.", which represent - * linker sets. Finally, for each set "foo" with "count" elements, it - * writes a line "DEFINE_SET(foo, count);" to the standard output. - */ -int -main(int argc, char **argv) -{ - int i; - int status = EXIT_SUCCESS; - hashent *list; - - for (i = 1; i < argc; i++) - if (enter_sets(argv[i]) == -1) - status = EXIT_FAILURE; - - list = merge(); - while (list != NULL) { - hashent *next; - - printf("DEFINE_SET(%s, %lu);\n", list->name, - (unsigned long) (list->size / sizeof (void *))); - next = list->next; - free(list->name); - free(list); - list = next; - } - - return (status); -} - -/* - * Enter the given string into the hash table, if it is not already there. - * Each hash chain is kept sorted, so that it will be easy to merge the - * chains to get a single sorted list. - */ -static void -enter(const char *name, size_t size) -{ - int c = 0; - hashent *entp; - hashent **linkp; - hashent *newp; - - linkp = &hashtab[hash(name) % HASHSIZE]; - while ((entp = *linkp) != NULL && (c = strcmp(name, entp->name)) > 0) - linkp = &entp->next; - - if (entp == NULL || c != 0) { /* Not found; create a new entry. */ - newp = NEW(hashent, 1); - newp->name = xstrdup(name); - newp->size = 0; - newp->next = entp; - *linkp = newp; - entp = newp; - } - - entp->size += size; -} - -/* - * Return a hash value for the given string. - */ -static unsigned int -hash(const char *s) -{ - unsigned char ch; - unsigned int h = 0; - - while((ch = *s) != '\0') { - h = 9*h + ch; - s++; - } - return (h); -} - -/* - * Enter the linker sets from the given ELF object file. Returns 0 on - * success, or -1 if an error occurred. - */ -static int -enter_sets(const char *filename) -{ - int i; - FILE *iop; - Elf_Shdr *shdr; - char *shstr; - Elf_Ehdr ehdr; - - if ((iop = fopen(filename, "rb")) == NULL) { - warn("%s", filename); - return (-1); - } - if (fread(&ehdr, sizeof ehdr, 1, iop) != 1 || - ehdr.e_ident[EI_MAG0] != ELFMAG0 || - ehdr.e_ident[EI_MAG1] != ELFMAG1 || - ehdr.e_ident[EI_MAG2] != ELFMAG2 || - ehdr.e_ident[EI_MAG3] != ELFMAG3) { - warnx("%s: not an ELF file", filename); - fclose(iop); - return (-1); - } - if (ehdr.e_ident[EI_VERSION] != EV_CURRENT) { - warnx("%s: unsupported ELF version", filename); - fclose(iop); - return (-1); - } - if (ehdr.e_ident[EI_DATA] != my_byte_order()) { - warnx("%s: unsupported byte order", filename); - fclose(iop); - return (-1); - } - if (ehdr.e_shoff == 0) { - warnx("%s: no section table", filename); - fclose(iop); - return (-1); - } - if (ehdr.e_shstrndx == SHN_UNDEF) { - warnx("%s: no section name string table", filename); - fclose(iop); - return (-1); - } - - shdr = NEW(Elf_Shdr, ehdr.e_shnum); - if (fseek(iop, ehdr.e_shoff, SEEK_SET) == -1) { - warn("%s", filename); - free(shdr); - fclose(iop); - return (-1); - } - if (fread(shdr, sizeof *shdr, ehdr.e_shnum, iop) != ehdr.e_shnum) { - warnx("%s: truncated section table", filename); - free(shdr); - fclose(iop); - return (-1); - } - - shstr = NEW(char, shdr[ehdr.e_shstrndx].sh_size); - if (fseek(iop, shdr[ehdr.e_shstrndx].sh_offset, SEEK_SET) == -1) { - warn("%s", filename); - free(shstr); - free(shdr); - fclose(iop); - return (-1); - } - if (fread(shstr, sizeof *shstr, shdr[ehdr.e_shstrndx].sh_size, iop) != - shdr[ehdr.e_shstrndx].sh_size) { - warnx("%s: truncated section name string table", filename); - free(shstr); - free(shdr); - fclose(iop); - return (-1); - } - - for (i = 1; i < ehdr.e_shnum; i++) { - const char *name = shstr + shdr[i].sh_name; - - if (strncmp(name, PREFIX, sizeof (PREFIX) - 1) == 0) - enter(name + sizeof (PREFIX) - 1, shdr[i].sh_size); - } - - free(shstr); - free(shdr); - fclose(iop); - return (0); -} - -/* - * Destructively merge all the sorted hash chains into a single sorted - * list, and return a pointer to its first element. - */ -static hashent * -merge(void) -{ - unsigned int numchains = HASHSIZE; - - while (numchains > 1) { /* More merging to do. */ - unsigned int lo = 0; - /* - * Merge chains pairwise from the outside in, halving the - * number of chains. - */ - while (numchains - lo >= 2) { - hashent **linkp = &hashtab[lo]; - hashent *l1 = hashtab[lo++]; - hashent *l2 = hashtab[--numchains]; - - while (l1 != NULL && l2 != NULL) { - if (strcmp(l1->name, l2->name) < 0) { - *linkp = l1; - linkp = &l1->next; - l1 = l1->next; - } else { - *linkp = l2; - linkp = &l2->next; - l2 = l2->next; - } - } - *linkp = l1==NULL ? l2 : l1; - } - } - - return (hashtab[0]); -} - -/* - * Determine the host byte order. - */ -static int -my_byte_order(void) -{ - static unsigned short s = 0xbbaa; - int byte0; - - byte0 = *(unsigned char *)&s; - if (byte0 == 0xaa) - return (ELFDATA2LSB); - else if (byte0 == 0xbb) - return (ELFDATA2MSB); - else - return (ELFDATANONE); -} - -/* - * Allocate a chunk of memory and return a pointer to it. Die if the - * malloc fails. - */ -static void * -xmalloc(size_t size) -{ - void *p; - - p = malloc(size); - if (p == NULL) - err(EXIT_FAILURE, "malloc"); - return (p); -} - -/* - * Duplicate a string and return a pointer to the copy. Die if there is - * not enough memory. - */ -static char * -xstrdup(const char *s) -{ - int size; - - size = strlen(s) + 1; - return (memcpy(xmalloc(size), s, size)); -} |