Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Jun 2011 21:36:36 +0000 (UTC)
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r222880 - stable/8/sys/kern
Message-ID:  <201106082136.p58LaaHN048653@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dchagin
Date: Wed Jun  8 21:36:36 2011
New Revision: 222880
URL: http://svn.freebsd.org/changeset/base/222880

Log:
  MFC r215013 by mdf@:
  
  Whitespace and other aspects of style(9).  No functional changes.
  
  MFC r220730:
  
  Remove malloc(9) return value checks when M_WAITOK is used.

Modified:
  stable/8/sys/kern/link_elf.c
  stable/8/sys/kern/link_elf_obj.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)

Modified: stable/8/sys/kern/link_elf.c
==============================================================================
--- stable/8/sys/kern/link_elf.c	Wed Jun  8 21:32:14 2011	(r222879)
+++ stable/8/sys/kern/link_elf.c	Wed Jun  8 21:36:36 2011	(r222880)
@@ -74,52 +74,52 @@ __FBSDID("$FreeBSD$");
 #define MAXSEGS 4
 
 typedef struct elf_file {
-    struct linker_file	lf;		/* Common fields */
-    int			preloaded;	/* Was file pre-loaded */
-    caddr_t		address;	/* Relocation address */
+	struct linker_file lf;		/* Common fields */
+	int		preloaded;	/* Was file pre-loaded */
+	caddr_t		address;	/* Relocation address */
 #ifdef SPARSE_MAPPING
-    vm_object_t		object;		/* VM object to hold file pages */
+	vm_object_t	object;		/* VM object to hold file pages */
 #endif
-    Elf_Dyn*		dynamic;	/* Symbol table etc. */
-    Elf_Hashelt		nbuckets;	/* DT_HASH info */
-    Elf_Hashelt		nchains;
-    const Elf_Hashelt*	buckets;
-    const Elf_Hashelt*	chains;
-    caddr_t		hash;
-    caddr_t		strtab;		/* DT_STRTAB */
-    int			strsz;		/* DT_STRSZ */
-    const Elf_Sym*	symtab;		/* DT_SYMTAB */
-    Elf_Addr*		got;		/* DT_PLTGOT */
-    const Elf_Rel*	pltrel;		/* DT_JMPREL */
-    int			pltrelsize;	/* DT_PLTRELSZ */
-    const Elf_Rela*	pltrela;	/* DT_JMPREL */
-    int			pltrelasize;	/* DT_PLTRELSZ */
-    const Elf_Rel*	rel;		/* DT_REL */
-    int			relsize;	/* DT_RELSZ */
-    const Elf_Rela*	rela;		/* DT_RELA */
-    int			relasize;	/* DT_RELASZ */
-    caddr_t		modptr;
-    const Elf_Sym*	ddbsymtab;	/* The symbol table we are using */
-    long		ddbsymcnt;	/* Number of symbols */
-    caddr_t		ddbstrtab;	/* String table */
-    long		ddbstrcnt;	/* number of bytes in string table */
-    caddr_t		symbase;	/* malloc'ed symbold base */
-    caddr_t		strbase;	/* malloc'ed string base */
-    caddr_t		ctftab;		/* CTF table */
-    long		ctfcnt;		/* number of bytes in CTF table */
-    caddr_t		ctfoff;		/* CTF offset table */
-    caddr_t		typoff;		/* Type offset table */
-    long		typlen;		/* Number of type entries. */
-    Elf_Addr		pcpu_start;	/* Pre-relocation pcpu set start. */
-    Elf_Addr		pcpu_stop;	/* Pre-relocation pcpu set stop. */
-    Elf_Addr		pcpu_base;	/* Relocated pcpu set address. */
+	Elf_Dyn		*dynamic;	/* Symbol table etc. */
+	Elf_Hashelt	nbuckets;	/* DT_HASH info */
+	Elf_Hashelt	nchains;
+	const Elf_Hashelt *buckets;
+	const Elf_Hashelt *chains;
+	caddr_t		hash;
+	caddr_t		strtab;		/* DT_STRTAB */
+	int		strsz;		/* DT_STRSZ */
+	const Elf_Sym	*symtab;		/* DT_SYMTAB */
+	Elf_Addr	*got;		/* DT_PLTGOT */
+	const Elf_Rel	*pltrel;	/* DT_JMPREL */
+	int		pltrelsize;	/* DT_PLTRELSZ */
+	const Elf_Rela	*pltrela;	/* DT_JMPREL */
+	int		pltrelasize;	/* DT_PLTRELSZ */
+	const Elf_Rel	*rel;		/* DT_REL */
+	int		relsize;	/* DT_RELSZ */
+	const Elf_Rela	*rela;		/* DT_RELA */
+	int		relasize;	/* DT_RELASZ */
+	caddr_t		modptr;
+	const Elf_Sym	*ddbsymtab;	/* The symbol table we are using */
+	long		ddbsymcnt;	/* Number of symbols */
+	caddr_t		ddbstrtab;	/* String table */
+	long		ddbstrcnt;	/* number of bytes in string table */
+	caddr_t		symbase;	/* malloc'ed symbold base */
+	caddr_t		strbase;	/* malloc'ed string base */
+	caddr_t		ctftab;		/* CTF table */
+	long		ctfcnt;		/* number of bytes in CTF table */
+	caddr_t		ctfoff;		/* CTF offset table */
+	caddr_t		typoff;		/* Type offset table */
+	long		typlen;		/* Number of type entries. */
+	Elf_Addr	pcpu_start;	/* Pre-relocation pcpu set start. */
+	Elf_Addr	pcpu_stop;	/* Pre-relocation pcpu set stop. */
+	Elf_Addr	pcpu_base;	/* Relocated pcpu set address. */
 #ifdef VIMAGE
-    Elf_Addr		vnet_start;	/* Pre-relocation vnet set start. */
-    Elf_Addr		vnet_stop;	/* Pre-relocation vnet set stop. */
-    Elf_Addr		vnet_base;	/* Relocated vnet set address. */
+	Elf_Addr	vnet_start;	/* Pre-relocation vnet set start. */
+	Elf_Addr	vnet_stop;	/* Pre-relocation vnet set stop. */
+	Elf_Addr	vnet_base;	/* Relocated vnet set address. */
 #endif
 #ifdef GDB
-    struct link_map	gdb;		/* hooks for gdb */
+	struct link_map	gdb;		/* hooks for gdb */
 #endif
 } *elf_file_t;
 
@@ -127,70 +127,71 @@ typedef struct elf_file {
 
 static int	link_elf_link_common_finish(linker_file_t);
 static int	link_elf_link_preload(linker_class_t cls,
-				      const char*, linker_file_t*);
+				      const char *, linker_file_t *);
 static int	link_elf_link_preload_finish(linker_file_t);
-static int	link_elf_load_file(linker_class_t, const char*, linker_file_t*);
-static int	link_elf_lookup_symbol(linker_file_t, const char*,
-				       c_linker_sym_t*);
-static int	link_elf_symbol_values(linker_file_t, c_linker_sym_t, linker_symval_t*);
-static int	link_elf_search_symbol(linker_file_t, caddr_t value,
-				       c_linker_sym_t* sym, long* diffp);
+static int	link_elf_load_file(linker_class_t, const char *,
+		    linker_file_t *);
+static int	link_elf_lookup_symbol(linker_file_t, const char *,
+		    c_linker_sym_t *);
+static int	link_elf_symbol_values(linker_file_t, c_linker_sym_t,
+		    linker_symval_t *);
+static int	link_elf_search_symbol(linker_file_t, caddr_t,
+		    c_linker_sym_t *, long *);
 
 static void	link_elf_unload_file(linker_file_t);
 static void	link_elf_unload_preload(linker_file_t);
 static int	link_elf_lookup_set(linker_file_t, const char *,
-				    void ***, void ***, int *);
+		    void ***, void ***, int *);
 static int	link_elf_each_function_name(linker_file_t,
-				int (*)(const char *, void *),
-				void *);
+		    int (*)(const char *, void *), void *);
 static int	link_elf_each_function_nameval(linker_file_t,
-				linker_function_nameval_callback_t,
-				void *);
+		    linker_function_nameval_callback_t, void *);
 static void	link_elf_reloc_local(linker_file_t);
 static long	link_elf_symtab_get(linker_file_t, const Elf_Sym **);
 static long	link_elf_strtab_get(linker_file_t, caddr_t *);
-static Elf_Addr	elf_lookup(linker_file_t lf, Elf_Size symidx, int deps);
+static Elf_Addr	elf_lookup(linker_file_t, Elf_Size, int);
 
 static kobj_method_t link_elf_methods[] = {
-    KOBJMETHOD(linker_lookup_symbol,	link_elf_lookup_symbol),
-    KOBJMETHOD(linker_symbol_values,	link_elf_symbol_values),
-    KOBJMETHOD(linker_search_symbol,	link_elf_search_symbol),
-    KOBJMETHOD(linker_unload,		link_elf_unload_file),
-    KOBJMETHOD(linker_load_file,	link_elf_load_file),
-    KOBJMETHOD(linker_link_preload,	link_elf_link_preload),
-    KOBJMETHOD(linker_link_preload_finish, link_elf_link_preload_finish),
-    KOBJMETHOD(linker_lookup_set,	link_elf_lookup_set),
-    KOBJMETHOD(linker_each_function_name, link_elf_each_function_name),
-    KOBJMETHOD(linker_each_function_nameval, link_elf_each_function_nameval),
-    KOBJMETHOD(linker_ctf_get,          link_elf_ctf_get),
-    KOBJMETHOD(linker_symtab_get, 	link_elf_symtab_get),
-    KOBJMETHOD(linker_strtab_get, 	link_elf_strtab_get),
-    { 0, 0 }
+	KOBJMETHOD(linker_lookup_symbol,	link_elf_lookup_symbol),
+	KOBJMETHOD(linker_symbol_values,	link_elf_symbol_values),
+	KOBJMETHOD(linker_search_symbol,	link_elf_search_symbol),
+	KOBJMETHOD(linker_unload,		link_elf_unload_file),
+	KOBJMETHOD(linker_load_file,		link_elf_load_file),
+	KOBJMETHOD(linker_link_preload,		link_elf_link_preload),
+	KOBJMETHOD(linker_link_preload_finish,	link_elf_link_preload_finish),
+	KOBJMETHOD(linker_lookup_set,		link_elf_lookup_set),
+	KOBJMETHOD(linker_each_function_name,	link_elf_each_function_name),
+	KOBJMETHOD(linker_each_function_nameval, link_elf_each_function_nameval),
+	KOBJMETHOD(linker_ctf_get,		link_elf_ctf_get),
+	KOBJMETHOD(linker_symtab_get,		link_elf_symtab_get),
+	KOBJMETHOD(linker_strtab_get,		link_elf_strtab_get),
+	{ 0, 0 }
 };
 
 static struct linker_class link_elf_class = {
 #if ELF_TARG_CLASS == ELFCLASS32
-    "elf32",
+	"elf32",
 #else
-    "elf64",
+	"elf64",
 #endif
-    link_elf_methods, sizeof(struct elf_file)
+	link_elf_methods, sizeof(struct elf_file)
 };
 
-static int		parse_dynamic(elf_file_t ef);
-static int		relocate_file(elf_file_t ef);
-static int		link_elf_preload_parse_symbols(elf_file_t ef);
+static int	parse_dynamic(elf_file_t);
+static int	relocate_file(elf_file_t);
+static int	link_elf_preload_parse_symbols(elf_file_t);
 
 #ifdef GDB
-static void		r_debug_state(struct r_debug *dummy_one,
-				      struct link_map *dummy_two);
+static void	r_debug_state(struct r_debug *, struct link_map *);
 
 /*
  * A list of loaded modules for GDB to use for loading symbols.
  */
 struct r_debug r_debug;
 
-#define GDB_STATE(s)	r_debug.r_state = s; r_debug_state(NULL, NULL);
+#define GDB_STATE(s) do {				\
+	r_debug.r_state = s; r_debug_state(NULL, NULL);	\
+} while (0)
 
 /*
  * Function for the debugger to set a breakpoint on to gain control.
@@ -204,35 +205,37 @@ r_debug_state(struct r_debug *dummy_one 
 static void
 link_elf_add_gdb(struct link_map *l)
 {
-    struct link_map *prev;
+	struct link_map *prev;
 
-    l->l_next = NULL;
+	l->l_next = NULL;
 
-    if (r_debug.r_map == NULL) {
-	/* Add first. */
-	l->l_prev = NULL;
-	r_debug.r_map = l;
-    } else {
-	/* Append to list. */
-	for (prev = r_debug.r_map; prev->l_next != NULL; prev = prev->l_next)
-	    ;
-	l->l_prev = prev;
-	prev->l_next = l;
-    }
+	if (r_debug.r_map == NULL) {
+		/* Add first. */
+		l->l_prev = NULL;
+		r_debug.r_map = l;
+	} else {
+		/* Append to list. */
+		for (prev = r_debug.r_map;
+		    prev->l_next != NULL;
+		    prev = prev->l_next)
+			;
+		l->l_prev = prev;
+		prev->l_next = l;
+	}
 }
 
 static void
 link_elf_delete_gdb(struct link_map *l)
 {
-    if (l->l_prev == NULL) {
-	/* Remove first. */
-	if ((r_debug.r_map = l->l_next) != NULL)
-	    l->l_next->l_prev = NULL;
-    } else {
-	/* Remove any but first. */
-	if ((l->l_prev->l_next = l->l_next) != NULL)
-	    l->l_next->l_prev = l->l_prev;
-    }
+	if (l->l_prev == NULL) {
+		/* Remove first. */
+		if ((r_debug.r_map = l->l_next) != NULL)
+			l->l_next->l_prev = NULL;
+	} else {
+		/* Remove any but first. */
+		if ((l->l_prev->l_next = l->l_next) != NULL)
+			l->l_next->l_prev = l->l_prev;
+	}
 }
 #endif /* GDB */
 
@@ -262,85 +265,86 @@ static int
 link_elf_link_common_finish(linker_file_t lf)
 {
 #ifdef GDB
-    elf_file_t ef = (elf_file_t)lf;
-    char *newfilename;
+	elf_file_t ef = (elf_file_t)lf;
+	char *newfilename;
 #endif
-    int error;
+	int error;
 
-    /* Notify MD code that a module is being loaded. */
-    error = elf_cpu_load_file(lf);
-    if (error)
-	return (error);
+	/* Notify MD code that a module is being loaded. */
+	error = elf_cpu_load_file(lf);
+	if (error != 0)
+		return (error);
 
 #ifdef GDB
-    GDB_STATE(RT_ADD);
-    ef->gdb.l_addr = lf->address;
-    newfilename = malloc(strlen(lf->filename) + 1, M_LINKER, M_WAITOK);
-    strcpy(newfilename, lf->filename);
-    ef->gdb.l_name = newfilename;
-    ef->gdb.l_ld = ef->dynamic;
-    link_elf_add_gdb(&ef->gdb);
-    GDB_STATE(RT_CONSISTENT);
+	GDB_STATE(RT_ADD);
+	ef->gdb.l_addr = lf->address;
+	newfilename = malloc(strlen(lf->filename) + 1, M_LINKER, M_WAITOK);
+	strcpy(newfilename, lf->filename);
+	ef->gdb.l_name = newfilename;
+	ef->gdb.l_ld = ef->dynamic;
+	link_elf_add_gdb(&ef->gdb);
+	GDB_STATE(RT_CONSISTENT);
 #endif
 
-    return (0);
+	return (0);
 }
 
 static void
 link_elf_init(void* arg)
 {
-    Elf_Dyn	*dp;
-    caddr_t	modptr, baseptr, sizeptr;
-    elf_file_t	ef;
-    char	*modname;
-
-    linker_add_class(&link_elf_class);
-
-    dp = (Elf_Dyn*) &_DYNAMIC;
-    modname = NULL;
-    modptr = preload_search_by_type("elf" __XSTRING(__ELF_WORD_SIZE) " kernel");
-    if (modptr == NULL)
-	modptr = preload_search_by_type("elf kernel");
-    if (modptr)
-	modname = (char *)preload_search_info(modptr, MODINFO_NAME);
-    if (modname == NULL)
-	modname = "kernel";
-    linker_kernel_file = linker_make_file(modname, &link_elf_class);
-    if (linker_kernel_file == NULL)
-	panic("link_elf_init: Can't create linker structures for kernel");
-
-    ef = (elf_file_t) linker_kernel_file;
-    ef->preloaded = 1;
-    ef->address = 0;
+	Elf_Dyn *dp;
+	caddr_t modptr, baseptr, sizeptr;
+	elf_file_t ef;
+	char *modname;
+
+	linker_add_class(&link_elf_class);
+
+	dp = (Elf_Dyn *)&_DYNAMIC;
+	modname = NULL;
+	modptr = preload_search_by_type("elf" __XSTRING(__ELF_WORD_SIZE) " kernel");
+	if (modptr == NULL)
+		modptr = preload_search_by_type("elf kernel");
+	if (modptr != NULL)
+		modname = (char *)preload_search_info(modptr, MODINFO_NAME);
+	if (modname == NULL)
+		modname = "kernel";
+	linker_kernel_file = linker_make_file(modname, &link_elf_class);
+	if (linker_kernel_file == NULL)
+		panic("%s: Can't create linker structures for kernel",
+		    __func__);
+
+	ef = (elf_file_t) linker_kernel_file;
+	ef->preloaded = 1;
+	ef->address = 0;
 #ifdef SPARSE_MAPPING
-    ef->object = 0;
+	ef->object = 0;
 #endif
-    ef->dynamic = dp;
-
-    if (dp)
-	parse_dynamic(ef);
-    linker_kernel_file->address = (caddr_t) KERNBASE;
-    linker_kernel_file->size = -(intptr_t)linker_kernel_file->address;
+	ef->dynamic = dp;
 
-    if (modptr) {
-	ef->modptr = modptr;
-	baseptr = preload_search_info(modptr, MODINFO_ADDR);
-	if (baseptr)
-	    linker_kernel_file->address = *(caddr_t *)baseptr;
-	sizeptr = preload_search_info(modptr, MODINFO_SIZE);
-	if (sizeptr)
-	    linker_kernel_file->size = *(size_t *)sizeptr;
-    }
-    (void)link_elf_preload_parse_symbols(ef);
+	if (dp != NULL)
+		parse_dynamic(ef);
+	linker_kernel_file->address = (caddr_t) KERNBASE;
+	linker_kernel_file->size = -(intptr_t)linker_kernel_file->address;
+
+	if (modptr != NULL) {
+		ef->modptr = modptr;
+		baseptr = preload_search_info(modptr, MODINFO_ADDR);
+		if (baseptr != NULL)
+			linker_kernel_file->address = *(caddr_t *)baseptr;
+		sizeptr = preload_search_info(modptr, MODINFO_SIZE);
+		if (sizeptr != NULL)
+			linker_kernel_file->size = *(size_t *)sizeptr;
+	}
+	(void)link_elf_preload_parse_symbols(ef);
 
 #ifdef GDB
-    r_debug.r_map = NULL;
-    r_debug.r_brk = r_debug_state;
-    r_debug.r_state = RT_CONSISTENT;
+	r_debug.r_map = NULL;
+	r_debug.r_brk = r_debug_state;
+	r_debug.r_state = RT_CONSISTENT;
 #endif
 
-    (void)link_elf_link_common_finish(linker_kernel_file);
-    linker_kernel_file->flags |= LINKER_FILE_LINKED;
+	(void)link_elf_link_common_finish(linker_kernel_file);
+	linker_kernel_file->flags |= LINKER_FILE_LINKED;
 }
 
 SYSINIT(link_elf, SI_SUB_KLD, SI_ORDER_THIRD, link_elf_init, 0);
@@ -348,795 +352,791 @@ SYSINIT(link_elf, SI_SUB_KLD, SI_ORDER_T
 static int
 link_elf_preload_parse_symbols(elf_file_t ef)
 {
-    caddr_t	pointer;
-    caddr_t	ssym, esym, base;
-    caddr_t	strtab;
-    int		strcnt;
-    Elf_Sym*	symtab;
-    int		symcnt;
-
-    if (ef->modptr == NULL)
-	return 0;
-    pointer = preload_search_info(ef->modptr, MODINFO_METADATA|MODINFOMD_SSYM);
-    if (pointer == NULL)
-	return 0;
-    ssym = *(caddr_t *)pointer;
-    pointer = preload_search_info(ef->modptr, MODINFO_METADATA|MODINFOMD_ESYM);
-    if (pointer == NULL)
-	return 0;
-    esym = *(caddr_t *)pointer;
-
-    base = ssym;
-
-    symcnt = *(long *)base;
-    base += sizeof(long);
-    symtab = (Elf_Sym *)base;
-    base += roundup(symcnt, sizeof(long));
-
-    if (base > esym || base < ssym) {
-	printf("Symbols are corrupt!\n");
-	return EINVAL;
-    }
+	caddr_t pointer;
+	caddr_t ssym, esym, base;
+	caddr_t strtab;
+	int strcnt;
+	Elf_Sym *symtab;
+	int symcnt;
 
-    strcnt = *(long *)base;
-    base += sizeof(long);
-    strtab = base;
-    base += roundup(strcnt, sizeof(long));
-
-    if (base > esym || base < ssym) {
-	printf("Symbols are corrupt!\n");
-	return EINVAL;
-    }
+	if (ef->modptr == NULL)
+		return (0);
+	pointer = preload_search_info(ef->modptr,
+	    MODINFO_METADATA | MODINFOMD_SSYM);
+	if (pointer == NULL)
+		return (0);
+	ssym = *(caddr_t *)pointer;
+	pointer = preload_search_info(ef->modptr,
+	    MODINFO_METADATA | MODINFOMD_ESYM);
+	if (pointer == NULL)
+		return (0);
+	esym = *(caddr_t *)pointer;
+
+	base = ssym;
 
-    ef->ddbsymtab = symtab;
-    ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
-    ef->ddbstrtab = strtab;
-    ef->ddbstrcnt = strcnt;
+	symcnt = *(long *)base;
+	base += sizeof(long);
+	symtab = (Elf_Sym *)base;
+	base += roundup(symcnt, sizeof(long));
+
+	if (base > esym || base < ssym) {
+		printf("Symbols are corrupt!\n");
+		return (EINVAL);
+	}
 
-    return 0;
+	strcnt = *(long *)base;
+	base += sizeof(long);
+	strtab = base;
+	base += roundup(strcnt, sizeof(long));
+
+	if (base > esym || base < ssym) {
+		printf("Symbols are corrupt!\n");
+		return (EINVAL);
+	}
+
+	ef->ddbsymtab = symtab;
+	ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
+	ef->ddbstrtab = strtab;
+	ef->ddbstrcnt = strcnt;
+
+	return (0);
 }
 
 static int
 parse_dynamic(elf_file_t ef)
 {
-    Elf_Dyn *dp;
-    int plttype = DT_REL;
+	Elf_Dyn *dp;
+	int plttype = DT_REL;
 
-    for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
-	switch (dp->d_tag) {
-	case DT_HASH:
-	{
-	    /* From src/libexec/rtld-elf/rtld.c */
-	    const Elf_Hashelt *hashtab = (const Elf_Hashelt *)
-		(ef->address + dp->d_un.d_ptr);
-	    ef->nbuckets = hashtab[0];
-	    ef->nchains = hashtab[1];
-	    ef->buckets = hashtab + 2;
-	    ef->chains = ef->buckets + ef->nbuckets;
-	    break;
-	}
-	case DT_STRTAB:
-	    ef->strtab = (caddr_t) (ef->address + dp->d_un.d_ptr);
-	    break;
-	case DT_STRSZ:
-	    ef->strsz = dp->d_un.d_val;
-	    break;
-	case DT_SYMTAB:
-	    ef->symtab = (Elf_Sym*) (ef->address + dp->d_un.d_ptr);
-	    break;
-	case DT_SYMENT:
-	    if (dp->d_un.d_val != sizeof(Elf_Sym))
-		return ENOEXEC;
-	    break;
-	case DT_PLTGOT:
-	    ef->got = (Elf_Addr *) (ef->address + dp->d_un.d_ptr);
-	    break;
-	case DT_REL:
-	    ef->rel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
-	    break;
-	case DT_RELSZ:
-	    ef->relsize = dp->d_un.d_val;
-	    break;
-	case DT_RELENT:
-	    if (dp->d_un.d_val != sizeof(Elf_Rel))
-		return ENOEXEC;
-	    break;
-	case DT_JMPREL:
-	    ef->pltrel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
-	    break;
-	case DT_PLTRELSZ:
-	    ef->pltrelsize = dp->d_un.d_val;
-	    break;
-	case DT_RELA:
-	    ef->rela = (const Elf_Rela *) (ef->address + dp->d_un.d_ptr);
-	    break;
-	case DT_RELASZ:
-	    ef->relasize = dp->d_un.d_val;
-	    break;
-	case DT_RELAENT:
-	    if (dp->d_un.d_val != sizeof(Elf_Rela))
-		return ENOEXEC;
-	    break;
-	case DT_PLTREL:
-	    plttype = dp->d_un.d_val;
-	    if (plttype != DT_REL && plttype != DT_RELA)
-		return ENOEXEC;
-	    break;
+	for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
+		switch (dp->d_tag) {
+		case DT_HASH:
+		{
+			/* From src/libexec/rtld-elf/rtld.c */
+			const Elf_Hashelt *hashtab = (const Elf_Hashelt *)
+			    (ef->address + dp->d_un.d_ptr);
+			ef->nbuckets = hashtab[0];
+			ef->nchains = hashtab[1];
+			ef->buckets = hashtab + 2;
+			ef->chains = ef->buckets + ef->nbuckets;
+			break;
+		}
+		case DT_STRTAB:
+			ef->strtab = (caddr_t) (ef->address + dp->d_un.d_ptr);
+			break;
+		case DT_STRSZ:
+			ef->strsz = dp->d_un.d_val;
+			break;
+		case DT_SYMTAB:
+			ef->symtab = (Elf_Sym*) (ef->address + dp->d_un.d_ptr);
+			break;
+		case DT_SYMENT:
+			if (dp->d_un.d_val != sizeof(Elf_Sym))
+				return (ENOEXEC);
+			break;
+		case DT_PLTGOT:
+			ef->got = (Elf_Addr *) (ef->address + dp->d_un.d_ptr);
+			break;
+		case DT_REL:
+			ef->rel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
+			break;
+		case DT_RELSZ:
+			ef->relsize = dp->d_un.d_val;
+			break;
+		case DT_RELENT:
+			if (dp->d_un.d_val != sizeof(Elf_Rel))
+				return (ENOEXEC);
+			break;
+		case DT_JMPREL:
+			ef->pltrel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
+			break;
+		case DT_PLTRELSZ:
+			ef->pltrelsize = dp->d_un.d_val;
+			break;
+		case DT_RELA:
+			ef->rela = (const Elf_Rela *) (ef->address + dp->d_un.d_ptr);
+			break;
+		case DT_RELASZ:
+			ef->relasize = dp->d_un.d_val;
+			break;
+		case DT_RELAENT:
+			if (dp->d_un.d_val != sizeof(Elf_Rela))
+				return (ENOEXEC);
+			break;
+		case DT_PLTREL:
+			plttype = dp->d_un.d_val;
+			if (plttype != DT_REL && plttype != DT_RELA)
+				return (ENOEXEC);
+			break;
 #ifdef GDB
-	case DT_DEBUG:
-	    dp->d_un.d_ptr = (Elf_Addr) &r_debug;
-	    break;
+		case DT_DEBUG:
+			dp->d_un.d_ptr = (Elf_Addr)&r_debug;
+			break;
 #endif
+		}
 	}
-    }
 
-    if (plttype == DT_RELA) {
-	ef->pltrela = (const Elf_Rela *) ef->pltrel;
-	ef->pltrel = NULL;
-	ef->pltrelasize = ef->pltrelsize;
-	ef->pltrelsize = 0;
-    }
+	if (plttype == DT_RELA) {
+		ef->pltrela = (const Elf_Rela *)ef->pltrel;
+		ef->pltrel = NULL;
+		ef->pltrelasize = ef->pltrelsize;
+		ef->pltrelsize = 0;
+	}
 
-    ef->ddbsymtab = ef->symtab;
-    ef->ddbsymcnt = ef->nchains;
-    ef->ddbstrtab = ef->strtab;
-    ef->ddbstrcnt = ef->strsz;
+	ef->ddbsymtab = ef->symtab;
+	ef->ddbsymcnt = ef->nchains;
+	ef->ddbstrtab = ef->strtab;
+	ef->ddbstrcnt = ef->strsz;
 
-    return 0;
+	return (0);
 }
 
 static int
 parse_dpcpu(elf_file_t ef)
 { 
-    int count;
-    int error;
+	int count;
+	int error;
 
-    ef->pcpu_start = 0;
-    ef->pcpu_stop = 0;
-    error = link_elf_lookup_set(&ef->lf, "pcpu", (void ***)&ef->pcpu_start,
-                               (void ***)&ef->pcpu_stop, &count);
-    /* Error just means there is no pcpu set to relocate. */
-    if (error)
-        return (0);
-    count *= sizeof(void *);
-    /*
-     * Allocate space in the primary pcpu area.  Copy in our initialization
-     * from the data section and then initialize all per-cpu storage from
-     * that.
-     */
-    ef->pcpu_base = (Elf_Addr)(uintptr_t)dpcpu_alloc(count);
-    if (ef->pcpu_base == (Elf_Addr)NULL)
-        return (ENOSPC);
-    memcpy((void *)ef->pcpu_base, (void *)ef->pcpu_start, count);
-    dpcpu_copy((void *)ef->pcpu_base, count);
+	ef->pcpu_start = 0;
+	ef->pcpu_stop = 0;
+	error = link_elf_lookup_set(&ef->lf, "pcpu", (void ***)&ef->pcpu_start,
+	    (void ***)&ef->pcpu_stop, &count);
+	/* Error just means there is no pcpu set to relocate. */
+	if (error != 0)
+		return (0);
+	count *= sizeof(void *);
+	/*
+	 * Allocate space in the primary pcpu area.  Copy in our
+	 * initialization from the data section and then initialize
+	 * all per-cpu storage from that.
+	 */
+	ef->pcpu_base = (Elf_Addr)(uintptr_t)dpcpu_alloc(count);
+	if (ef->pcpu_base == 0)
+		return (ENOSPC);
+	memcpy((void *)ef->pcpu_base, (void *)ef->pcpu_start, count);
+	dpcpu_copy((void *)ef->pcpu_base, count);
 
-    return (0);
+	return (0);
 }
 
 #ifdef VIMAGE
 static int
 parse_vnet(elf_file_t ef)
 { 
-    int count;
-    int error;
+	int count;
+	int error;
 
-    ef->vnet_start = 0;
-    ef->vnet_stop = 0;
-    error = link_elf_lookup_set(&ef->lf, "vnet", (void ***)&ef->vnet_start,
-                               (void ***)&ef->vnet_stop, &count);
-    /* Error just means there is no vnet data set to relocate. */
-    if (error)
-        return (0);
-    count *= sizeof(void *);
-    /*
-     * Allocate space in the primary vnet area.  Copy in our initialization
-     * from the data section and then initialize all per-vnet storage from
-     * that.
-     */
-    ef->vnet_base = (Elf_Addr)(uintptr_t)vnet_data_alloc(count);
-    if (ef->vnet_base == (Elf_Addr)NULL)
-        return (ENOSPC);
-    memcpy((void *)ef->vnet_base, (void *)ef->vnet_start, count);
-    vnet_data_copy((void *)ef->vnet_base, count);
+	ef->vnet_start = 0;
+	ef->vnet_stop = 0;
+	error = link_elf_lookup_set(&ef->lf, "vnet", (void ***)&ef->vnet_start,
+	    (void ***)&ef->vnet_stop, &count);
+	/* Error just means there is no vnet data set to relocate. */
+	if (error != 0)
+		return (0);
+	count *= sizeof(void *);
+	/*
+	 * Allocate space in the primary vnet area.  Copy in our
+	 * initialization from the data section and then initialize
+	 * all per-vnet storage from that.
+	 */
+	ef->vnet_base = (Elf_Addr)(uintptr_t)vnet_data_alloc(count);
+	if (ef->vnet_base == 0)
+		return (ENOSPC);
+	memcpy((void *)ef->vnet_base, (void *)ef->vnet_start, count);
+	vnet_data_copy((void *)ef->vnet_base, count);
 
-    return (0);
+	return (0);
 }
 #endif
 
 static int
 link_elf_link_preload(linker_class_t cls,
-		      const char* filename, linker_file_t *result)
+    const char* filename, linker_file_t *result)
 {
-    caddr_t		modptr, baseptr, sizeptr, dynptr;
-    char		*type;
-    elf_file_t		ef;
-    linker_file_t	lf;
-    int			error;
-    vm_offset_t		dp;
-
-    /* Look to see if we have the file preloaded */
-    modptr = preload_search_by_name(filename);
-    if (modptr == NULL)
-	return ENOENT;
-
-    type = (char *)preload_search_info(modptr, MODINFO_TYPE);
-    baseptr = preload_search_info(modptr, MODINFO_ADDR);
-    sizeptr = preload_search_info(modptr, MODINFO_SIZE);
-    dynptr = preload_search_info(modptr, MODINFO_METADATA|MODINFOMD_DYNAMIC);
-    if (type == NULL ||
-	(strcmp(type, "elf" __XSTRING(__ELF_WORD_SIZE) " module") != 0 &&
-	 strcmp(type, "elf module") != 0))
-	return (EFTYPE);
-    if (baseptr == NULL || sizeptr == NULL || dynptr == NULL)
-	return (EINVAL);
-
-    lf = linker_make_file(filename, &link_elf_class);
-    if (lf == NULL) {
-	return ENOMEM;
-    }
+	caddr_t modptr, baseptr, sizeptr, dynptr;
+	char *type;
+	elf_file_t ef;
+	linker_file_t lf;
+	int error;
+	vm_offset_t dp;
+
+	/* Look to see if we have the file preloaded */
+	modptr = preload_search_by_name(filename);
+	if (modptr == NULL)
+		return (ENOENT);
+
+	type = (char *)preload_search_info(modptr, MODINFO_TYPE);
+	baseptr = preload_search_info(modptr, MODINFO_ADDR);
+	sizeptr = preload_search_info(modptr, MODINFO_SIZE);
+	dynptr = preload_search_info(modptr,
+	    MODINFO_METADATA | MODINFOMD_DYNAMIC);
+	if (type == NULL ||
+	    (strcmp(type, "elf" __XSTRING(__ELF_WORD_SIZE) " module") != 0 &&
+	     strcmp(type, "elf module") != 0))
+		return (EFTYPE);
+	if (baseptr == NULL || sizeptr == NULL || dynptr == NULL)
+		return (EINVAL);
+
+	lf = linker_make_file(filename, &link_elf_class);
+	if (lf == NULL)
+		return (ENOMEM);
 
-    ef = (elf_file_t) lf;
-    ef->preloaded = 1;
-    ef->modptr = modptr;
-    ef->address = *(caddr_t *)baseptr;
+	ef = (elf_file_t) lf;
+	ef->preloaded = 1;
+	ef->modptr = modptr;
+	ef->address = *(caddr_t *)baseptr;
 #ifdef SPARSE_MAPPING
-    ef->object = 0;
+	ef->object = 0;
 #endif
-    dp = (vm_offset_t)ef->address + *(vm_offset_t *)dynptr;
-    ef->dynamic = (Elf_Dyn *)dp;
-    lf->address = ef->address;
-    lf->size = *(size_t *)sizeptr;
-
-    error = parse_dynamic(ef);
-    if (error == 0)
-        error = parse_dpcpu(ef);
+	dp = (vm_offset_t)ef->address + *(vm_offset_t *)dynptr;
+	ef->dynamic = (Elf_Dyn *)dp;
+	lf->address = ef->address;
+	lf->size = *(size_t *)sizeptr;
+
+	error = parse_dynamic(ef);
+	if (error == 0)
+		error = parse_dpcpu(ef);
 #ifdef VIMAGE
-    if (error == 0)
-	error = parse_vnet(ef);
+	if (error == 0)
+		error = parse_vnet(ef);
 #endif
-    if (error) {
-	linker_file_unload(lf, LINKER_UNLOAD_FORCE);
-	return error;
-    }
-    link_elf_reloc_local(lf);
-    *result = lf;
-    return (0);
+	if (error != 0) {
+		linker_file_unload(lf, LINKER_UNLOAD_FORCE);
+		return (error);
+	}
+	link_elf_reloc_local(lf);
+	*result = lf;
+	return (0);
 }
 
 static int
 link_elf_link_preload_finish(linker_file_t lf)
 {
-    elf_file_t		ef;
-    int error;
+	elf_file_t ef;
+	int error;
 
-    ef = (elf_file_t) lf;
+	ef = (elf_file_t) lf;
 #if 0	/* this will be more trouble than it's worth for now */
-    for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
-	if (dp->d_tag != DT_NEEDED)
-	    continue;
-	modname = ef->strtab + dp->d_un.d_val;
-	error = linker_load_module(modname, lf);
-	if (error)
-	    goto out;
+	for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
+		if (dp->d_tag != DT_NEEDED)
+			continue;
+		modname = ef->strtab + dp->d_un.d_val;
+		error = linker_load_module(modname, lf);
+		if (error != 0)
+			goto out;
     }
 #endif
-    error = relocate_file(ef);
-    if (error)
-	return error;
-    (void)link_elf_preload_parse_symbols(ef);
+	error = relocate_file(ef);
+	if (error != 0)
+		return (error);
+	(void)link_elf_preload_parse_symbols(ef);
 
-    return (link_elf_link_common_finish(lf));
+	return (link_elf_link_common_finish(lf));
 }
 
 static int
 link_elf_load_file(linker_class_t cls, const char* filename,
-	linker_file_t* result)
+    linker_file_t* result)
 {
-    struct nameidata nd;
-    struct thread* td = curthread;	/* XXX */
-    Elf_Ehdr *hdr;
-    caddr_t firstpage;
-    int nbytes, i;
-    Elf_Phdr *phdr;
-    Elf_Phdr *phlimit;
-    Elf_Phdr *segs[MAXSEGS];
-    int nsegs;
-    Elf_Phdr *phdyn;
-    Elf_Phdr *phphdr;
-    caddr_t mapbase;
-    size_t mapsize;
-    Elf_Off base_offset;
-    Elf_Addr base_vaddr;
-    Elf_Addr base_vlimit;
-    int error = 0;
-    int resid, flags;
-    elf_file_t ef;
-    linker_file_t lf;
-    Elf_Shdr *shdr;
-    int symtabindex;
-    int symstrindex;
-    int symcnt;
-    int strcnt;
-    int vfslocked;
-
-    shdr = NULL;
-    lf = NULL;
-
-    NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, filename, td);
-    flags = FREAD;
-    error = vn_open(&nd, &flags, 0, NULL);
-    if (error)
-	return error;
-    vfslocked = NDHASGIANT(&nd);
-    NDFREE(&nd, NDF_ONLY_PNBUF);
-    if (nd.ni_vp->v_type != VREG) {
-	error = ENOEXEC;
-	firstpage = NULL;
-	goto out;
-    }
+	struct nameidata nd;
+	struct thread* td = curthread;	/* XXX */
+	Elf_Ehdr *hdr;
+	caddr_t firstpage;
+	int nbytes, i;
+	Elf_Phdr *phdr;
+	Elf_Phdr *phlimit;
+	Elf_Phdr *segs[MAXSEGS];
+	int nsegs;
+	Elf_Phdr *phdyn;
+	Elf_Phdr *phphdr;
+	caddr_t mapbase;
+	size_t mapsize;
+	Elf_Off base_offset;
+	Elf_Addr base_vaddr;
+	Elf_Addr base_vlimit;
+	int error = 0;
+	int resid, flags;
+	elf_file_t ef;
+	linker_file_t lf;
+	Elf_Shdr *shdr;
+	int symtabindex;
+	int symstrindex;
+	int symcnt;
+	int strcnt;
+	int vfslocked;
+
+	shdr = NULL;

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201106082136.p58LaaHN048653>