git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] async_die_is_recursing: work around GCC v11.x issue on Fedora

From
Victoria Dye via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 4, 2021, 04:01 UTC
Message-ID
<pull.1072.v2.git.1635998463474.gitgitgadget@gmail.com>
In-Reply-To
<pull.1072.git.1635990465854.gitgitgadget@gmail.com>
From: Victoria Dye <vdye@github.com>

This fix corrects an issue found in the `dockerized(pedantic, fedora)` CI build, first appearing after the introduction of a new version of the Fedora docker image version. This image includes a version of `glibc` with the attribute `__attr_access_none` added to `pthread_setspecific` [1], the implementation of which only exists for GCC 11.X - the version included in the Fedora image. The attribute requires that the pointer provided in the second argument of `pthread_getspecific` must, if not NULL, be a pointer to a valid object. In the usage in `async_die_is_recursing`, `(void *)1` is not valid, causing the error.

This fix imitates a workaround added in SELinux [2] by using the pointer to the static `async_die_counter` itself as the second argument to `pthread_setspecific`. This guaranteed non-NULL, valid pointer matches the intent of the current usage while not triggering the build error.

[1] https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=a1561c3bbe8 [2] https://lore.kernel.org/all/20211021140519.6593-1-cgzones@googlemail.com/

Co-authored-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Victoria Dye <vdye@github.com>
---
    async_die_is_recursing: fix use of pthread_getspecific for Fedora
    
    Following up on Johannes' report earlier [1], this patch fixes a
    compiler error in the Fedora CI build (the same issue was identified in
    a local developer build about a week ago [2]). This fix changes the
    second argument in the call to pthread_setspecific from '(void *)1' to a
    valid pointer, thus preventing the error in the use of
    __attr_access_none.
    
    
    Changes since V1
    ================
    
     * Change &ret to &async_die_counter ("dummy" argument to
       pthread_setspecific) so that it's using a global (rather than local)
       variable
     * Fix typo in commit message (pthread_getspecific ->
       pthread_setspecific)
    
    [1]
    https://lore.kernel.org/git/nycvar.QRO.7.76.6.2111040007170.56@tvgsbejvaqbjf.bet/
    [2]
    https://lore.kernel.org/git/43fe6d5c-bdb2-585c-c601-1da7a1b3ff8b@archlinux.org/
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1072%2Fvdye%2Ffix-fedora-build-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1072/vdye/fix-fedora-build-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1072
Range-diff vs v1:
 1:  efe0b398f54 ! 1:  7f10e09269a async_die_is_recursing: fix use of pthread_getspecific for Fedora
     @@ Metadata
      Author: Victoria Dye <vdye@github.com>
      
       ## Commit message ##
     -    async_die_is_recursing: fix use of pthread_getspecific for Fedora
     +    async_die_is_recursing: work around GCC v11.x issue on Fedora
      
     -    Correct an issue encountered in the `dockerized(pedantic, fedora)` CI build,
     -    first appearing after the release of v36 as the latest stable version of the
     -    Fedora docker image. This image includes a version of `glibc` with the
     -    attribute `__attr_access_none` added to `pthread_getspecific` [1], the
     +    This fix corrects an issue found in the `dockerized(pedantic, fedora)` CI
     +    build, first appearing after the introduction of a new version of the Fedora
     +    docker image version. This image includes a version of `glibc` with the
     +    attribute `__attr_access_none` added to `pthread_setspecific` [1], the
          implementation of which only exists for GCC 11.X - the version included in
     -    Fedora. The attribute requires that the pointer provided in the second
     -    argument of `pthread_getspecific` must, if not NULL, be a pointer to a valid
     -    object. In the usage in `async_die_is_recursing`, `(void *)1` is not valid,
     -    resulting in the error.
     +    the Fedora image. The attribute requires that the pointer provided in the
     +    second argument of `pthread_getspecific` must, if not NULL, be a pointer to
     +    a valid object. In the usage in `async_die_is_recursing`, `(void *)1` is not
     +    valid, causing the error.
      
     -    The fix imitates a workaround added in SELinux [2] by using the pointer to
     -    `ret` as the second argument to `pthread_getspecific`. This guaranteed
     -    non-NULL, valid pointer adheres to the current intended usage of
     -    `pthread_getspecific` while not triggering the build error.
     +    This fix imitates a workaround added in SELinux [2] by using the pointer to
     +    the static `async_die_counter` itself as the second argument to
     +    `pthread_setspecific`. This guaranteed non-NULL, valid pointer matches the
     +    intent of the current usage while not triggering the build error.
      
          [1] https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=a1561c3bbe8
          [2] https://lore.kernel.org/all/20211021140519.6593-1-cgzones@googlemail.com/
     @@ run-command.c: static NORETURN void die_async(const char *err, va_list params)
       {
       	void *ret = pthread_getspecific(async_die_counter);
      -	pthread_setspecific(async_die_counter, (void *)1);
     -+	pthread_setspecific(async_die_counter, &ret); /* set to any non-NULL valid pointer */
     ++	pthread_setspecific(async_die_counter, &async_die_counter); /* set to any non-NULL valid pointer */
       	return ret != NULL;
       }
       
 run-command.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/run-command.c b/run-command.c
index 7ef5cc712a9..f40df01c772 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1099,7 +1099,7 @@ static NORETURN void die_async(const char *err, va_list params)
 static int async_die_is_recursing(void)
 {
 	void *ret = pthread_getspecific(async_die_counter);
-	pthread_setspecific(async_die_counter, (void *)1);
+	pthread_setspecific(async_die_counter, &async_die_counter); /* set to any non-NULL valid pointer */
 	return ret != NULL;
 }
 

base-commit: 876b1423317071f43c99666f3fc3db3642dfbe14
-- 
gitgitgadget
Previous: Jeff KingNext: Jeff King
Message 6 of 15 in “async_die_is_recursing: fix use of pthread_getspecific for Fedora”
  1. async_die_is_recursing: fix use of pthread_getspecific for FedoraVictoria Dye via GitGitGadget, Nov 4, 2021
  2. Carlo ArenasNov 4, 2021
  3. Jeff KingNov 4, 2021
  4. Carlo ArenasNov 4, 2021
  5. Jeff KingNov 4, 2021
  6. async_die_is_recursing: work around GCC v11.x issue on FedoraVictoria Dye via GitGitGadget, Nov 4, 2021
  7. Jeff KingNov 4, 2021
  8. Junio C HamanoNov 4, 2021
  9. Ævar Arnfjörð BjarmasonNov 4, 2021
  10. Derrick StoleeNov 4, 2021
  11. Junio C HamanoNov 4, 2021
  12. Junio C HamanoNov 5, 2021
  13. Johannes SchindelinNov 4, 2021
  14. Carlo ArenasNov 4, 2021
  15. Johannes SchindelinNov 4, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.