Index | Thread | Search

From:
ASOU Masato <takeasou.masato@gmail.com>
Subject:
Re: ld.so not calling destructor
To:
tech@openbsd.org
Cc:
Masato ASOU <takeasou.masato@gmail.com>
Date:
Wed, 21 Jan 2026 10:14:39 +0900

Download raw body.

Thread
The ld.so has a following issue:

- When a .so file that marked NODELETE is linked, the destructor
  defined with __attribute__((destructor)) does not called.

For example, if you add -lpthread to prog1 and run it, the function
fini() will not be called as below:

$ cd /usr/src/regress/libexec/ld.so/initfirst/test1/prog1
$ make

</snip>

$ obj/prog1
init if1
init if2
init normal
main
func normal
fini normal
fini if1
fini if2
$ vi Makefile
$ git diff Makefile
diff --git a/regress/libexec/ld.so/initfirst/test1/prog1/Makefile b/regress/libe
xec/ld.so/initfirst/test1/prog1/Makefile
index d33b92c1f..d9ecb7f3a 100644
--- a/regress/libexec/ld.so/initfirst/test1/prog1/Makefile
+++ b/regress/libexec/ld.so/initfirst/test1/prog1/Makefile
@@ -11,7 +11,7 @@ LDFLAGS+=     -Wl,-rpath,$(IF1_OBJDIR) -L$(IF1_OBJDIR)
 LDFLAGS+=      -Wl,-rpath,$(IF2_OBJDIR) -L$(IF2_OBJDIR)
 LDFLAGS+=      -Wl,-rpath,$(IF3_OBJDIR) -L$(IF3_OBJDIR)
 LDFLAGS+=      -Wl,-rpath,$(NORMAL_OBJDIR) -L$(NORMAL_OBJDIR)
-LDADD_prog1+=  -lnormal -lif1 -lif2
+LDADD_prog1+=  -lnormal -lif1 -lif2 -lpthread
 LDADD_prog2+=  -lif1 -lnormal -lif2
 LDADD_prog3+=  -lif1 -lif2 -lnormal
 LDADD_prog4+=  -lif1 -lif2 -lif3
$ make clean
rm -f a.out [Ee]rrs mklog *.core y.tab.h   prog1 prog2 prog3 prog4
main.o main.o main.o main.o    main.d main.d main.d main.d
$ make
cc -O2 -pipe  -g  -MD -MP  -c
/usr/src/regress/libexec/ld.so/initfirst/test1/prog1/main.c

</snip>

==== do-prog1 ====
./prog1 | cmp -s
/usr/src/regress/libexec/ld.so/initfirst/test1/prog1/expected1 -
*** Error 1 in . (Makefile:22 'do-prog1')
FAILED
*** Error 1 in /usr/src/regress/libexec/ld.so/initfirst/test1/prog1
(<bsd.regress.mk>:105 'regress': if make -C
/usr/src/regress/libexec/ld....)
$ obj/prog1
init if1
init if2
init normal
main
func normal
$

Can someone solve this problem?

Best regards,
--
ASOU Masato

On Wed, Jan 7, 2026 at 3:22 PM ASOU Masato <takeasou.masato@gmail.com> wrote:
>
> I've put this on hold for now as it's taking a while to investigate
> vnconfig.  I'm currently investigating why regress/libexec/ld.so
> fails when applying the ld.so patch.
> --
> ASOU Masato
>
> On Tue, Aug 19, 2025 at 3:47 PM ASOU Masato <takeasou.masato@gmail.com> wrote:
> >
> > On Fri, Aug 15, 2025 at 6:47 PM Martin Pieuchot <mpi@grenadille.net> wrote:
> > >
> > > 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?
> >
> > There is an issue with ld.so where the link to elf_object_t is not
> > updated when free() the elf_object_t. I am working on fixing this.
> > However, when I run the make command second time in /usr/src/regress,
> > an error occurs when the ececute vnconfig -u vnd2a command in
> > regress/usr.sbin/installboot. Therefore, I am currently investigating
> > this vnconfig issue.
> >
> > --
> > ASOU Masato