Bug 29899 - Fix for bz#20305 broke glibc on alpha-linux-gnu
Summary: Fix for bz#20305 broke glibc on alpha-linux-gnu
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-13 17:43 UTC by John Paul Adrian Glaubitz
Modified: 2022-12-30 14:35 UTC (History)
8 users (show)

See Also:
Host: alpha-linux-gnu
Target:
Build:
Last reconfirmed: 2022-12-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Paul Adrian Glaubitz 2022-12-13 17:43:17 UTC
The following commit broke glibc on alpha-linux-gnu, in this case Debian unstable running on Alpha:

commit 6c57d320484988e87e446e2e60ce42816bf51d53
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Feb 1 11:00:38 2021 -0800

    sysconf: Add _SC_MINSIGSTKSZ/_SC_SIGSTKSZ [BZ #20305]
    
    Add _SC_MINSIGSTKSZ for the minimum signal stack size derived from
    AT_MINSIGSTKSZ, which is the minimum number of bytes of free stack
    space required in order to gurantee successful, non-nested handling
    of a single signal whose handler is an empty function, and _SC_SIGSTKSZ
    which is the suggested minimum number of bytes of stack space required
    for a signal stack.

Without the patch applied, running bash in a qemu-user-static chroot from the build directory of a cross-compiled build works fine:

(sid-alpha-sbuild)glaubitz@z6:~/glibc-git/build$ LD_LIBRARY_PATH=/home/glaubitz/glibc-git/build /bin/bash
(sid-alpha-sbuild)glaubitz@z6:~/glibc-git/build$ 
exit

With the patch applied, the above command results in a segmentation fault:

(sid-alpha-sbuild)glaubitz@z6:~/glibc-git/build$ LD_LIBRARY_PATH=/home/glaubitz/glibc-git/build /bin/bash
Segmentation fault
(sid-alpha-sbuild)glaubitz@z6:~/glibc-git/build$

The issue also becomes apparent when comparing the testsuite failures for glibc-2.33 and glibc-2.34 in Debian unstable:

> https://buildd.debian.org/status/fetch.php?pkg=glibc&arch=alpha&ver=2.33-8&stamp=1657736413&raw=0
> https://buildd.debian.org/status/fetch.php?pkg=glibc&arch=alpha&ver=2.34-1&stamp=1659947712&raw=0
Comment 1 H.J. Lu 2022-12-13 19:52:23 UTC
What are values of SIGSTKSZ and MINSIGSTKSZ before and after the commit?
Comment 2 John Paul Adrian Glaubitz 2022-12-13 20:38:00 UTC
(In reply to H.J. Lu from comment #1)
> What are values of SIGSTKSZ and MINSIGSTKSZ before and after the commit?

I'm not sure how to read out those values as I tried it with small test program which crashes after the commit.

Without commit, I get:

(sid-alpha-sbuild)glaubitz@z6:~/glibc-git/build$ /bz20305 
The value of SIGSTKSZ is 16384.
The value of MINSIGSTKSZ is 4096.
(sid-alpha-sbuild)glaubitz@z6:~/glibc-git/build$

I used the following test program:

#include <stdio.h>
#include <signal.h>

int main() {

        printf("The value of SIGSTKSZ is %d.\n", SIGSTKSZ);
        printf("The value of MINSIGSTKSZ is %d.\n", MINSIGSTKSZ);

        return 0;
}

Do you have any other suggestion for dumping the values?
Comment 3 H.J. Lu 2022-12-13 21:12:12 UTC
(In reply to John Paul Adrian Glaubitz from comment #2)
> (In reply to H.J. Lu from comment #1)
> > What are values of SIGSTKSZ and MINSIGSTKSZ before and after the commit?
> 
> I'm not sure how to read out those values as I tried it with small test
> program which crashes after the commit.
> 
> Without commit, I get:
> 
> (sid-alpha-sbuild)glaubitz@z6:~/glibc-git/build$ /bz20305 
> The value of SIGSTKSZ is 16384.
> The value of MINSIGSTKSZ is 4096.
> (sid-alpha-sbuild)glaubitz@z6:~/glibc-git/build$
> 
> I used the following test program:
> 
> #include <stdio.h>
> #include <signal.h>
> 
> int main() {
> 
>         printf("The value of SIGSTKSZ is %d.\n", SIGSTKSZ);
>         printf("The value of MINSIGSTKSZ is %d.\n", MINSIGSTKSZ);
> 
>         return 0;
> }
> 
> Do you have any other suggestion for dumping the values?

Why does this program crash with the commit?
Comment 4 John Paul Adrian Glaubitz 2022-12-13 21:22:47 UTC
(In reply to H.J. Lu from comment #3)
> Why does this program crash with the commit?

That's what I am trying to find out. I suspect that the values of MINSIGSTKSZ and SIGSTKSZ are not the cause of the problem.
Comment 5 John Paul Adrian Glaubitz 2022-12-14 07:53:10 UTC
This is the minimum change directly on top the commit that fixes the problem for me:

diff --git a/elf/dl-sysdep.c b/elf/dl-sysdep.c
index bd5066fe3b..bc45a6e9d3 100644
--- a/elf/dl-sysdep.c
+++ b/elf/dl-sysdep.c
@@ -115,10 +115,10 @@ _dl_sysdep_start (void **start_argptr,
   user_entry = (ElfW(Addr)) ENTRY_POINT;
   GLRO(dl_platform) = NULL; /* Default to nothing known about the platform.  */
 
-  /* NB: Default to a constant CONSTANT_MINSIGSTKSZ.  */
-  _Static_assert (__builtin_constant_p (CONSTANT_MINSIGSTKSZ),
-             "CONSTANT_MINSIGSTKSZ is constant");
-  GLRO(dl_minsigstacksize) = CONSTANT_MINSIGSTKSZ;
+  /* /\* NB: Default to a constant CONSTANT_MINSIGSTKSZ.  *\/ */
+  /* _Static_assert (__builtin_constant_p (CONSTANT_MINSIGSTKSZ), */
+  /*                   "CONSTANT_MINSIGSTKSZ is constant"); */
+  /* GLRO(dl_minsigstacksize) = CONSTANT_MINSIGSTKSZ; */
 
   for (av = GLRO(dl_auxv); av->a_type != AT_NULL; set_seen (av++))
     switch (av->a_type)
@@ -184,9 +184,9 @@ _dl_sysdep_start (void **start_argptr,
       case AT_RANDOM:
        _dl_random = (void *) av->a_un.a_val;
        break;
-      case AT_MINSIGSTKSZ:
-   GLRO(dl_minsigstacksize) = av->a_un.a_val;
-   break;
+      /* case AT_MINSIGSTKSZ: */
+      /*     GLRO(dl_minsigstacksize) = av->a_un.a_val; */
+      /*     break; */
       DL_PLATFORM_AUXV
       }
 
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 9720a4e446..9ead714718 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -536,8 +536,8 @@ struct rtld_global_ro
   /* Cached value of `getpagesize ()'.  */
   EXTERN size_t _dl_pagesize;
 
-  /* Cached value of `sysconf (_SC_MINSIGSTKSZ)'.  */
-  EXTERN size_t _dl_minsigstacksize;
+  /* /\* Cached value of `sysconf (_SC_MINSIGSTKSZ)'.  *\/ */
+  /* EXTERN size_t _dl_minsigstacksize; */
 
   /* Do we read from ld.so.cache?  */
   EXTERN int _dl_inhibit_cache;
diff --git a/sysdeps/unix/sysv/linux/sysconf.c b/sysdeps/unix/sysv/linux/sysconf.c
index 366fcef01e..5a5c89f80e 100644
--- a/sysdeps/unix/sysv/linux/sysconf.c
+++ b/sysdeps/unix/sysv/linux/sysconf.c
@@ -77,12 +77,12 @@ __sysconf (int name)
       }
       break;
 
-    case _SC_MINSIGSTKSZ:
-      assert (GLRO(dl_minsigstacksize) != 0);
-      return GLRO(dl_minsigstacksize);
+    /* case _SC_MINSIGSTKSZ: */
+    /*   assert (GLRO(dl_minsigstacksize) != 0); */
+    /*   return GLRO(dl_minsigstacksize); */
 
-    case _SC_SIGSTKSZ:
-      return sysconf_sigstksz ();
+    /* case _SC_SIGSTKSZ: */
+    /*   return sysconf_sigstksz (); */
 
     default:
       break;

So, my suspicion is that adding the variable _dl_minsigstacksize to struct rtld_global_ro {} breaks the ABI on Alpha.
Comment 6 H.J. Lu 2022-12-14 16:00:46 UTC
(In reply to John Paul Adrian Glaubitz from comment #5)
> So, my suspicion is that adding the variable _dl_minsigstacksize to struct
> rtld_global_ro {} breaks the ABI on Alpha.

rtld_global_ro is private to glibc.  Are there any hardcoded rtld_global_ro
related values on Alpha?
Comment 7 John Paul Adrian Glaubitz 2022-12-21 10:25:30 UTC
It seems that this issue has been fixed in version 2.36 but there is another issue which so far I have failed to bisect:

(sid-alpha-sbuild)glaubitz@nofan:~/glibc-git/build$ LD_LIBRARY_PATH=/home/glaubitz/glibc-git/build /bin/bash
Floating point exception
(sid-alpha-sbuild)glaubitz@nofan:~/glibc-git/build$
Comment 8 John Paul Adrian Glaubitz 2022-12-30 14:35:36 UTC
After discussing this issue with Adhemveral, it turns out that my testing method was incorrect and the segfault was a result of mixing ld.so and libc.so from different glibc builds which, of course, doesn't work.

Closing this issue although the original problem may still exist. It affects statically linked programs only, however.