PERFORCE change 49986 for review
Peter Wemm
peter at FreeBSD.org
Tue Mar 30 11:02:21 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=49986
Change 49986 by peter at peter_daintree on 2004/03/30 11:01:54
bah, the code/data/bss needs to be in a single block so that profiling
and gdb -k can see it as a single entity. Not to mention the kldstat
output that shows the base/size.
Affected files ...
.. //depot/projects/hammer/sys/kern/link_elf_obj.c#8 edit
Differences ...
==== //depot/projects/hammer/sys/kern/link_elf_obj.c#8 (text+ko) ====
@@ -208,6 +208,7 @@
caddr_t firstpage;
int nbytes, i;
int nsegs;
+ caddr_t mapbase;
size_t mapsize;
Elf_Addr base_vlimit;
int error = 0;
@@ -221,6 +222,7 @@
int strcnt;
int nsym;
int pb, nb, rl, ra;
+ int alignmask;
GIANT_REQUIRED;
@@ -404,29 +406,41 @@
nb = 0;
rl = 0;
ra = 0;
+ alignmask = 0;
for (i = 0; i < hdr->e_shnum; i++) {
switch (shdr[i].sh_type) {
case SHT_PROGBITS:
- ef->progtab[pb].addr = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK);
+ case SHT_NOBITS:
+ alignmask = (1u << shdr[i].sh_addralign) - 1;
+ mapsize += alignmask;
+ mapsize &= ~alignmask;
+ break;
+ }
+
+ switch (shdr[i].sh_type) {
+ case SHT_PROGBITS:
+ ef->progtab[pb].addr = mapsize;
ef->progtab[pb].fileoff = shdr[i].sh_offset;
ef->progtab[pb].size = shdr[i].sh_size;
ef->progtab[pb].align = shdr[i].sh_addralign;
+ mapsize += shdr[i].sh_size;
pb++;
break;
case SHT_NOBITS:
- ef->nobittab[nb].addr = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK | M_ZERO);
+ ef->nobittab[nb].addr = mapsize;
ef->nobittab[nb].size = shdr[i].sh_size;
ef->nobittab[nb].align = shdr[i].sh_addralign;
+ mapsize += shdr[i].sh_size;
nb++;
break;
case SHT_REL:
- ef->reltab[rl].addr = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK);
+ ef->reltab[rl].addr = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK)
ef->reltab[rl].fileoff = shdr[i].sh_offset;
ef->reltab[rl].size = shdr[i].sh_size;
rl++;
break;
case SHT_RELA:
- ef->relatab[ra].addr = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK);
+ ef->relatab[ra].addr = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK)
ef->relatab[ra].fileoff = shdr[i].sh_offset;
ef->relatab[ra].size = shdr[i].sh_size;
ra++;
@@ -441,6 +455,18 @@
panic("lots rel");
if (ra != ef->nrelatab)
panic("lots rela");
+
+ 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 */
+ 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 */
More information about the p4-projects
mailing list