Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 May 2020 21:56:45 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r361564 - in stable/12: cddl/contrib/opensolaris/lib/libdtrace/common lib/libc/gen libexec/rtld-elf sys/sys
Message-ID:  <202005272156.04RLujAJ091465@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Wed May 27 21:56:45 2020
New Revision: 361564
URL: https://svnweb.freebsd.org/changeset/base/361564

Log:
  MFC r361303, r361349, r361394, r361398, r361537:
  Change link_map::l_addr to mean load offset in ABI-compatible way.
  Add link_map::l_refname.
  Add rtld feature indicators.

Modified:
  stable/12/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c
  stable/12/lib/libc/gen/dlinfo.3
  stable/12/libexec/rtld-elf/Symbol.map
  stable/12/libexec/rtld-elf/rtld.1
  stable/12/libexec/rtld-elf/rtld.c
  stable/12/sys/sys/link_elf.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c
==============================================================================
--- stable/12/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c	Wed May 27 21:44:26 2020	(r361563)
+++ stable/12/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c	Wed May 27 21:56:45 2020	(r361564)
@@ -143,12 +143,18 @@ dtrace_dof_init(void)
 		return;
 	}
 
+#ifdef __FreeBSD__
+	elf = (void *)lmp->l_base;
+#else
 	elf = (void *)lmp->l_addr;
+#endif
 
 	dh.dofhp_dof = (uintptr_t)dof;
-	dh.dofhp_addr = elf->e_type == ET_DYN ? (uintptr_t) lmp->l_addr : 0;
 #ifdef __FreeBSD__
+	dh.dofhp_addr = elf->e_type == ET_DYN ? (uintptr_t) lmp->l_base : 0;
 	dh.dofhp_pid = getpid();
+#else
+	dh.dofhp_addr = elf->e_type == ET_DYN ? (uintptr_t) lmp->l_addr : 0;
 #endif
 
 	if (lmid == 0) {

Modified: stable/12/lib/libc/gen/dlinfo.3
==============================================================================
--- stable/12/lib/libc/gen/dlinfo.3	Wed May 27 21:44:26 2020	(r361563)
+++ stable/12/lib/libc/gen/dlinfo.3	Wed May 27 21:56:45 2020	(r361564)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 14, 2003
+.Dd May 21, 2020
 .Dt DLINFO 3
 .Os
 .Sh NAME
@@ -105,14 +105,16 @@ structure is defined in
 .In link.h
 and has the following members:
 .Bd -literal -offset indent
-caddr_t         l_addr;    /* Base Address of library */
+caddr_t         l_base;    /* Base Address of library */
 const char      *l_name;   /* Absolute Path to Library */
 const void      *l_ld;     /* Pointer to .dynamic in memory */
 struct link_map *l_next,   /* linked list of mapped libs */
                 *l_prev;
+caddr_t         l_addr;     /* Load Offset of library */
+const char      *l_refname; /* Object this one filters for */
 .Ed
 .Bl -tag -width ".Va l_addr"
-.It Va l_addr
+.It Va l_base
 The base address of the object loaded into memory.
 .It Va l_name
 The full name of the loaded shared object.
@@ -128,6 +130,15 @@ structure on the link-map list.
 The previous
 .Vt Link_map
 structure on the link-map list.
+.It Va l_addr
+The load offset of the object, that is, the difference between
+the actual load address and the base virtual address the object
+was linked at.
+.It Va l_refname
+A name of the object this object filters for, if any.
+If there are more then one filtee, a name from the first
+.Dv DT_FILTER
+dynamic entry is supplied.
 .El
 .It Dv RTLD_DI_SERINFO
 Retrieve the library search paths associated with the given

Modified: stable/12/libexec/rtld-elf/Symbol.map
==============================================================================
--- stable/12/libexec/rtld-elf/Symbol.map	Wed May 27 21:44:26 2020	(r361563)
+++ stable/12/libexec/rtld-elf/Symbol.map	Wed May 27 21:56:45 2020	(r361564)
@@ -32,4 +32,6 @@ FBSDprivate_1.0 {
     _rtld_get_stack_prot;
     _rtld_is_dlopened;
     _r_debug_postinit;
+    _rtld_version__FreeBSD_version;
+    _rtld_version_laddr_offset;
 };

Modified: stable/12/libexec/rtld-elf/rtld.1
==============================================================================
--- stable/12/libexec/rtld-elf/rtld.1	Wed May 27 21:44:26 2020	(r361563)
+++ stable/12/libexec/rtld-elf/rtld.1	Wed May 27 21:56:45 2020	(r361564)
@@ -355,6 +355,54 @@ ignores
 and is naturally prone to race conditions.
 Environments which rely on such restrictions are weak
 and breakable on their own.
+.Sh VERSIONING
+Newer
+.Nm
+might provide some features or changes in runtime behavior that cannot be
+easily detected at runtime by checking of the normal exported symbols.
+Note that it is almost always wrong to verify
+.Dv __FreeBSD_version
+in userspace to detect features, either at compile or at run time,
+because either kernel, or libc, or environment variables could not
+match the running
+.Nm .
+.Pp
+To solve the problem,
+.Nm
+exports some feature indicators in the
+.Fx
+private symbols namespace
+.Dv FBSDprivate_1.0 .
+Symbols start with the
+.Dv _rtld_version
+prefix.
+Current list of defined symbols and corresponding features is:
+.Bl -tag -width indent
+.It Dv _rtld_version__FreeBSD_version
+Symbol exports the value of the
+.Dv __FreeBSD_version
+definition as it was provided during the
+.Nm
+build.
+The symbol is always present since the
+.Dv _rtld_version
+facility was introduced.
+.It Dv _rtld_version_laddr_offset
+The
+.Va l_addr
+member of the
+.Vt link_map
+structure contains the load offset of the shared object.
+Before that,
+.Va l_addr
+contained the base address of the library.
+See
+.Xr dlinfo 3 .
+.Pp
+Also it indicates the presence of
+.Va l_refname
+member of the structure.
+.El
 .Sh FILES
 .Bl -tag -width ".Pa /var/run/ld-elf32.so.hints" -compact
 .It Pa /var/run/ld-elf.so.hints
@@ -369,6 +417,7 @@ The libmap configuration file for 32-bit binaries on 6
 .Sh SEE ALSO
 .Xr ld 1 ,
 .Xr ldd 1 ,
+.Xr dlinfo 3 ,
 .Xr capsicum 4 ,
 .Xr elf 5 ,
 .Xr libmap.conf 5 ,

Modified: stable/12/libexec/rtld-elf/rtld.c
==============================================================================
--- stable/12/libexec/rtld-elf/rtld.c	Wed May 27 21:44:26 2020	(r361563)
+++ stable/12/libexec/rtld-elf/rtld.c	Wed May 27 21:56:45 2020	(r361564)
@@ -1171,6 +1171,9 @@ digest_dynamic1(Obj_Entry *obj, int early, const Elf_D
 
 		*needed_filtees_tail = nep;
 		needed_filtees_tail = &nep->next;
+
+		if (obj->linkmap.l_refname == NULL)
+		    obj->linkmap.l_refname = (char *)dynp->d_un.d_val;
 	    }
 	    break;
 
@@ -1353,6 +1356,10 @@ digest_dynamic1(Obj_Entry *obj, int early, const Elf_D
 	}
 	obj->dynsymcount += obj->symndx_gnu;
     }
+
+    if (obj->linkmap.l_refname != NULL)
+	obj->linkmap.l_refname = obj->strtab + (unsigned long)obj->
+	  linkmap.l_refname;
 }
 
 static bool
@@ -3981,52 +3988,50 @@ rtld_dirname_abs(const char *path, char *base)
 static void
 linkmap_add(Obj_Entry *obj)
 {
-    struct link_map *l = &obj->linkmap;
-    struct link_map *prev;
+	struct link_map *l, *prev;
 
-    obj->linkmap.l_name = obj->path;
-    obj->linkmap.l_addr = obj->mapbase;
-    obj->linkmap.l_ld = obj->dynamic;
-#ifdef __mips__
-    /* GDB needs load offset on MIPS to use the symbols */
-    obj->linkmap.l_offs = obj->relocbase;
-#endif
+	l = &obj->linkmap;
+	l->l_name = obj->path;
+	l->l_base = obj->mapbase;
+	l->l_ld = obj->dynamic;
+	l->l_addr = obj->relocbase;
 
-    if (r_debug.r_map == NULL) {
-	r_debug.r_map = l;
-	return;
-    }
+	if (r_debug.r_map == NULL) {
+		r_debug.r_map = l;
+		return;
+	}
 
-    /*
-     * Scan to the end of the list, but not past the entry for the
-     * dynamic linker, which we want to keep at the very end.
-     */
-    for (prev = r_debug.r_map;
-      prev->l_next != NULL && prev->l_next != &obj_rtld.linkmap;
-      prev = prev->l_next)
-	;
+	/*
+	 * Scan to the end of the list, but not past the entry for the
+	 * dynamic linker, which we want to keep at the very end.
+	 */
+	for (prev = r_debug.r_map;
+	    prev->l_next != NULL && prev->l_next != &obj_rtld.linkmap;
+	     prev = prev->l_next)
+		;
 
-    /* Link in the new entry. */
-    l->l_prev = prev;
-    l->l_next = prev->l_next;
-    if (l->l_next != NULL)
-	l->l_next->l_prev = l;
-    prev->l_next = l;
+	/* Link in the new entry. */
+	l->l_prev = prev;
+	l->l_next = prev->l_next;
+	if (l->l_next != NULL)
+		l->l_next->l_prev = l;
+	prev->l_next = l;
 }
 
 static void
 linkmap_delete(Obj_Entry *obj)
 {
-    struct link_map *l = &obj->linkmap;
+	struct link_map *l;
 
-    if (l->l_prev == NULL) {
-	if ((r_debug.r_map = l->l_next) != NULL)
-	    l->l_next->l_prev = NULL;
-	return;
-    }
+	l = &obj->linkmap;
+	if (l->l_prev == NULL) {
+		if ((r_debug.r_map = l->l_next) != NULL)
+			l->l_next->l_prev = NULL;
+		return;
+	}
 
-    if ((l->l_prev->l_next = l->l_next) != NULL)
-	l->l_next->l_prev = l->l_prev;
+	if ((l->l_prev->l_next = l->l_next) != NULL)
+		l->l_next->l_prev = l->l_prev;
 }
 
 /*
@@ -5775,3 +5780,9 @@ realloc(void *cp, size_t nbytes)
 
 	return (__crt_realloc(cp, nbytes));
 }
+
+extern int _rtld_version__FreeBSD_version __exported;
+int _rtld_version__FreeBSD_version = __FreeBSD_version;
+
+extern char _rtld_version_laddr_offset __exported;
+char _rtld_version_laddr_offset;

Modified: stable/12/sys/sys/link_elf.h
==============================================================================
--- stable/12/sys/sys/link_elf.h	Wed May 27 21:44:26 2020	(r361563)
+++ stable/12/sys/sys/link_elf.h	Wed May 27 21:56:45 2020	(r361564)
@@ -57,13 +57,15 @@
 #define	LA_SER_SECURE	0x80	/* default (secure) path prepended */
 
 typedef struct link_map {
-	caddr_t		l_addr;			/* Base Address of library */
+	caddr_t		l_base;			/* Base Address of library */
 #ifdef __mips__
-	caddr_t		l_offs;			/* Load Offset of library */
+	caddr_t		l_xxx;			/* unused */
 #endif
 	const char	*l_name;		/* Absolute Path to Library */
 	const void	*l_ld;			/* Pointer to .dynamic in memory */
 	struct link_map	*l_next, *l_prev;	/* linked list of of mapped libs */
+	caddr_t		l_addr;			/* Load Offset of library */
+	const char	*l_refname;		/* object we are filtering for */
 } Link_map;
 
 struct r_debug {



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