This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: fork call __attribute__((destructor))
- From: Carlos O'Donell <carlos at redhat dot com>
- To: Yubin Ruan <ablacktshirt at gmail dot com>, binutils at sourceware dot org
- Date: Fri, 4 Aug 2017 14:10:29 -0400
- Subject: Re: fork call __attribute__((destructor))
- Authentication-results: sourceware.org; auth=none
- References: <CAJYFCiOQBKJPMRhmoFerxtWB94+3urPCNizSzfp4n01oC5wAhw@mail.gmail.com>
On 08/04/2017 01:01 PM, Yubin Ruan wrote:
> Hi,
> I used to assumed that a function marked with a
> "__attribute__((destructor))" would be called after the .so is
> unloaded, typically when the program exit. However, I discover that
> when I call "fork()" the destructor is also called.
>
> How could that happen? Is it a bug or something? Am I doing something
> wrong? What is the rationale behind that?
>
> And, is there any way to prevent the destructor being called when
> somebody call fork()?
Please provide an example program that does this.
Also note that the running of the destructor is part of the dynamic
loader's responsibility, not the static linker (binutils).
I suggest asking on libc-help@sourceware.org.
--
Cheers,
Carlos.