This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH glibc 2.31 3/5] support record failure: allow use from constructor
- From: Florian Weimer <fweimer at redhat dot com>
- To: Mathieu Desnoyers <mathieu dot desnoyers at efficios dot com>
- Cc: Carlos O'Donell <carlos at redhat dot com>, Joseph Myers <joseph at codesourcery dot com>, Szabolcs Nagy <szabolcs dot nagy at arm dot com>, libc-alpha at sourceware dot org
- Date: Wed, 16 Oct 2019 15:41:03 +0200
- Subject: Re: [PATCH glibc 2.31 3/5] support record failure: allow use from constructor
- References: <20190807142726.2579-1-mathieu.desnoyers@efficios.com> <20190807142726.2579-4-mathieu.desnoyers@efficios.com>
* Mathieu Desnoyers:
> diff --git a/support/support_record_failure.c b/support/support_record_failure.c
> index a8ffd1fb7d..86d9c71409 100644
> --- a/support/support_record_failure.c
> +++ b/support/support_record_failure.c
> @@ -32,8 +32,12 @@
> zero, the failure of a test can be detected.
>
> The init constructor function below puts *state on a shared
> - annonymous mapping, so that failure reports from subprocesses
> - propagate to the parent process. */
> + anonymous mapping, so that failure reports from subprocesses
> + propagate to the parent process.
> +
> + support_record_failure_init is exposed so it can be called explicitly
> + in case this API needs to be used from a constructor. */
> +
> struct test_failures
> {
> unsigned int counter;
> @@ -41,10 +45,14 @@ struct test_failures
> };
> static struct test_failures *state;
>
> -static __attribute__ ((constructor)) void
> -init (void)
> +__attribute__ ((constructor)) void
> +support_record_failure_init (void)
> {
> - void *ptr = mmap (NULL, sizeof (*state), PROT_READ | PROT_WRITE,
> + void *ptr;
> +
> + if (state != NULL)
> + return;
> + ptr = mmap (NULL, sizeof (*state), PROT_READ | PROT_WRITE,
> MAP_ANONYMOUS | MAP_SHARED, -1, 0);
> if (ptr == MAP_FAILED)
> {
I think the general direction is useful here, but we should rather avoid
constructor ordering problems by using <allocate_once.h> here. Let me
check how this would look like.
Thanks,
Florian