Index | Thread | Search

From:
Martin Pieuchot <mpi@grenadille.net>
Subject:
Re: ld.so not calling destructor
To:
Alexander Bluhm <bluhm@openbsd.org>
Cc:
ASOU Masato <takeasou.masato@gmail.com>, tech@openbsd.org, Philip Guenther <guenther@openbsd.org>
Date:
Fri, 15 Aug 2025 11:46:56 +0200

Download raw body.

Thread
On 12/02/25(Wed) 13:55, Alexander Bluhm wrote:
> On Fri, Jan 17, 2025 at 02:24:12PM +0900, ASOU Masato wrote:
> > On Fri, Jan 17, 2025 at 2:19???PM ASOU Masato <takeasou.masato@gmail.com> wrote:
> > > I applied your patch and following diff:
> 
> With a slightly different patch for ld.so, only run-regress-prog1
> of regress is failing.  I moved down the call to _dl_unlink_children()
> a bit.  Also with this fix, a workaround a patch for llvm-openmp
> can be removed.  It seems that the callbacks are called in the right
> order now.

What happened to this?

> Nevertheless, the failing regress looks relevant regarding ordering
> of destructors and needs more thoughts.
> 
> bluhm
> 
> Index: libexec/ld.so/library_subr.c
> ===================================================================
> RCS file: /mount/openbsd/cvs/src/libexec/ld.so/library_subr.c,v
> diff -u -p -r1.55 library_subr.c
> --- libexec/ld.so/library_subr.c	27 Apr 2023 12:27:56 -0000	1.55
> +++ libexec/ld.so/library_subr.c	12 Feb 2025 12:21:32 -0000
> @@ -533,6 +533,17 @@ _dl_link_child(elf_object_t *dep, elf_ob
>  }
>  
>  void
> +_dl_unlink_children(void)
> +{
> +	elf_object_t *node;
> +
> +	for (node = _dl_objects; node != NULL; node = node->next) {
> +		if (node->refcount > 0)
> +			_dl_child_refcnt_decrement(node);
> +	}
> +}
> +
> +void
>  object_vec_grow(struct object_vector *vec, int more)
>  {
>  	vec->alloc += more;
> Index: libexec/ld.so/loader.c
> ===================================================================
> RCS file: /mount/openbsd/cvs/src/libexec/ld.so/loader.c,v
> diff -u -p -r1.223 loader.c
> --- libexec/ld.so/loader.c	22 Jan 2024 02:08:31 -0000	1.223
> +++ libexec/ld.so/loader.c	12 Feb 2025 12:21:55 -0000
> @@ -208,6 +208,7 @@ _dl_dtors(void)
>  	_dl_objects->opencount--;
>  	_dl_notify_unload_shlib(_dl_objects);
>  
> +	_dl_unlink_children();
>  	_dl_run_all_dtors();
>  }
>  
> Index: libexec/ld.so/resolve.h
> ===================================================================
> RCS file: /mount/openbsd/cvs/src/libexec/ld.so/resolve.h,v
> diff -u -p -r1.108 resolve.h
> --- libexec/ld.so/resolve.h	21 May 2024 05:00:47 -0000	1.108
> +++ libexec/ld.so/resolve.h	12 Feb 2025 12:21:32 -0000
> @@ -318,6 +318,7 @@ int _dl_load_dep_libs(elf_object_t *obje
>  int _dl_rtld(elf_object_t *object);
>  void _dl_call_init(elf_object_t *object);
>  void _dl_link_child(elf_object_t *dep, elf_object_t *p);
> +void _dl_unlink_children(void);
>  void _dl_link_grpsym(elf_object_t *object);
>  void _dl_cache_grpsym_list_setup(elf_object_t *_object);
>  void _dl_link_grpref(elf_object_t *load_group, elf_object_t *load_object);
>