[gnutls-devel] Automatic library initialization

Nikos Mavrogiannopoulos nmav at gnutls.org
Mon Nov 16 15:17:24 CET 2015


On Mon, Nov 16, 2015 at 12:12 PM, Tim Ruehsen <tim.ruehsen at gmx.de> wrote:

>> In a distribution
>> the automatic initialization helps to have users of gnutls who
>> couldn't otherwise use it. For example a library which has no
>> equivalent global_init function couldn't use gnutls easily.
> Do you have a special project in mind ?

Yes, a common bug reported was applications crashing when they
attempted to call gnutls_global_init() from awkward situations (e.g.,
having several of threads which all called gnutls_global_init). The
applications themselves didn't even know they were calling
gnutls_global_init(), it was some intermediate library, which also
didn't expect to be used by multithreaded applications. The way to
solve that was handling all initialization in a constructor. I don't
have the exact names of the projects with that issue, but they are in
the mailing list.

> Also, your theoretical example applies to any library that uses another
> library. AFAIK, it is a good practice to avoid code in the library
> constructor.

It is not theoretical as you imply. There were real issues that had to
be solved somehow.

>> > IMO, you should revert your decision and should not automatic initialize.
>> > For someone who badly needs that (beyond my imagination right now), a
>> > ./configure flag and GNUTLS_NO_EXPLICIT_INIT should do it. Maybe it
>> > should be
>> > GNUTLS_AUTOMATIC_INIT, defaulting to 0.
>> That is too late now as it would be an ABI break. However a configure
>> flag is certainly an easy thing to be added, but it would only solve
>> your problem if you target some specific systems. What is the use case
>> you are trying to address?
> A ./configure flag would be enough. I'll ask the Debian maintainer(s) to apply
> such a flag. As long as there are no packages/projects that *rely* on
> automatic init, there should be no problem. If there are, these packages
> should be fixed.

That is hardly a solution. An API is not distribution specific, and if
the gnutls' API doesn't require gnutls_global_init(), that should be
for any distribution including debian. We need to find something
better to prevent the constructor being run for specific applications.

regards,
Nikos



More information about the Gnutls-devel mailing list