Skip to content

Commit bc9b87d

Browse files
committed
runtime/cgo: provide backward compatibility with old glibc for cgo
Fixes: golang#65625 Before go1.22, the example in golang#65625 can be run successfully, though the core issue is in old version glibc, but it will be better to provide this backward compatibility to let people can upgrade to go 1.22+. Signed-off-by: lifubang <[email protected]>
1 parent 9623a35 commit bc9b87d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/runtime/cgo/gcc_stack_unix.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ x_cgo_getstackbound(uintptr bounds[2])
1717
pthread_attr_t attr;
1818
void *addr;
1919
size_t size;
20+
int err;
2021

2122
#if defined(__GLIBC__) || (defined(__sun) && !defined(__illumos__))
2223
// pthread_getattr_np is a GNU extension supported in glibc.
2324
// Solaris is not glibc but does support pthread_getattr_np
2425
// (and the fallback doesn't work...). Illumos does not.
25-
pthread_getattr_np(pthread_self(), &attr); // GNU extension
26+
err = pthread_getattr_np(pthread_self(), &attr); // GNU extension
27+
if (err != 0) {
28+
// This is to have a backward compatibility with glibc < 2.32
29+
pthread_attr_init(&attr);
30+
pthread_getattr_np(pthread_self(), &attr);
31+
}
32+
2633
pthread_attr_getstack(&attr, &addr, &size); // low address
2734
#elif defined(__illumos__)
2835
pthread_attr_init(&attr);

0 commit comments

Comments
 (0)