svn commit: r205641 - head/sys/kern

Nathan Whitehorn nwhitehorn at FreeBSD.org
Thu Mar 25 14:21:22 UTC 2010


Author: nwhitehorn
Date: Thu Mar 25 14:21:22 2010
New Revision: 205641
URL: http://svn.freebsd.org/changeset/base/205641

Log:
  Change the way text_addr and data_addr are computed to use the
  executable status of segments instead of detecting the main text segment
  by which segment contains the program entry point. This affects
  obreak() and is required for correct operation of that function
  on 64-bit PowerPC systems. The previous behavior was apparently
  required only for the Alpha, which is no longer supported.
  
  Reviewed by:	jhb
  Tested on:	amd64, sparc64, powerpc

Modified:
  head/sys/kern/imgact_elf.c

Modified: head/sys/kern/imgact_elf.c
==============================================================================
--- head/sys/kern/imgact_elf.c	Thu Mar 25 13:47:21 2010	(r205640)
+++ head/sys/kern/imgact_elf.c	Thu Mar 25 14:21:22 2010	(r205641)
@@ -832,13 +832,8 @@ __CONCAT(exec_, __elfN(imgact))(struct i
 			    phdr[i].p_vaddr + et_dyn_addr - seg_addr);
 
 			/*
-			 * Is this .text or .data?  We can't use
-			 * VM_PROT_WRITE or VM_PROT_EXEC, it breaks the
-			 * alpha terribly and possibly does other bad
-			 * things so we stick to the old way of figuring
-			 * it out:  If the segment contains the program
-			 * entry point, it's a text segment, otherwise it
-			 * is a data segment.
+			 * Make the largest executable segment the official
+			 * text segment and all others data.
 			 *
 			 * Note that obreak() assumes that data_addr + 
 			 * data_size == end of data load area, and the ELF
@@ -846,12 +841,10 @@ __CONCAT(exec_, __elfN(imgact))(struct i
 			 * address.  If multiple data segments exist, the
 			 * last one will be used.
 			 */
-			if (hdr->e_entry >= phdr[i].p_vaddr &&
-			    hdr->e_entry < (phdr[i].p_vaddr +
-			    phdr[i].p_memsz)) {
+
+			if (phdr[i].p_flags & PF_X && text_size < seg_size) {
 				text_size = seg_size;
 				text_addr = seg_addr;
-				entry = (u_long)hdr->e_entry + et_dyn_addr;
 			} else {
 				data_size = seg_size;
 				data_addr = seg_addr;
@@ -871,6 +864,8 @@ __CONCAT(exec_, __elfN(imgact))(struct i
 		data_size = text_size;
 	}
 
+	entry = (u_long)hdr->e_entry + et_dyn_addr;
+
 	/*
 	 * Check limits.  It should be safe to check the
 	 * limits after loading the segments since we do


More information about the svn-src-all mailing list