Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GOFLAGS="-buildmode=pie" leads to segfaulting executable on 386 #278

Open
zmedico opened this issue Nov 19, 2023 · 4 comments
Open

GOFLAGS="-buildmode=pie" leads to segfaulting executable on 386 #278

zmedico opened this issue Nov 19, 2023 · 4 comments

Comments

@zmedico
Copy link

zmedico commented Nov 19, 2023

This issue was originally reported in https://bugs.gentoo.org/917577, and I was able to reproduce it in the 386 version of the debian:unstable-20231030 docker image, like this:

# Select the 386 version of debian:unstable-20231030 by sha256 hash.
FROM docker.io/library/debian@sha256:fc007e931599ce93e8feb29ce52c5a750e387f195670938c7023716189522a36
RUN apt update && \
	apt install -y golang git make && 
	git clone --depth=1 https://github.com/prometheus/promu.git /tmp/promu && \
	env GOFLAGS="-buildmode=pie" make -C /tmp/promu build && \
	/tmp/promu/promu

The make command exits "successfully" after emitting a message like this:

# github.com/prometheus/promu
loadinternal: cannot find runtime/cgo

The resulting executable segfaults regardless of arguments:

# /tmp/promu/promu 
Segmentation fault (core dumped)
@zmedico
Copy link
Author

zmedico commented Nov 20, 2023

If I enable the promu builld --cgo option or set go.cgo true in .promu.yml, then it suppresses the issue.

@zmedico
Copy link
Author

zmedico commented Nov 22, 2023

If I enable the promu builld --cgo option or set go.cgo true in .promu.yml, then it suppresses the issue.

However, with cgo enabled, the resulting executable is not a pie executable:

# file /tmp/promu/promu
/tmp/promu/promu: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, BuildID[sha1]=89ffa6bf6408eee0c5e1ca0ca3ee8e2121227088, for GNU/Linux 3.2.0, stripped

And the build emits these warnings:

GO111MODULE= /root/go/bin/promu build --prefix /tmp/promu
 >   promu
# github.com/prometheus/promu
/usr/bin/ld: /tmp/go-link-2178255396/000002.o: in function `mygetgrouplist':
/_/GOROOT/src/os/user/getgrouplist_unix.go:15:(.text+0x29): warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-2178255396/000001.o: in function `mygetgrgid_r':
/_/GOROOT/src/os/user/cgo_lookup_cgo.go:45:(.text+0x5d): warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-2178255396/000001.o: in function `mygetgrnam_r':
/_/GOROOT/src/os/user/cgo_lookup_cgo.go:54:(.text+0x11d): warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-2178255396/000001.o: in function `mygetpwnam_r':
/_/GOROOT/src/os/user/cgo_lookup_cgo.go:36:(.text+0x1e9): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-2178255396/000001.o: in function `mygetpwuid_r':
/_/GOROOT/src/os/user/cgo_lookup_cgo.go:27:(.text+0x2e9): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

@zmedico
Copy link
Author

zmedico commented Nov 27, 2023

When tried adding -buildmode=pie to build.flags in .promu.yml (as suggested in #158), results were no different than when it was specified via GOFLAGS.

@zmedico
Copy link
Author

zmedico commented Feb 20, 2024

Also see golang/go#47949.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant