svn commit: r233697 - stable/9/libexec/rtld-elf

Konstantin Belousov kib at FreeBSD.org
Fri Mar 30 09:38:36 UTC 2012


Author: kib
Date: Fri Mar 30 09:38:35 2012
New Revision: 233697
URL: http://svn.freebsd.org/changeset/base/233697

Log:
  MFC r232974:
  Stop using strerror(3) in rtld, which brings in msgcat and stdio.
  Directly access sys_errlist array of errno messages with private
  rtld_strerror() function.

Modified:
  stable/9/libexec/rtld-elf/libmap.c
  stable/9/libexec/rtld-elf/map_object.c
  stable/9/libexec/rtld-elf/rtld.c
  stable/9/libexec/rtld-elf/rtld.h
Directory Properties:
  stable/9/libexec/rtld-elf/   (props changed)

Modified: stable/9/libexec/rtld-elf/libmap.c
==============================================================================
--- stable/9/libexec/rtld-elf/libmap.c	Fri Mar 30 09:37:25 2012	(r233696)
+++ stable/9/libexec/rtld-elf/libmap.c	Fri Mar 30 09:38:35 2012	(r233697)
@@ -71,20 +71,20 @@ lm_init(char *libmap_override)
 	fd = open(_PATH_LIBMAP_CONF, O_RDONLY);
 	if (fd == -1) {
 		dbg("lm_init: open(\"%s\") failed, %s", _PATH_LIBMAP_CONF,
-		    strerror(errno));
+		    rtld_strerror(errno));
 		goto override;
 	}
 	if (fstat(fd, &st) == -1) {
 		close(fd);
 		dbg("lm_init: fstat(\"%s\") failed, %s", _PATH_LIBMAP_CONF,
-		    strerror(errno));
+		    rtld_strerror(errno));
 		goto override;
 	}
 	lm_map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	if (lm_map == (const char *)MAP_FAILED) {
 		close(fd);
 		dbg("lm_init: mmap(\"%s\") failed, %s", _PATH_LIBMAP_CONF,
-		    strerror(errno));
+		    rtld_strerror(errno));
 		goto override;
 	}
 	close(fd);

Modified: stable/9/libexec/rtld-elf/map_object.c
==============================================================================
--- stable/9/libexec/rtld-elf/map_object.c	Fri Mar 30 09:37:25 2012	(r233696)
+++ stable/9/libexec/rtld-elf/map_object.c	Fri Mar 30 09:38:35 2012	(r233697)
@@ -182,7 +182,7 @@ map_object(int fd, const char *path, con
       MAP_NOCORE, -1, 0);
     if (mapbase == (caddr_t) -1) {
 	_rtld_error("%s: mmap of entire address space failed: %s",
-	  path, strerror(errno));
+	  path, rtld_strerror(errno));
 	return NULL;
     }
     if (base_addr != NULL && mapbase != base_addr) {
@@ -202,7 +202,8 @@ map_object(int fd, const char *path, con
 	data_flags = convert_flags(segs[i]->p_flags) | MAP_FIXED;
 	if (mmap(data_addr, data_vlimit - data_vaddr, data_prot,
 	  data_flags, fd, data_offset) == (caddr_t) -1) {
-	    _rtld_error("%s: mmap of data failed: %s", path, strerror(errno));
+	    _rtld_error("%s: mmap of data failed: %s", path,
+		rtld_strerror(errno));
 	    return NULL;
 	}
 
@@ -219,7 +220,7 @@ map_object(int fd, const char *path, con
 		if ((data_prot & PROT_WRITE) == 0 && -1 ==
 		     mprotect(clear_page, PAGE_SIZE, data_prot|PROT_WRITE)) {
 			_rtld_error("%s: mprotect failed: %s", path,
-			    strerror(errno));
+			    rtld_strerror(errno));
 			return NULL;
 		}
 
@@ -238,7 +239,7 @@ map_object(int fd, const char *path, con
 		if (mmap(bss_addr, bss_vlimit - bss_vaddr, data_prot,
 		    data_flags | MAP_ANON, -1, 0) == (caddr_t)-1) {
 		    _rtld_error("%s: mmap of bss failed: %s", path,
-			strerror(errno));
+			rtld_strerror(errno));
 		    return NULL;
 		}
 	    }
@@ -305,7 +306,7 @@ get_elf_header (int fd, const char *path
     ssize_t nbytes;
 
     if ((nbytes = pread(fd, u.buf, PAGE_SIZE, 0)) == -1) {
-	_rtld_error("%s: read error: %s", path, strerror(errno));
+	_rtld_error("%s: read error: %s", path, rtld_strerror(errno));
 	return NULL;
     }
 

Modified: stable/9/libexec/rtld-elf/rtld.c
==============================================================================
--- stable/9/libexec/rtld-elf/rtld.c	Fri Mar 30 09:37:25 2012	(r233696)
+++ stable/9/libexec/rtld-elf/rtld.c	Fri Mar 30 09:38:35 2012	(r233697)
@@ -2163,7 +2163,7 @@ relocate_objects(Obj_Entry *first, bool 
 	    if (mprotect(obj->mapbase, obj->textsize,
 	      PROT_READ|PROT_WRITE|PROT_EXEC) == -1) {
 		_rtld_error("%s: Cannot write-enable text segment: %s",
-		  obj->path, strerror(errno));
+		  obj->path, rtld_strerror(errno));
 		return -1;
 	    }
 	}
@@ -2176,7 +2176,7 @@ relocate_objects(Obj_Entry *first, bool 
 	    if (mprotect(obj->mapbase, obj->textsize,
 	      PROT_READ|PROT_EXEC) == -1) {
 		_rtld_error("%s: Cannot write-protect text segment: %s",
-		  obj->path, strerror(errno));
+		  obj->path, rtld_strerror(errno));
 		return -1;
 	    }
 	}
@@ -2196,7 +2196,7 @@ relocate_objects(Obj_Entry *first, bool 
 	if (obj->relro_size > 0) {
 	    if (mprotect(obj->relro_page, obj->relro_size, PROT_READ) == -1) {
 		_rtld_error("%s: Cannot enforce relro protection: %s",
-		  obj->path, strerror(errno));
+		  obj->path, rtld_strerror(errno));
 		return -1;
 	    }
 	}
@@ -4356,3 +4356,12 @@ __chk_fail(void)
 	_rtld_error("buffer overflow detected; terminated");
 	die();
 }
+
+const char *
+rtld_strerror(int errnum)
+{
+
+	if (errnum < 0 || errnum >= sys_nerr)
+		return ("Unknown error");
+	return (sys_errlist[errnum]);
+}

Modified: stable/9/libexec/rtld-elf/rtld.h
==============================================================================
--- stable/9/libexec/rtld-elf/rtld.h	Fri Mar 30 09:37:25 2012	(r233696)
+++ stable/9/libexec/rtld-elf/rtld.h	Fri Mar 30 09:38:35 2012	(r233697)
@@ -313,6 +313,7 @@ typedef struct Struct_SymLook {
 } SymLook;
 
 extern void _rtld_error(const char *, ...) __printflike(1, 2);
+extern const char *rtld_strerror(int);
 extern Obj_Entry *map_object(int, const char *, const struct stat *);
 extern void *xcalloc(size_t);
 extern void *xmalloc(size_t);


More information about the svn-src-stable-9 mailing list