Skip to content

Commit 2a405ee

Browse files
1 parent 7319ccc commit 2a405ee

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

1.6/alpine/17847.patch

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
2+
index bdfa056..ebfb418 100644
3+
--- a/src/cmd/link/internal/ld/lib.go
4+
+++ b/src/cmd/link/internal/ld/lib.go
5+
@@ -1173,6 +1173,28 @@ func hostlink() {
6+
7+
argv = append(argv, ldflag...)
8+
9+
+ // When building a program with the default -buildmode=exe the
10+
+ // gc compiler generates code requires DT_TEXTREL in a
11+
+ // position independent executable (PIE). On systems where the
12+
+ // toolchain creates PIEs by default, and where DT_TEXTREL
13+
+ // does not work, the resulting programs will not run. See
14+
+ // issue #17847. To avoid this problem pass -no-pie to the
15+
+ // toolchain if it is supported.
16+
+ if Buildmode == BuildmodeExe {
17+
+ src := filepath.Join(*flagTmpdir, "trivial.c")
18+
+ if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
19+
+ Errorf(nil, "WriteFile trivial.c failed: %v", err)
20+
+ }
21+
+ cmd := exec.Command(argv[0], "-c", "-no-pie", "trivial.c")
22+
+ cmd.Dir = *flagTmpdir
23+
+ cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...)
24+
+ out, err := cmd.CombinedOutput()
25+
+ supported := err == nil && !bytes.Contains(out, []byte("unrecognized"))
26+
+ if supported {
27+
+ argv = append(argv, "-no-pie")
28+
+ }
29+
+ }
30+
+
31+
for _, p := range strings.Fields(extldflags) {
32+
argv = append(argv, p)
33+

1.6/alpine/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ ENV GOLANG_SRC_SHA256 6326aeed5f86cf18f16d6dc831405614f855e2d416a91fd3fdc334f772
88

99
# https://golang.org/issue/14851
1010
COPY no-pic.patch /
11+
# https://golang.org/issue/17847
12+
COPY 17847.patch /
1113

1214
RUN set -ex \
1315
&& apk add --no-cache --virtual .build-deps \
@@ -25,6 +27,7 @@ RUN set -ex \
2527
&& rm golang.tar.gz \
2628
&& cd /usr/local/go/src \
2729
&& patch -p2 -i /no-pic.patch \
30+
&& patch -p2 -i /17847.patch \
2831
&& ./make.bash \
2932
\
3033
&& rm -rf /*.patch \

1.7/alpine/17847.patch

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
2+
index 14f4fa9..7bc8c84 100644
3+
--- a/src/cmd/link/internal/ld/lib.go
4+
+++ b/src/cmd/link/internal/ld/lib.go
5+
@@ -1251,6 +1251,28 @@ func hostlink() {
6+
}
7+
}
8+
9+
+ // When building a program with the default -buildmode=exe the
10+
+ // gc compiler generates code requires DT_TEXTREL in a
11+
+ // position independent executable (PIE). On systems where the
12+
+ // toolchain creates PIEs by default, and where DT_TEXTREL
13+
+ // does not work, the resulting programs will not run. See
14+
+ // issue #17847. To avoid this problem pass -no-pie to the
15+
+ // toolchain if it is supported.
16+
+ if Buildmode == BuildmodeExe {
17+
+ src := filepath.Join(*flagTmpdir, "trivial.c")
18+
+ if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
19+
+ Errorf(nil, "WriteFile trivial.c failed: %v", err)
20+
+ }
21+
+ cmd := exec.Command(argv[0], "-c", "-no-pie", "trivial.c")
22+
+ cmd.Dir = *flagTmpdir
23+
+ cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...)
24+
+ out, err := cmd.CombinedOutput()
25+
+ supported := err == nil && !bytes.Contains(out, []byte("unrecognized"))
26+
+ if supported {
27+
+ argv = append(argv, "-no-pie")
28+
+ }
29+
+ }
30+
+
31+
for _, p := range strings.Fields(extldflags) {
32+
argv = append(argv, p)
33+

1.7/alpine/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ ENV GOLANG_SRC_SHA256 79430a0027a09b0b3ad57e214c4c1acfdd7af290961dd08d322818895a
88

99
# https://golang.org/issue/14851
1010
COPY no-pic.patch /
11+
# https://golang.org/issue/17847
12+
COPY 17847.patch /
1113

1214
RUN set -ex \
1315
&& apk add --no-cache --virtual .build-deps \
@@ -25,6 +27,7 @@ RUN set -ex \
2527
&& rm golang.tar.gz \
2628
&& cd /usr/local/go/src \
2729
&& patch -p2 -i /no-pic.patch \
30+
&& patch -p2 -i /17847.patch \
2831
&& ./make.bash \
2932
\
3033
&& rm -rf /*.patch \

0 commit comments

Comments
 (0)