[TESTING]: ClangBSD branch needs testing before the import to HEAD

Dimitry Andric dimitry at andric.com
Mon May 31 18:10:32 UTC 2010


On 2010-05-31 19:44, Alexandre "Sunny" Kovalenko wrote:
> What is the good way to do installworld from CURRENT-snapshot to
> ClangBSD? Half way through some shared object (run-time loader?) gets
> overwritten and it is all signal 11 from there on.

Hi Alexandre,

A fix for this has already been applied in head, but it was not yet
merged back to clangbsd.  That is going to happen soon.  In the
meantime, please:
- Use /rescue to rollback /libexec/ld-elf.so.1 (from the backup in
  /libexec/ld-elf.so.1.old)
- Apply the patch I have attached to your clangbsd source dir
- Rebuild libexec/rtld-elf in there

Then you should be able to do installworld without any problems.
-------------- next part --------------
Index: libexec/rtld-elf/arm/reloc.c
===================================================================
--- libexec/rtld-elf/arm/reloc.c	(revision 208620)
+++ libexec/rtld-elf/arm/reloc.c	(working copy)
@@ -245,7 +245,6 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	const Elf_Rel *rellim;
 	const Elf_Rel *rel;
 	SymCache *cache;
-	int bytes = obj->nchains * sizeof(SymCache);
 	int r = -1;
 	
 	/* The relocation for the dynamic loader has already been done. */
@@ -255,10 +254,9 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
  	 * The dynamic loader may be called from a thread, we have
 	 * limited amounts of stack available so we cannot use alloca().
 	 */
-	cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
-	if (cache == MAP_FAILED)
-		cache = NULL;
-	
+	cache = calloc(obj->nchains, sizeof(SymCache));
+	/* No need to check for NULL here */
+
 	rellim = (const Elf_Rel *)((caddr_t)obj->rel + obj->relsize);
 	for (rel = obj->rel; rel < rellim; rel++) {
 		if (reloc_nonplt_object(obj, rel, cache) < 0)
@@ -266,9 +264,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	}
 	r = 0;
 done:
-	if (cache) {
-		munmap(cache, bytes);
-	}
+	if (cache != NULL)
+		free(cache);
 	return (r);
 }
 
Index: libexec/rtld-elf/powerpc/reloc.c
===================================================================
--- libexec/rtld-elf/powerpc/reloc.c	(revision 208620)
+++ libexec/rtld-elf/powerpc/reloc.c	(working copy)
@@ -287,7 +287,6 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	const Elf_Rela *relalim;
 	const Elf_Rela *rela;
 	SymCache *cache;
-	int bytes = obj->nchains * sizeof(SymCache);
 	int r = -1;
 
 	/*
@@ -295,10 +294,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	 * limited amounts of stack available so we cannot use alloca().
 	 */
 	if (obj != obj_rtld) {
-		cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON,
-		    -1, 0);
-		if (cache == MAP_FAILED)
-			cache = NULL;
+		cache = calloc(obj->nchains, sizeof(SymCache));
+		/* No need to check for NULL here */
 	} else
 		cache = NULL;
 
@@ -314,9 +311,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	}
 	r = 0;
 done:
-	if (cache) {
-		munmap(cache, bytes);
-	}
+	if (cache != NULL)
+		free(cache);
 	return (r);
 }
 
Index: libexec/rtld-elf/sparc64/reloc.c
===================================================================
--- libexec/rtld-elf/sparc64/reloc.c	(revision 208620)
+++ libexec/rtld-elf/sparc64/reloc.c	(working copy)
@@ -254,7 +254,6 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	const Elf_Rela *relalim;
 	const Elf_Rela *rela;
 	SymCache *cache;
-	int bytes = obj->nchains * sizeof(SymCache);
 	int r = -1;
 
 	/*
@@ -262,10 +261,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	 * limited amounts of stack available so we cannot use alloca().
 	 */
 	if (obj != obj_rtld) {
-		cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON,
-		    -1, 0);
-		if (cache == MAP_FAILED)
-			cache = NULL;
+		cache = calloc(obj->nchains, sizeof(SymCache));
+		/* No need to check for NULL here */
 	} else
 		cache = NULL;
 
@@ -276,8 +273,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	}
 	r = 0;
 done:
-	if (cache)
-		munmap(cache, bytes);
+	if (cache != NULL)
+		free(cache);
 	return (r);
 }
 
Index: libexec/rtld-elf/rtld.c
===================================================================
--- libexec/rtld-elf/rtld.c	(revision 208620)
+++ libexec/rtld-elf/rtld.c	(working copy)
@@ -3311,6 +3311,10 @@ allocate_module_tls(int index)
     }
 
     p = malloc(obj->tlssize);
+    if (p == NULL) {
+	_rtld_error("Cannot allocate TLS block for index %d", index);
+	die();
+    }
     memcpy(p, obj->tlsinit, obj->tlsinitsize);
     memset(p + obj->tlsinitsize, 0, obj->tlssize - obj->tlsinitsize);
 
Index: libexec/rtld-elf/i386/reloc.c
===================================================================
--- libexec/rtld-elf/i386/reloc.c	(revision 208620)
+++ libexec/rtld-elf/i386/reloc.c	(working copy)
@@ -119,15 +119,16 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	const Elf_Rel *rellim;
 	const Elf_Rel *rel;
 	SymCache *cache;
-	int bytes = obj->nchains * sizeof(SymCache);
 	int r = -1;
 
 	/*
 	 * The dynamic loader may be called from a thread, we have
 	 * limited amounts of stack available so we cannot use alloca().
 	 */
-	cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
-	if (cache == MAP_FAILED)
+	if (obj != obj_rtld) {
+	    cache = calloc(obj->nchains, sizeof(SymCache));
+	    /* No need to check for NULL here */
+	} else
 	    cache = NULL;
 
 	rellim = (const Elf_Rel *) ((caddr_t) obj->rel + obj->relsize);
@@ -273,8 +274,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	}
 	r = 0;
 done:
-	if (cache)
-	    munmap(cache, bytes);
+	if (cache != NULL)
+	    free(cache);
 	return(r);
 }
 
Index: libexec/rtld-elf/amd64/reloc.c
===================================================================
--- libexec/rtld-elf/amd64/reloc.c	(revision 208620)
+++ libexec/rtld-elf/amd64/reloc.c	(working copy)
@@ -118,15 +118,16 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	const Elf_Rela *relalim;
 	const Elf_Rela *rela;
 	SymCache *cache;
-	int bytes = obj->nchains * sizeof(SymCache);
 	int r = -1;
 
 	/*
 	 * The dynamic loader may be called from a thread, we have
 	 * limited amounts of stack available so we cannot use alloca().
 	 */
-	cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
-	if (cache == MAP_FAILED)
+	if (obj != obj_rtld) {
+	    cache = calloc(obj->nchains, sizeof(SymCache));
+	    /* No need to check for NULL here */
+	} else
 	    cache = NULL;
 
 	relalim = (const Elf_Rela *) ((caddr_t) obj->rela + obj->relasize);
@@ -322,8 +323,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
 	}
 	r = 0;
 done:
-	if (cache)
-	    munmap(cache, bytes);
+	if (cache != NULL)
+	    free(cache);
 	return(r);
 }
 


More information about the freebsd-current mailing list