PERFORCE change 50021 for review

Peter Wemm peter at FreeBSD.org
Tue Mar 30 16:55:52 PST 2004


http://perforce.freebsd.org/chv.cgi?CH=50021

Change 50021 by peter at peter_daintree on 2004/03/30 16:55:34

	begin debugging this stuff  (real kernel hackers only need printf!)

Affected files ...

.. //depot/projects/hammer/sys/kern/link_elf_obj.c#13 edit

Differences ...

==== //depot/projects/hammer/sys/kern/link_elf_obj.c#13 (text+ko) ====

@@ -87,7 +87,7 @@
 
 typedef struct elf_file {
 	struct linker_file lf;		/* Common fields */
-	caddr_t		address;	/* Relocation address */	/* XXX OBE */
+	caddr_t		address;	/* Relocation address */
 
 	Elf_progent	*progtab;
 	int		nprogtab;
@@ -229,7 +229,7 @@
 		error = ENOMEM;
 		goto out;
 	}
-	error = vn_rdwr(UIO_READ, nd.ni_vp, hdr, PAGE_SIZE, 0,
+	error = vn_rdwr(UIO_READ, nd.ni_vp, (void *)hdr, PAGE_SIZE, 0,
 	    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
 	    &resid, td);
 	if (error)
@@ -267,6 +267,8 @@
 		goto out;
 	}
 
+printf("elf_load_obj: initial checks look ok!\n");
+
 	/* Allocate and read in the section header */
 	nbytes = hdr->e_shnum * hdr->e_shentsize;
 	if (nbytes == 0 || hdr->e_shoff == 0 ||
@@ -275,6 +277,7 @@
 		goto out;
 	}
 	shdr = malloc(nbytes, M_LINKER, M_WAITOK | M_ZERO);
+printf("section table %d bytes allocated at %p\n", nbytes, shdr);
 	if (shdr == NULL) {
 		error = ENOMEM;
 		goto out;
@@ -288,6 +291,7 @@
 		goto out;
 	}
 
+printf("section table read in ok\n");
 	lf = linker_make_file(filename, &link_elf_class);
 	if (!lf) {
 		error = ENOMEM;
@@ -295,6 +299,7 @@
 	}
 	ef = (elf_file_t) lf;
 
+printf("scan header1\n");
 	/* Scan the section header for information and table sizing. */
 	ef->nprogtab = 0;
 	ef->nnobittab = 0;
@@ -306,22 +311,31 @@
 	for (i = 0; i < hdr->e_shnum; i++) {
 		switch (shdr[i].sh_type) {
 		case SHT_PROGBITS:
+printf("scan: progbits!\n");
 			ef->nprogtab++;
 			break;
 		case SHT_NOBITS:
+printf("scan: nobits!\n");
 			ef->nnobittab++;
 			break;
 		case SHT_SYMTAB:
+printf("scan: symtab!\n");
 			nsym++;
 			symtabindex = i;
 			symstrindex = shdr[i].sh_link;
+printf("[symtab peer is %d]\n", symstrindex);
 			break;
 		case SHT_REL:
+printf("scan: rel!\n");
 			ef->nrel++;
 			break;
 		case SHT_RELA:
+printf("scan: rela!\n");
 			ef->nrela++;
 			break;
+		default:
+printf("scan: unknown section type %d\n", shdr[i].sh_type);
+			break;
 		}
 	}
 	if (ef->nprogtab == 0 && ef->nnobittab == 0) {
@@ -372,13 +386,16 @@
 	rl = 0;
 	ra = 0;
 	alignmask = 0;
+printf("scan pass 2\n");
 	for (i = 0; i < hdr->e_shnum; i++) {
 		switch (shdr[i].sh_type) {
 		case SHT_PROGBITS:
 		case SHT_NOBITS:
 			alignmask = (1u << shdr[i].sh_addralign) - 1;
+printf("addralign %ld mask %d\n", shdr[i].sh_addralign, alignmask);
 			mapsize += alignmask;
 			mapsize &= ~alignmask;
+printf("mapsize now at %ld\n", mapsize);
 			break;
 		}
 
@@ -388,6 +405,7 @@
 			ef->progtab[pb].fileoff = shdr[i].sh_offset;
 			ef->progtab[pb].filesz = shdr[i].sh_size;
 			ef->progtab[pb].align = shdr[i].sh_addralign;
+printf("progbits at %ld\n", mapsize);
 			mapsize += shdr[i].sh_size;
 			pb++;
 			break;
@@ -395,17 +413,20 @@
 			ef->nobittab[nb].addr = (void *)(uintptr_t)mapsize;
 			ef->nobittab[nb].memsz = shdr[i].sh_size;
 			ef->nobittab[nb].align = shdr[i].sh_addralign;
+printf("nobits at %ld\n", mapsize);
 			mapsize += shdr[i].sh_size;
 			nb++;
 			break;
 		case SHT_REL:
 			ef->reltab[rl].rel = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK);
+printf("rel %ld allocated at %p\n", shdr[i].sh_size, ef->reltab[rl].rel);
 			ef->reltab[rl].fileoff = shdr[i].sh_offset;
 			ef->reltab[rl].filesz = shdr[i].sh_size;
 			rl++;
 			break;
 		case SHT_RELA:
 			ef->relatab[ra].rela = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK);
+printf("rela %ld allocated at %p\n", shdr[i].sh_size, ef->relatab[ra].rela);
 			ef->relatab[ra].fileoff = shdr[i].sh_offset;
 			ef->relatab[ra].filesz = shdr[i].sh_size;
 			ra++;
@@ -431,14 +452,20 @@
 		error = ENOMEM;
 		goto out;
 	}
+printf("final mapbase %p, final mapsize %ld\n", mapbase, mapsize);
 
 	/* Add the base address to the previously calculated/aligned offsets */
-	for (i = 0; i < ef->nprogtab; i++)
+	for (i = 0; i < ef->nprogtab; i++) {
 		ef->progtab[i].addr = mapbase + (uintptr_t)ef->progtab[i].addr;
-	for (i = 0; i < ef->nnobittab; i++)
+printf("progtab[%d] at %p\n", i, ef->progtab[i].addr);
+	}
+	for (i = 0; i < ef->nnobittab; i++) {
 		ef->nobittab[i].addr = mapbase + (uintptr_t)ef->nobittab[i].addr;
+printf("nobittab[%d] at %p\n", i, ef->nobittab[i].addr);
+	}
 	
 
+printf("reading symbols\n");
 	/* Load the symbol table. */
 	error = vn_rdwr(UIO_READ, nd.ni_vp,
 	    ef->symbase, ef->ddbsymcnt, shdr[symtabindex].sh_offset,
@@ -446,6 +473,7 @@
 	    &resid, td);
 	if (error)
 		goto out;
+printf("reading strings\n");
 	error = vn_rdwr(UIO_READ, nd.ni_vp,
 	    ef->strbase, ef->ddbstrcnt, shdr[symstrindex].sh_offset,
 	    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
@@ -453,8 +481,10 @@
 	if (error)
 		goto out;
 
+printf("reading progbits\n");
 	/* Read in the text/data/set/etc sections */
 	for (i = 0; i < ef->nprogtab; i++) {
+printf("reading progbits %d\n", i);
 		error = vn_rdwr(UIO_READ, nd.ni_vp,
 		    ef->progtab[pb].addr,
 		    ef->progtab[pb].filesz,
@@ -469,6 +499,7 @@
 	 * Read in relocation tables.  Platforms use rel or rela, but
 	 * usually not both.
 	 */
+printf("reading rel\n");
 	for (i = 0; i < ef->nrel; i++) {
 		error = vn_rdwr(UIO_READ, nd.ni_vp,
 		    (void *)ef->reltab[pb].rel,
@@ -479,6 +510,7 @@
 		if (error)
 			goto out;
 	}
+printf("reading rela\n");
 	for (i = 0; i < ef->nrela; i++) {
 		error = vn_rdwr(UIO_READ, nd.ni_vp,
 		    (void *)ef->relatab[pb].rela,
@@ -491,31 +523,38 @@
 	}
 
 
+printf("now do post link stuff\n");
 	/* Inform the kld system about the situation */
 	lf->address = ef->address;
 	lf->size = mapsize;
 
+printf("do intra-module relocs\n");
 	/* Local intra-module relocations */
 	link_elf_reloc_local(lf);
 
+printf("load dependencies\n");
 	/* Pull in dependencies */
 	error = linker_load_dependencies(lf);
 	if (error)
 		goto out;
 
+printf("do external relocs\n");
 	/* External relocations */
 	error = relocate_file(ef);
 	if (error)
 		goto out;
 
+printf("notify MD code\n");
 	/* Notify MD code that a module is being loaded. */
 	error = elf_cpu_load_file(lf);
 	if (error)
 		goto out;
 
+printf("HOLY SHIT! WE MADE IT!!!\n");
 	*result = lf;
 
 out:
+printf("link_elf_obj: finishing up! error = %d\n", error);
 	if (error && lf)
 		linker_file_unload(lf);
 	if (shdr)


More information about the p4-projects mailing list