PERFORCE change 49991 for review
Peter Wemm
peter at FreeBSD.org
Tue Mar 30 11:43:13 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=49991
Change 49991 by peter at peter_daintree on 2004/03/30 11:43:04
tidy up a bit.
Affected files ...
.. //depot/projects/hammer/sys/kern/link_elf_obj.c#9 edit
Differences ...
==== //depot/projects/hammer/sys/kern/link_elf_obj.c#9 (text+ko) ====
@@ -110,7 +110,6 @@
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 *);
static int link_elf_link_preload_finish(linker_file_t);
@@ -159,23 +158,6 @@
printf("kldload: %s\n", s);
}
-/*
- * Actions performed after linking/loading both the preloaded kernel and any
- * modules;
- */
-static int
-link_elf_link_common_finish(linker_file_t lf)
-{
- int error;
-
- /* Notify MD code that a module is being loaded. */
- error = elf_cpu_load_file(lf);
- if (error)
- return (error);
-
- return (0);
-}
-
static void
link_elf_init(void *arg)
{
@@ -292,7 +274,7 @@
goto out;
}
- /* Read in the section header */
+ /* Allocate and read in the section header */
nbytes = hdr->e_shnum * hdr->e_shentsize;
if (nbytes == 0 || hdr->e_shoff == 0 ||
hdr->e_shentsize != sizeof(Elf_Shdr)) {
@@ -320,21 +302,7 @@
}
ef = (elf_file_t) lf;
- /*
- * Scan the program header entries, and save key information.
- *
- * We rely on there being exactly two load segments, text and data,
- * in that order.
- *
- * XXX do several passes of section table instead.
- * XXX 1) count various things needed to size arrays
- * XXX 2) grab info about things like PROGBITS/REL/RELA/STRTAB/SYMTAB
- * XXX 3) read the string and symbol tables so we can do relocations etc
- * XXX 4) (later on) load the rest of the entries.
- */
- shdr = (Elf_Shdr *)shtbuf;
- shlimit = shdr + hdr->e_phnum;
-
+ /* Scan the section header for information and table sizing. */
ef->nprogent = 0;
ef->nnobits = 0;
nsym = 0;
@@ -369,6 +337,7 @@
goto out;
}
if (nsym != 1) {
+ /* Only allow one symbol table for now */
link_elf_error("file has no valid symbol table");
error = ENOEXEC;
goto out;
@@ -380,7 +349,8 @@
goto out;
}
-/* XXX *************** STEP 2 GOES HERE ************* XXX */
+ /* Allocate space for tracking the load chunks */
+ /* XXX - maybe unneeded. might be able to use the shdr directly */
if (ef->nprogtab != 0)
ef->progtab = malloc(ef->nprogtab * sizeof(*ef->progtab), M_LINKER, M_WAITOK);
if (ef->nnobittab != 0)
@@ -391,6 +361,7 @@
ef->relatab = malloc(ef->nrelatab * sizeof(*ef->relatab), M_LINKER, M_WAITOK);
/* XXX check for failures */
+ /* Space for symbol table */
ef->ddbsymcnt = shdr[symtabindex].sh_size / sizeof(Elf_Sym);
ef->ddbsymbase = malloc(shdr[symtabindex].sh_size, M_LINKER, M_WAITOK);
@@ -402,6 +373,7 @@
goto out;
}
+ /* Size code/data(progbits) and bss(nobits). allocate space for relocs */
pb = 0;
nb = 0;
rl = 0;
@@ -456,19 +428,23 @@
if (ra != ef->nrelatab)
panic("lots rela");
+ /*
+ * We know how much space we need for the text/data/bss/etc.
+ * This stuff needs to be in a single chunk so that profiling etc
+ * can get the bounds and gdb can associate offsets with modules
+ */
mapbase = malloc(mapsize, M_LINKER, M_WAITOK | M_ZERO);
if (mapbase == NULL) {
error = ENOMEM;
goto out;
}
- /* Now that we have the mapping address, plug in the offsets */
+ /* Add the base address to the previously calculated/aligned offsets */
for (i = 0; i < ef->nprogtab)
ef->progtab[i].addr += mapbase;
for (i = 0; i < ef->nnobittab)
ef->nobittab[i].addr += mapbase;
-/* XXX *************** STEP 3 GOES HERE ************* XXX */
/* Load the symbol table. */
error = vn_rdwr(UIO_READ, nd.ni_vp,
@@ -483,6 +459,8 @@
&resid, td);
if (error)
goto out;
+
+ /* Read in the text/data/set/etc sections */
for (i = 0; i < ef->nprogtab; i++) {
error = vn_rdwr(UIO_READ, nd.ni_vp,
ef->progtab[pb].addr,
@@ -493,6 +471,11 @@
if (error)
goto out;
}
+
+ /*
+ * Read in relocation tables. Platforms use rel or rela, but
+ * usually not both.
+ */
for (i = 0; i < ef->nreltab; i++) {
error = vn_rdwr(UIO_READ, nd.ni_vp,
ef->reltab[pb].addr,
@@ -515,21 +498,25 @@
}
-/* XXX *************** STEP 4 GOES HERE ************* XXX */
-
+ /* Inform the kld system about the situation */
lf->address = ef->address;
lf->size = mapsize;
+ /* Local intra-module relocations */
link_elf_reloc_local(lf);
+ /* Pull in dependencies */
error = linker_load_dependencies(lf);
if (error)
goto out;
+
+ /* External relocations */
error = relocate_file(ef);
if (error)
goto out;
- error = link_elf_link_common_finish(lf);
+ /* Notify MD code that a module is being loaded. */
+ error = elf_cpu_load_file(lf);
if (error)
goto out;
@@ -784,7 +771,8 @@
static int
link_elf_each_function_name(linker_file_t file,
- int (*callback)(const char *, void *), void *opaque) {
+ int (*callback)(const char *, void *), void *opaque)
+{
elf_file_t ef = (elf_file_t)file;
const Elf_Sym *symp;
int i, error;
More information about the p4-projects
mailing list