Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Nov 2018 20:39:16 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r340102 - in head/libexec/rtld-elf: powerpc powerpc64
Message-ID:  <201811032039.wA3KdGjD086723@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sat Nov  3 20:39:16 2018
New Revision: 340102
URL: https://svnweb.freebsd.org/changeset/base/340102

Log:
  Flush data cache for executable loadable segments explicitly.
  
  Do not use textsize and do not flush everything between map base and
  base + textsize, because unmapped areas cannot be flushed.
  
  This makes Obj_Entry textsize only use go away, and I will remove it
  later.
  
  Reported by:	tuexen
  Tested by:	Mark Millard <marklmi26-fbsd@yahoo.com>
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/libexec/rtld-elf/powerpc/reloc.c
  head/libexec/rtld-elf/powerpc64/reloc.c

Modified: head/libexec/rtld-elf/powerpc/reloc.c
==============================================================================
--- head/libexec/rtld-elf/powerpc/reloc.c	Sat Nov  3 20:35:39 2018	(r340101)
+++ head/libexec/rtld-elf/powerpc/reloc.c	Sat Nov  3 20:39:16 2018	(r340102)
@@ -294,6 +294,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int
 {
 	const Elf_Rela *relalim;
 	const Elf_Rela *rela;
+	const Elf_Phdr *phdr;
 	SymCache *cache;
 	int r = -1;
 
@@ -327,8 +328,18 @@ done:
 	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->relocbase + phdr->p_vaddr,
+			    phdr->p_memsz);
+		}
+	}
 
 	return (r);
 }

Modified: head/libexec/rtld-elf/powerpc64/reloc.c
==============================================================================
--- head/libexec/rtld-elf/powerpc64/reloc.c	Sat Nov  3 20:35:39 2018	(r340101)
+++ head/libexec/rtld-elf/powerpc64/reloc.c	Sat Nov  3 20:39:16 2018	(r340102)
@@ -291,6 +291,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int
 {
 	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 @@ done:
 	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->relocbase + phdr->p_vaddr,
+			    phdr->p_memsz);
+		}
+	}
 
 	return (r);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201811032039.wA3KdGjD086723>