PERFORCE change 49907 for review
Peter Wemm
peter at FreeBSD.org
Mon Mar 29 11:12:40 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=49907
Change 49907 by peter at peter_daintree on 2004/03/29 11:12:00
move '*' position to a more style compliant place.
Affected files ...
.. //depot/projects/hammer/sys/kern/link_elf_obj.c#5 edit
Differences ...
==== //depot/projects/hammer/sys/kern/link_elf_obj.c#5 (text+ko) ====
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 1998-2000 Doug Rabson
+ * Copyright (c) 2004 Peter Wemm
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -59,7 +60,13 @@
Elf_Off base_offset;
Elf_Off filesz;
int flags;
-} Elf_loadent;
+} Elf_progent;
+
+typedef struct {
+ Elf_Addr base_vaddr;
+ Elf_Off filesz;
+ int flags;
+} Elf_nobitent;
typedef struct {
const Elf_Rel *rel;
@@ -74,36 +81,40 @@
typedef struct elf_file {
struct linker_file lf; /* Common fields */
- caddr_t address; /* Relocation address */
+ caddr_t address; /* Relocation address */ /* XXX OBE */
+
+ Elf_progent *progtab;
+ int nprogtab;
+
+ Elf_nobitent *nobittab;
+ int nnobittab;
- Elf_loadseg *segtab;
- int nsegtab;
Elf_relaent *relatab;
int nrela;
Elf_relent *reltab;
int nrel;
- 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 symbase; /* malloc'ed symbol base */
caddr_t strbase; /* malloc'ed string base */
} *elf_file_t;
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_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*);
+ linker_symval_t *);
static int link_elf_search_symbol(linker_file_t, caddr_t value,
- c_linker_sym_t* sym, long* diffp);
+ c_linker_sym_t *sym, long *diffp);
static void link_elf_unload_file(linker_file_t);
static int link_elf_lookup_set(linker_file_t, const char *,
@@ -134,7 +145,7 @@
link_elf_methods, sizeof(struct elf_file)
};
-static int relocate_file(elf_file_t ef);
+static int relocate_file(elf_file_t ef);
static void
link_elf_error(const char *s)
@@ -160,7 +171,7 @@
}
static void
-link_elf_init(void* arg)
+link_elf_init(void *arg)
{
linker_add_class(&link_elf_class);
@@ -169,7 +180,7 @@
SYSINIT(link_elf, SI_SUB_KLD, SI_ORDER_SECOND, link_elf_init, 0);
static int
-link_elf_link_preload(linker_class_t cls, const char* filename,
+link_elf_link_preload(linker_class_t cls, const char *filename,
linker_file_t *result)
{
return (EFTYPE);
@@ -182,11 +193,11 @@
}
static int
-link_elf_load_file(linker_class_t cls, const char* filename,
- linker_file_t* result)
+link_elf_load_file(linker_class_t cls, const char *filename,
+ linker_file_t *result)
{
struct nameidata nd;
- struct thread* td = curthread; /* XXX */
+ struct thread *td = curthread; /* XXX */
Elf_Ehdr *hdr;
caddr_t firstpage;
int nbytes, i;
@@ -243,7 +254,7 @@
nbytes = PAGE_SIZE - resid;
if (error)
goto out;
- if (nbytes < sizeof(Elf_Ehdr))
+ if (nbytes < sizeof(Elf_Ehdr)){
error = ENOEXEC;
goto out;
}
@@ -297,6 +308,19 @@
goto out;
}
+ lf = linker_make_file(filename, &link_elf_class);
+ if (!lf) {
+ error = ENOMEM;
+ goto out;
+ }
+
+ ef = (elf_file_t) lf;
+ ef->address = malloc(mapsize, M_LINKER, M_WAITOK);
+ if (!ef->address) {
+ error = ENOMEM;
+ goto out;
+ }
+
/*
* Scan the program header entries, and save key information.
*
@@ -312,20 +336,20 @@
shdr = (Elf_Shdr *)shtbuf;
shlimit = shdr + hdr->e_phnum;
- nbits = 0;
- nnobits = 0;
+ ef->nprogent = 0;
+ ef->nnobits = 0;
nsym = 0;
- nrel = 0;
- nrela = 0;
+ ef->nrel = 0;
+ ef->nrela = 0;
symtabindex = -1;
symstrindex = -1;
for (i = 0; i < hdr->e_shnum; i++) {
switch (shdr[i].sh_type) {
case SHT_PROGBITS:
- nprogbits++;
+ ef->nprogtab++;
break;
case SHT_NOBITS:
- nnobits++;
+ ef->nnobittab++;
break;
case SHT_SYMTAB:
nsym++;
@@ -333,10 +357,10 @@
symstrindex = shdr[i].sh_link;
break;
case SHT_REL:
- nrel++;
+ ef->nreltab++;
break;
case SHT_RELA:
- nrela++;
+ ef->nrelatab++;
break;
}
}
@@ -358,25 +382,35 @@
}
/* XXX *************** STEP 2 GOES HERE ************* XXX */
+ if (ef->nprogtab != 0)
+ ef->progtab = malloc(ef->nprogtab * sizeof(*ef->progtab), M_LINKER, M_WAITOK);
+ if (ef->nnobittab != 0)
+ ef->nobittab = malloc(ef->nobbittab * sizeof(*ef->nobittab), M_LINKER, M_WAITOK);
+ if (ef->nreltab != 0)
+ ef->reltab = malloc(ef->nreltab * sizeof(*ef->reltab), M_LINKER, M_WAITOK);
+ if (ef->nrelatab != 0)
+ ef->relatab = malloc(ef->nrelatab * sizeof(*ef->relatab), M_LINKER, M_WAITOK);
+
+ ef->ddbsymcnt = shdr[symtabindex].sh_size / sizeof(Elf_Sym);
+ ef->ddbsymbase = malloc(shdr[symtabindex].sh_size, M_LINKER, M_WAITOK);
+
+ ef->ddbstrcnt = shdr[symstrindex].sh_size;
+ ef->ddbstrbase = malloc(shdr[symstrindex].sh_size, M_LINKER, M_WAITOK);
+
+ if (ef->symbase == NULL || ef->strbase == NULL) {
+ error = ENOMEM;
+ goto out;
+ }
+
for (i = 0; i < hdr->e_shnum; i++) {
switch (shdr[i].sh_type) {
+ }
}
+
/* XXX *************** STEP 3 GOES HERE ************* XXX */
/* Load the symbol table. */
- if (symtabindex < 0 || symstrindex < 0)
- goto nosyms;
-
- symcnt = shdr[symtabindex].sh_size;
- ef->symbase = malloc(symcnt, M_LINKER, M_WAITOK);
- strcnt = shdr[symstrindex].sh_size;
- ef->strbase = malloc(strcnt, M_LINKER, M_WAITOK);
-
- if (ef->symbase == NULL || ef->strbase == NULL) {
- error = ENOMEM;
- goto out;
- }
error = vn_rdwr(UIO_READ, nd.ni_vp,
ef->symbase, symcnt, shdr[symtabindex].sh_offset,
UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
@@ -390,10 +424,6 @@
if (error)
goto out;
- ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
- ef->ddbsymtab = (const Elf_Sym *)ef->symbase;
- ef->ddbstrcnt = strcnt;
- ef->ddbstrtab = ef->strbase;
/* XXX *************** STEP 4 GOES HERE ************* XXX */
@@ -406,18 +436,6 @@
base_vlimit = round_page(segs[1]->p_vaddr + segs[1]->p_memsz);
mapsize = base_vlimit - base_vaddr;
- lf = linker_make_file(filename, &link_elf_class);
- if (!lf) {
- error = ENOMEM;
- goto out;
- }
-
- ef = (elf_file_t) lf;
- ef->address = malloc(mapsize, M_LINKER, M_WAITOK);
- if (!ef->address) {
- error = ENOMEM;
- goto out;
- }
mapbase = ef->address;
/*
@@ -452,11 +470,11 @@
if (error)
goto out;
- nosyms:
+nosyms:
*result = lf;
- out:
+out:
if (error && lf)
linker_file_unload(lf);
if (shdr)
@@ -566,11 +584,11 @@
}
static int
-link_elf_lookup_symbol(linker_file_t lf, const char* name, c_linker_sym_t* sym)
+link_elf_lookup_symbol(linker_file_t lf, const char *name, c_linker_sym_t *sym)
{
elf_file_t ef = (elf_file_t) lf;
unsigned long symnum;
- const Elf_Sym* symp;
+ const Elf_Sym *symp;
const char *strp;
int i;
@@ -593,10 +611,10 @@
}
static int
-link_elf_symbol_values(linker_file_t lf, c_linker_sym_t sym, linker_symval_t* symval)
+link_elf_symbol_values(linker_file_t lf, c_linker_sym_t sym, linker_symval_t *symval)
{
elf_file_t ef = (elf_file_t) lf;
- const Elf_Sym* es = (const Elf_Sym*) sym;
+ const Elf_Sym *es = (const Elf_Sym*) sym;
if (es >= ef->ddbsymtab && es < (ef->ddbsymtab + ef->ddbsymcnt)) {
symval->name = ef->ddbstrtab + es->st_name;
@@ -609,14 +627,14 @@
static int
link_elf_search_symbol(linker_file_t lf, caddr_t value,
- c_linker_sym_t* sym, long* diffp)
+ c_linker_sym_t *sym, long *diffp)
{
elf_file_t ef = (elf_file_t) lf;
u_long off = (uintptr_t) (void *) value;
u_long diff = off;
u_long st_value;
- const Elf_Sym* es;
- const Elf_Sym* best = 0;
+ const Elf_Sym *es;
+ const Elf_Sym *best = 0;
int i;
for (i = 0, es = ef->ddbsymtab; i < ef->ddbsymcnt; i++, es++) {
@@ -705,7 +723,7 @@
link_elf_each_function_name(linker_file_t file,
int (*callback)(const char *, void *), void *opaque) {
elf_file_t ef = (elf_file_t)file;
- const Elf_Sym* symp;
+ const Elf_Sym *symp;
int i, error;
/* Exhaustive search */
More information about the p4-projects
mailing list