Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Apr 2025 13:38:44 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Andriy Gapon <avg@freebsd.org>
Cc:        FreeBSD Current <current@freebsd.org>
Subject:   Re: RTLD_DEEPBIND question
Message-ID:  <aAN9NH1IR-gZceP4@kib.kiev.ua>
In-Reply-To: <aAN69URjEJFuOLxR@kib.kiev.ua>
References:  <0b3dda4e-53e4-40e5-9484-8b5ffb84e658@FreeBSD.org> <aALjHwFnFKChuAdR@kib.kiev.ua> <900c8521-559a-47b5-acaa-ae941f6852c4@freebsd.org> <fd12cce4-7e6b-4ab6-bced-b36e98c995ba@FreeBSD.org> <7c4e1682-d797-493c-8326-08d51dde3359@FreeBSD.org> <aAN69URjEJFuOLxR@kib.kiev.ua>

index | next in thread | previous in thread | raw e-mail

On Sat, Apr 19, 2025 at 01:29:15PM +0300, Konstantin Belousov wrote:
> On Sat, Apr 19, 2025 at 01:25:28PM +0300, Andriy Gapon wrote:
> > On 19/04/2025 12:39, Andriy Gapon wrote:
> > > On 19/04/2025 12:25, Andriy Gapon wrote:
> > > > On 19/04/2025 02:41, Konstantin Belousov wrote:
> > > > > RTLD_DEEPBIND works by first iterating over all (recursive) DT_NEEEDED
> > > > > object for the object where the symbol is resolved, then by looking at
> > > > > the global list of loaded objects.
> > > > > Non-deepbind resolution is performed by looking at the global list.
> > > > > 
> > > > > You can see it in the rtld.c:symlook_default().
> > > 
> > >  From a quick look at the code, should we try to resolve the symbol in
> > > refobj itself when it's marked with deepbind?
> > Oh, and it looks like objects loaded under the "deepbind" object (e.g.,
> > needed objects) may not be aware that they are in the deepbind sub-tree?
> 
> But should they?
> 
> Lets start with some minimal intrusive change:
> 

And there is the version with the recursive marking by deepbind:

diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 2346c6eae9f6..9767c8e7016c 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -3824,27 +3824,26 @@ dlopen_object(const char *name, int fd, Obj_Entry *refobj, int lo_flags,
 			if ((lo_flags & (RTLD_LO_EARLY | RTLD_LO_IGNSTLS)) ==
 				0 &&
 			    obj->static_tls && !allocate_tls_offset(obj)) {
-				_rtld_error("%s: No space available "
-					    "for static Thread Local Storage",
+				_rtld_error(
+		    "%s: No space available for static Thread Local Storage",
 				    obj->path);
 				result = -1;
 			}
 			if (result != -1)
 				result = load_needed_objects(obj,
-				    lo_flags &
-					(RTLD_LO_DLOPEN | RTLD_LO_EARLY |
-					    RTLD_LO_IGNSTLS | RTLD_LO_TRACE));
+				    lo_flags & (RTLD_LO_DLOPEN | RTLD_LO_EARLY |
+				    RTLD_LO_IGNSTLS | RTLD_LO_TRACE |
+				    RTLD_LO_DEEPBIND));
 			init_dag(obj);
 			ref_dag(obj);
 			if (result != -1)
 				result = rtld_verify_versions(&obj->dagmembers);
 			if (result != -1 && ld_tracing)
 				goto trace;
-			if (result == -1 ||
-			    relocate_object_dag(obj,
-				(mode & RTLD_MODEMASK) == RTLD_NOW, &obj_rtld,
-				(lo_flags & RTLD_LO_EARLY) ? SYMLOOK_EARLY : 0,
-				lockstate) == -1) {
+			if (result == -1 || relocate_object_dag(obj,
+			    (mode & RTLD_MODEMASK) == RTLD_NOW, &obj_rtld,
+			    (lo_flags & RTLD_LO_EARLY) ? SYMLOOK_EARLY : 0,
+			    lockstate) == -1) {
 				dlopen_cleanup(obj, lockstate);
 				obj = NULL;
 			} else if (lo_flags & RTLD_LO_EARLY) {
@@ -4679,12 +4678,13 @@ symlook_default(SymLook *req, const Obj_Entry *refobj)
 	 */
 	res = symlook_obj(&req1, refobj);
 	if (res == 0 && (refobj->symbolic ||
-	    ELF_ST_VISIBILITY(req1.sym_out->st_other) == STV_PROTECTED)) {
+	    ELF_ST_VISIBILITY(req1.sym_out->st_other) == STV_PROTECTED ||
+	    refobj->deepbind)) {
 		req->sym_out = req1.sym_out;
 		req->defobj_out = req1.defobj_out;
 		assert(req->defobj_out != NULL);
 	}
-	if (refobj->symbolic || req->defobj_out != NULL)
+	if (refobj->symbolic || req->defobj_out != NULL || refobj->deepbind)
 		donelist_check(&donelist, refobj);
 
 	if (!refobj->deepbind)


help

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