svn commit: r339876 - head/libexec/rtld-elf

Konstantin Belousov kib at freebsd.org
Fri Nov 2 11:38:38 UTC 2018


On Fri, Nov 02, 2018 at 12:16:23AM -0700, Mark Millard wrote:
> It stops when the dcbst in __syncicache runs into an address in
> the p_align 65536 caused hole between the two PT_LOAD's with PF_X.
> /bin/ls itself has such a hole, as do the .so libraries involved.

Try this.  I only compile-tested the change.

diff --git a/libexec/rtld-elf/powerpc/reloc.c b/libexec/rtld-elf/powerpc/reloc.c
index e921a4dc7d1..5f21e33bee3 100644
--- a/libexec/rtld-elf/powerpc/reloc.c
+++ b/libexec/rtld-elf/powerpc/reloc.c
@@ -294,6 +294,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
 {
 	const Elf_Rela *relalim;
 	const Elf_Rela *rela;
+	const Elf_Phdr *phdr;
 	SymCache *cache;
 	int r = -1;
 
@@ -327,8 +328,18 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
 	if (cache != NULL)
 		free(cache);
 
-	/* Synchronize icache for text seg in case we made any changes */
-	__syncicache(obj->mapbase, obj->textsize);
+	/*
+	 * Synchronize icache for executable segments in case we made
+	 * any changes.
+	 */
+	for (phdr = obj->phdr;
+	    (const char *)phdr < (const char *)obj->phdr + obj->phsize;
+	    phdr++) {
+		if (phdr->p_type == PT_LOAD && (phdr->p_flags & PF_X) != 0) {
+			__syncicache(obj->mapbase + phdr->p_vaddr,
+			    phdr->p_memsz);
+		}
+	}
 
 	return (r);
 }
diff --git a/libexec/rtld-elf/powerpc64/reloc.c b/libexec/rtld-elf/powerpc64/reloc.c
index c2d6dac13b1..980b4933afe 100644
--- a/libexec/rtld-elf/powerpc64/reloc.c
+++ b/libexec/rtld-elf/powerpc64/reloc.c
@@ -291,6 +291,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
 {
 	const Elf_Rela *relalim;
 	const Elf_Rela *rela;
+	const Elf_Phdr *phdr;
 	SymCache *cache;
 	int bytes = obj->dynsymcount * sizeof(SymCache);
 	int r = -1;
@@ -327,8 +328,18 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
 	if (cache)
 		munmap(cache, bytes);
 
-	/* Synchronize icache for text seg in case we made any changes */
-	__syncicache(obj->mapbase, obj->textsize);
+	/*
+	 * Synchronize icache for executable segments in case we made
+	 * any changes.
+	 */
+	for (phdr = obj->phdr;
+	    (const char *)phdr < (const char *)obj->phdr + obj->phsize;
+	    phdr++) {
+		if (phdr->p_type == PT_LOAD && (phdr->p_flags & PF_X) != 0) {
+			__syncicache(obj->mapbase + phdr->p_vaddr,
+			    phdr->p_memsz);
+		}
+	}
 
 	return (r);
 }


More information about the svn-src-head mailing list