Skip to content

Commit

Permalink
Merge pull request docker-library#91 from ncopa/golang-alpine-pie-fix
Browse files Browse the repository at this point in the history
add -fno-PIC when using external linker on alpine
  • Loading branch information
yosifkit committed Mar 31, 2016
2 parents 3cdd851 + 0f3ab4a commit 7339ea4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion 1.6/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ENV GOLANG_BOOTSTRAP_VERSION 1.4.3
ENV GOLANG_BOOTSTRAP_URL https://golang.org/dl/go$GOLANG_BOOTSTRAP_VERSION.src.tar.gz
ENV GOLANG_BOOTSTRAP_SHA1 486db10dc571a55c8d795365070f66d343458c48

# https://golang.org/issue/14851
COPY no-pic.patch /

RUN set -ex \
&& apk add --no-cache --virtual .build-deps \
bash \
Expand All @@ -30,9 +33,10 @@ RUN set -ex \
&& tar -C /usr/local -xzf golang.tar.gz \
&& rm golang.tar.gz \
&& cd /usr/local/go/src \
&& patch -p2 -i /no-pic.patch \
&& ./make.bash \
\
&& rm -rf /usr/local/bootstrap /usr/local/go/pkg/bootstrap \
&& rm -rf /usr/local/bootstrap /usr/local/go/pkg/bootstrap /*.patch \
&& apk del .build-deps

ENV GOPATH /go
Expand Down
16 changes: 16 additions & 0 deletions 1.6/alpine/no-pic.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 8ccbec9dd634..4e96bfadc260 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -1194,6 +1194,11 @@ func hostlink() {
argv = append(argv, peimporteddlls()...)
}

+ // The Go linker does not currently support building PIE
+ // executables when using the external linker. See:
+ // https://github.com/golang/go/issues/6940
+ argv = append(argv, "-fno-PIC")
+
if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "host link:")
for _, v := range argv {

0 comments on commit 7339ea4

Please sign in to comment.