Skip to content

Commit 16dd63a

Browse files
committed
add -fno-PIC when using external linker on alpine
The Alpine toolchain enables PIE by default. Since the go linker does not (yet) support PIE we need to explicitly disable it on Alpine. This is a workaround for golang/go#14851
1 parent 3cdd851 commit 16dd63a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

1.6/alpine/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ENV GOLANG_SRC_SHA256 a96cce8ce43a9bf9b2a4c7d470bc7ee0cb00410da815980681c8353218
77
ENV GOLANG_BOOTSTRAP_VERSION 1.4.3
88
ENV GOLANG_BOOTSTRAP_URL https://golang.org/dl/go$GOLANG_BOOTSTRAP_VERSION.src.tar.gz
99
ENV GOLANG_BOOTSTRAP_SHA1 486db10dc571a55c8d795365070f66d343458c48
10+
COPY no-pic.patch /
1011

1112
RUN set -ex \
1213
&& apk add --no-cache --virtual .build-deps \
@@ -30,11 +31,13 @@ RUN set -ex \
3031
&& tar -C /usr/local -xzf golang.tar.gz \
3132
&& rm golang.tar.gz \
3233
&& cd /usr/local/go/src \
34+
&& patch -p2 -i /no-pic.patch \
3335
&& ./make.bash \
3436
\
35-
&& rm -rf /usr/local/bootstrap /usr/local/go/pkg/bootstrap \
37+
&& rm -rf /usr/local/bootstrap /usr/local/go/pkg/bootstrap /*.patch \
3638
&& apk del .build-deps
3739

40+
3841
ENV GOPATH /go
3942
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
4043

1.6/alpine/no-pic.patch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
2+
index 8ccbec9dd634..4e96bfadc260 100644
3+
--- a/src/cmd/link/internal/ld/lib.go
4+
+++ b/src/cmd/link/internal/ld/lib.go
5+
@@ -1194,6 +1194,11 @@ func hostlink() {
6+
argv = append(argv, peimporteddlls()...)
7+
}
8+
9+
+ // The Go linker does not currently support building PIE
10+
+ // executables when using the external linker. See:
11+
+ // https://github.com/golang/go/issues/6940
12+
+ argv = append(argv, "-fno-PIC")
13+
+
14+
if Debug['v'] != 0 {
15+
fmt.Fprintf(&Bso, "host link:")
16+
for _, v := range argv {

0 commit comments

Comments
 (0)