Skip to content

Commit

Permalink
runtime/cgo: provide backward compatibility with old glibc for cgo
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lifubang committed May 20, 2024
1 parent 9623a35 commit bc9b87d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/runtime/cgo/gcc_stack_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ x_cgo_getstackbound(uintptr bounds[2])
pthread_attr_t attr;
void *addr;
size_t size;
int err;

#if defined(__GLIBC__) || (defined(__sun) && !defined(__illumos__))
// pthread_getattr_np is a GNU extension supported in glibc.
// Solaris is not glibc but does support pthread_getattr_np
// (and the fallback doesn't work...). Illumos does not.
pthread_getattr_np(pthread_self(), &attr); // GNU extension
err = pthread_getattr_np(pthread_self(), &attr); // GNU extension
if (err != 0) {
// This is to have a backward compatibility with glibc < 2.32
pthread_attr_init(&attr);
pthread_getattr_np(pthread_self(), &attr);
}

pthread_attr_getstack(&attr, &addr, &size); // low address
#elif defined(__illumos__)
pthread_attr_init(&attr);
Expand Down

0 comments on commit bc9b87d

Please sign in to comment.