Browse code

Merge pull request #34369 from cyphar/build-buildmode-pie

*: switch to -buildmode=pie

Akihiro Suda authored on 2018/01/29 23:54:03
Showing 10 changed files
... ...
@@ -114,10 +114,10 @@ RUN set -x \
114 114
 	&& git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \
115 115
 	&& (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \
116 116
 	&& GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
117
-		go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
117
+		go build -buildmode=pie -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
118 118
 	&& (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT_SCHEMA1") \
119 119
 	&& GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
120
-		go build -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \
120
+		go build -buildmode=pie -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \
121 121
 	&& rm -rf "$GOPATH"
122 122
 
123 123
 # Install notary and notary-server
... ...
@@ -127,9 +127,9 @@ RUN set -x \
127 127
 	&& git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \
128 128
 	&& (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION") \
129 129
 	&& GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
130
-		go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
130
+		go build -buildmode=pie -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
131 131
 	&& GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
132
-		go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \
132
+		go build -buildmode=pie -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \
133 133
 	&& rm -rf "$GOPATH"
134 134
 
135 135
 # Get the "docker-py" source so we can run their integration tests
... ...
@@ -90,7 +90,7 @@ RUN set -x \
90 90
 	&& git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \
91 91
 	&& (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \
92 92
 	&& GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
93
-		go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
93
+		go build -buildmode=pie -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
94 94
 	&& rm -rf "$GOPATH"
95 95
 
96 96
 # Install notary and notary-server
... ...
@@ -100,9 +100,9 @@ RUN set -x \
100 100
 	&& git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \
101 101
 	&& (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION") \
102 102
 	&& GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
103
-		go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
103
+		go build -buildmode=pie -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
104 104
 	&& GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
105
-		go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \
105
+		go build -buildmode=pie -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \
106 106
 	&& rm -rf "$GOPATH"
107 107
 
108 108
 # Get the "docker-py" source so we can run their integration tests
... ...
@@ -85,10 +85,10 @@ RUN set -x \
85 85
 	&& git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \
86 86
 	&& (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \
87 87
 	&& GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
88
-		go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
88
+		go build -buildmode=pie -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
89 89
 	&& (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT_SCHEMA1") \
90 90
 	&& GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
91
-		go build -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \
91
+		go build -buildmode=pie -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \
92 92
 	&& rm -rf "$GOPATH"
93 93
 
94 94
 # Install notary and notary-server
... ...
@@ -98,9 +98,9 @@ RUN set -x \
98 98
 	&& git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \
99 99
 	&& (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION") \
100 100
 	&& GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
101
-		go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
101
+		go build -buildmode=pie -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
102 102
 	&& GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
103
-		go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \
103
+		go build -buildmode=pie -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \
104 104
 	&& rm -rf "$GOPATH"
105 105
 
106 106
 # Get the "docker-py" source so we can run their integration tests
... ...
@@ -31,7 +31,7 @@ ENV DOCKER_GITCOMMIT=$DOCKER_GITCOMMIT
31 31
 ADD . .
32 32
 
33 33
 # Build DockerSuite.TestBuild* dependency
34
-RUN CGO_ENABLED=0 go build -o /output/httpserver github.com/docker/docker/contrib/httpserver
34
+RUN CGO_ENABLED=0 go build -buildmode=pie -o /output/httpserver github.com/docker/docker/contrib/httpserver
35 35
 
36 36
 # Build the integration tests and copy the resulting binaries to /output/tests
37 37
 RUN hack/make.sh build-integration-test-binary
... ...
@@ -83,10 +83,10 @@ RUN set -x \
83 83
 	&& git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \
84 84
 	&& (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \
85 85
 	&& GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
86
-		go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
86
+		go build -buildmode=pie -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
87 87
 	&& (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT_SCHEMA1") \
88 88
 	&& GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
89
-		go build -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \
89
+		go build -buildmode=pie -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \
90 90
 	&& rm -rf "$GOPATH"
91 91
 
92 92
 # Install notary and notary-server
... ...
@@ -96,9 +96,9 @@ RUN set -x \
96 96
 	&& git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \
97 97
 	&& (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION") \
98 98
 	&& GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
99
-		go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
99
+		go build -buildmode=pie -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
100 100
 	&& GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
101
-		go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \
101
+		go build -buildmode=pie -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \
102 102
 	&& rm -rf "$GOPATH"
103 103
 
104 104
 # Get the "docker-py" source so we can run their integration tests
... ...
@@ -77,10 +77,10 @@ RUN set -x \
77 77
 	&& git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \
78 78
 	&& (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \
79 79
 	&& GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
80
-		go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
80
+		go build -buildmode=pie -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
81 81
 	&& (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT_SCHEMA1") \
82 82
 	&& GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
83
-		go build -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \
83
+		go build -buildmode=pie -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \
84 84
 	&& rm -rf "$GOPATH"
85 85
 
86 86
 # Install notary and notary-server
... ...
@@ -90,9 +90,9 @@ RUN set -x \
90 90
 	&& git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \
91 91
 	&& (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION") \
92 92
 	&& GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
93
-		go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
93
+		go build -buildmode=pie -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
94 94
 	&& GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
95
-		go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \
95
+		go build -buildmode=pie -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \
96 96
 	&& rm -rf "$GOPATH"
97 97
 
98 98
 # Get the "docker-py" source so we can run their integration tests
... ...
@@ -197,7 +197,7 @@ swagger-docs: ## preview the API documentation
197 197
 
198 198
 build-integration-cli-on-swarm: build ## build images and binary for running integration-cli on Swarm in parallel
199 199
 	@echo "Building hack/integration-cli-on-swarm (if build fails, please refer to hack/integration-cli-on-swarm/README.md)"
200
-	go build -o ./hack/integration-cli-on-swarm/integration-cli-on-swarm ./hack/integration-cli-on-swarm/host
200
+	go build -buildmode=pie -o ./hack/integration-cli-on-swarm/integration-cli-on-swarm ./hack/integration-cli-on-swarm/host
201 201
 	@echo "Building $(INTEGRATION_CLI_MASTER_IMAGE)"
202 202
 	docker build -t $(INTEGRATION_CLI_MASTER_IMAGE) hack/integration-cli-on-swarm/agent
203 203
 # For worker, we don't use `docker build` so as to enable DOCKER_INCREMENTAL_BINARY and so on
... ...
@@ -207,6 +207,6 @@ build-integration-cli-on-swarm: build ## build images and binary for running int
207 207
 # For avoiding bakings DOCKER_GRAPHDRIVER and so on to image, we cannot use $(DOCKER_ENVS) here
208 208
 	docker run -t -d --name $(tmp) -e DOCKER_GITCOMMIT -e BUILDFLAGS -e DOCKER_INCREMENTAL_BINARY --privileged $(DOCKER_MOUNT_PKGCACHE) $(DOCKER_IMAGE) top
209 209
 	docker exec $(tmp) hack/make.sh build-integration-test-binary dynbinary
210
-	docker exec $(tmp) go build -o /worker github.com/docker/docker/hack/integration-cli-on-swarm/agent/worker
210
+	docker exec $(tmp) go build -buildmode=pie -o /worker github.com/docker/docker/hack/integration-cli-on-swarm/agent/worker
211 211
 	docker commit -c 'ENTRYPOINT ["/worker"]' $(tmp) $(INTEGRATION_CLI_WORKER_IMAGE)
212 212
 	docker rm -f $(tmp)
... ...
@@ -60,7 +60,7 @@ install_proxy() {
60 60
 	git clone https://github.com/docker/libnetwork.git "$GOPATH/src/github.com/docker/libnetwork"
61 61
 	cd "$GOPATH/src/github.com/docker/libnetwork"
62 62
 	git checkout -q "$LIBNETWORK_COMMIT"
63
-	go build -ldflags="$PROXY_LDFLAGS" -o /usr/local/bin/docker-proxy github.com/docker/libnetwork/cmd/proxy
63
+	go build -buildmode=pie -ldflags="$PROXY_LDFLAGS" -o /usr/local/bin/docker-proxy github.com/docker/libnetwork/cmd/proxy
64 64
 }
65 65
 
66 66
 install_dockercli() {
... ...
@@ -89,7 +89,7 @@ build_dockercli() {
89 89
 	git checkout -q "v$DOCKERCLI_VERSION"
90 90
 	mkdir -p "$GOPATH/src/github.com/docker"
91 91
 	mv components/cli "$GOPATH/src/github.com/docker/cli"
92
-	go build -o /usr/local/bin/docker github.com/docker/cli/cmd/docker
92
+	go build -buildmode=pie -o /usr/local/bin/docker github.com/docker/cli/cmd/docker
93 93
 }
94 94
 
95 95
 install_gometalinter() {
... ...
@@ -97,7 +97,7 @@ install_gometalinter() {
97 97
 	go get -d github.com/alecthomas/gometalinter
98 98
 	cd "$GOPATH/src/github.com/alecthomas/gometalinter"
99 99
 	git checkout -q "$GOMETALINTER_COMMIT"
100
-	go build -o /usr/local/bin/gometalinter github.com/alecthomas/gometalinter
100
+	go build -buildmode=pie -o /usr/local/bin/gometalinter github.com/alecthomas/gometalinter
101 101
 	GOBIN=/usr/local/bin gometalinter --install
102 102
 }
103 103
 
... ...
@@ -108,7 +108,7 @@ do
108 108
 			echo "Install tomlv version $TOMLV_COMMIT"
109 109
 			git clone https://github.com/BurntSushi/toml.git "$GOPATH/src/github.com/BurntSushi/toml"
110 110
 			cd "$GOPATH/src/github.com/BurntSushi/toml" && git checkout -q "$TOMLV_COMMIT"
111
-			go build -v -o /usr/local/bin/tomlv github.com/BurntSushi/toml/cmd/tomlv
111
+			go build -buildmode=pie -v -o /usr/local/bin/tomlv github.com/BurntSushi/toml/cmd/tomlv
112 112
 			;;
113 113
 
114 114
 		runc)
... ...
@@ -157,7 +157,7 @@ do
157 157
 			git clone https://github.com/LK4D4/vndr.git "$GOPATH/src/github.com/LK4D4/vndr"
158 158
 			cd "$GOPATH/src/github.com/LK4D4/vndr"
159 159
 			git checkout -q "$VNDR_COMMIT"
160
-			go build -v -o /usr/local/bin/vndr .
160
+			go build -buildmode=pie -v -o /usr/local/bin/vndr .
161 161
 			;;
162 162
 
163 163
 		dockercli)
... ...
@@ -2,5 +2,5 @@
2 2
 # Please refer to the top-level Makefile for the worker image.
3 3
 FROM golang:1.7
4 4
 ADD . /go/src/github.com/docker/docker/hack/integration-cli-on-swarm/agent
5
-RUN go build -o /master github.com/docker/docker/hack/integration-cli-on-swarm/agent/master
5
+RUN go build -buildmode=pie -o /master github.com/docker/docker/hack/integration-cli-on-swarm/agent/master
6 6
 ENTRYPOINT ["/master"]
... ...
@@ -50,6 +50,11 @@ if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARC
50 50
 	esac
51 51
 fi
52 52
 
53
+# -buildmode=pie is not supported on Windows.
54
+if [ "$(go env GOOS)" != "windows" ]; then
55
+	BUILDFLAGS+=( "-buildmode=pie" )
56
+fi
57
+
53 58
 echo "Building: $DEST/$BINARY_FULLNAME"
54 59
 go build \
55 60
 	-o "$DEST/$BINARY_FULLNAME" \