Skip to content

Disable -fsplit-stack support on non-glibc targets

The -fsplit-stack option requires the pthread_t TCB definition in the libc to provide certain struct fields at specific hardcoded offsets. As far as I know, only glibc provides these fields at the required offsets. Most notably, musl libc does not have these fields. However, since gcc accesses the fields using a fixed offset this does not cause a compile-time error but instead results in a silent memory corruption at run-time with musl libc. For example, on s390x libgcc's __stack_split_initialize CTOR will overwrite the cancel field in the pthread_t TCB on musl.

The -fsplit-stack option is used within the gcc code base by gcc-go by default. On musl based systems with split-stack support (e.g. s390x or x86) this causes Go programs compiled with gcc-go to misbehave at run-time.

This patch fixes gcc-go on musl by disabling -fsplit-stack in gcc itself since it is not supported on non-glibc targets anyhow. This is achieved by checking if TARGET_GLIBC_MAJOR is defined to a non-zero value (it defaults to zero on non-glibc systems). The check has been added for x86 and s390x, the rs6000 config already checks for TARGET_GLIBC_MAJOR. Other architectures do not have split-stack support. With this patch applied, the gcc-go configure script will detect that -fsplit-stack support is not available and will not use it.

See https://www.openwall.com/lists/musl/2012/10/16/12

This patch has been tested on Alpine Linux Edge on the s390x architecture by bootstrapping Google's Go implementation with gcc-go.

Signed-off-by: Sören Tempel soeren+git@soeren-tempel.net

Merge request reports

Loading