Skip to content

Commit 0f3ab4a

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 0f3ab4a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

1.6/alpine/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ 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
1010

11+
# https://golang.org/issue/14851
12+
COPY no-pic.patch /
13+
1114
RUN set -ex \
1215
&& apk add --no-cache --virtual .build-deps \
1316
bash \
@@ -30,9 +33,10 @@ RUN set -ex \
3033
&& tar -C /usr/local -xzf golang.tar.gz \
3134
&& rm golang.tar.gz \
3235
&& cd /usr/local/go/src \
36+
&& patch -p2 -i /no-pic.patch \
3337
&& ./make.bash \
3438
\
35-
&& rm -rf /usr/local/bootstrap /usr/local/go/pkg/bootstrap \
39+
&& rm -rf /usr/local/bootstrap /usr/local/go/pkg/bootstrap /*.patch \
3640
&& apk del .build-deps
3741

3842
ENV GOPATH /go

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)