Commit 30bdc472 authored by Matthew Finkel's avatar Matthew Finkel
Browse files

Merge remote-tracking branch 'gktpo/bug_32027_v4'

parents ea9ec4f8 260a8442
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
From 44e3391a5a3d9a2c4b57f78e43414465ab84681e Mon Sep 17 00:00:00 2001
From: Nicolas Vigier <boklm@torproject.org>
Date: Thu, 27 Jun 2019 19:21:05 +0200
From 958f724b1b434702c3d44ceaca646791674d07b1 Mon Sep 17 00:00:00 2001
From: Georg Koppen <gk@torproject.org>
Date: Fri, 17 Apr 2020 10:24:23 +0000
Subject: [PATCH] Use fixed go-build tmp directory

Use fixed go-build tmp directory, when the directory does not exist, in
order to avoid some reproducibility issues where build directory gets
embedded in generated binaries.
---
 src/cmd/go/internal/work/action.go | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/cmd/go/internal/work/action.go b/src/cmd/go/internal/work/action.go
index 1f91046eb1..ba74b26a38 100644
index 33b7818fb2..5e369d0f53 100644
--- a/src/cmd/go/internal/work/action.go
+++ b/src/cmd/go/internal/work/action.go
@@ -224,9 +224,13 @@ func (b *Builder) Init() {
@@ -249,9 +249,13 @@ func (b *Builder) Init() {
 	if cfg.BuildN {
 		b.WorkDir = "$WORK"
 	} else {
-		tmp, err := ioutil.TempDir(os.Getenv("GOTMPDIR"), "go-build")
-		tmp, err := ioutil.TempDir(cfg.Getenv("GOTMPDIR"), "go-build")
-		if err != nil {
-			base.Fatalf("go: creating work dir: %v", err)
+		tmp := filepath.Join(os.Getenv("GOTMPDIR"), "go-build-workdir")
+		tmp := filepath.Join(cfg.Getenv("GOTMPDIR"), "go-build-workdir")
+		_, err := os.Stat(tmp)
+		if !os.IsNotExist(err) {
+			tmp, err = ioutil.TempDir(os.Getenv("GOTMPDIR"), "go-build")
+			tmp, err = ioutil.TempDir(cfg.Getenv("GOTMPDIR"), "go-build")
+			if err != nil {
+				base.Fatalf("go: creating work dir: %v", err)
+			}
 		}
 		if !filepath.IsAbs(tmp) {
 			abs, err := filepath.Abs(tmp)
-- 
2.26.1
+0 −57
Original line number Diff line number Diff line
From 90a3ce02dc25adcf1598faf11a66b151ada3f637 Mon Sep 17 00:00:00 2001
From: Elias Naur <mail@eliasnaur.com>
Date: Wed, 27 Mar 2019 14:25:24 +0100
Subject: [PATCH] cmd/link/internal/ld: skip TLS section on Android

We don't use the TLS section on android, and dropping it avoids
complaints about underalignment from the Android Q linker.

Updates #29674

Change-Id: I91dabf2a58e6eb1783872639a6a144858db09cef
Reviewed-on: https://go-review.googlesource.com/c/go/+/169618
Reviewed-by: Ian Lance Taylor <iant@golang.org>
---
 src/cmd/link/internal/ld/lib.go | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 1d44c0eb18b..b331e39fe3e 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -453,18 +453,23 @@ func (ctxt *Link) loadlib() {
 		}
 	}
 
-	tlsg := ctxt.Syms.Lookup("runtime.tlsg", 0)
-
-	// runtime.tlsg is used for external linking on platforms that do not define
-	// a variable to hold g in assembly (currently only intel).
-	if tlsg.Type == 0 {
-		tlsg.Type = sym.STLSBSS
-		tlsg.Size = int64(ctxt.Arch.PtrSize)
-	} else if tlsg.Type != sym.SDYNIMPORT {
-		Errorf(nil, "runtime declared tlsg variable %v", tlsg.Type)
-	}
-	tlsg.Attr |= sym.AttrReachable
-	ctxt.Tlsg = tlsg
+	// The Android Q linker started to complain about underalignment of the our TLS
+	// section. We don't actually use the section on android, so dont't
+	// generate it.
+	if objabi.GOOS != "android" {
+		tlsg := ctxt.Syms.Lookup("runtime.tlsg", 0)
+
+		// runtime.tlsg is used for external linking on platforms that do not define
+		// a variable to hold g in assembly (currently only intel).
+		if tlsg.Type == 0 {
+			tlsg.Type = sym.STLSBSS
+			tlsg.Size = int64(ctxt.Arch.PtrSize)
+		} else if tlsg.Type != sym.SDYNIMPORT {
+			Errorf(nil, "runtime declared tlsg variable %v", tlsg.Type)
+		}
+		tlsg.Attr |= sym.AttrReachable
+		ctxt.Tlsg = tlsg
+	}
 
 	var moduledata *sym.Symbol
 	if ctxt.BuildMode == BuildModePlugin {
+0 −2
Original line number Diff line number Diff line
@@ -68,8 +68,6 @@ cd /var/tmp/dist/go/src
  CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
[% ELSIF c("var/android") -%]
  patch -p2 < $rootdir/0001-Use-fixed-go-build-tmp-directory.patch
  # Obfs4 breaks on Android Q without this patch, see: #32303
  patch -p2 < $rootdir/90a3ce02dc25adcf1598faf11a66b151ada3f637.patch
  CGO_ENABLED=1 CC_FOR_TARGET=[% c("var/CC") %] CGO_CFLAGS='-D__ANDROID_API__=[% c("var/android_min_api") %]' CC= CFLAGS= LDFLAGS= ./make.bash
[% END -%]

+8 −4
Original line number Diff line number Diff line
# vim: filetype=yaml sw=2
version: 1.12.13
version: 1.13.10
filename: '[% project %]-[% c("version") %]-[% c("var/build_id") %].tar.gz'

var:
@@ -17,6 +17,9 @@ var:
      export GOOS=[% c("var/GOOS") %]
      export GOARCH=[% c("var/GOARCH") %]
    [% END -%]
    # Run in GOPATH mode: https://golang.org/cmd/go/#hdr-Module_support. (see:
    # #32027)
    export GO111MODULE=off
    export GOPATH=/var/tmp/dist/gopath
    export PATH=/var/tmp/dist/go/bin:/var/tmp/dist/gopath/bin:"$PATH"
    [% IF c("var/linux") -%]
@@ -50,6 +53,9 @@ var:
    do
      patch -p1 < $p
    done
    # Run in GOPATH mode: https://golang.org/cmd/go/#hdr-Module_support. (see:
    # #32027)
    export GO111MODULE=off
    [% IF c("var/build_go_lib_pre"); GET c("var/build_go_lib_pre"); END; -%]
    [% IF c("var/go_lib_install") -%]
      [% FOREACH inst IN c("var/go_lib_install") %]
@@ -112,11 +118,9 @@ input_files:
    enable: '[% ! c("var/linux") %]'
  - URL: 'https://golang.org/dl/go[% c("version") %].src.tar.gz'
    name: go
    sha256sum: 5383d3b8db4baa48284ffcb14606d9cad6f03e9db843fa6d835b94d63cccf5a7
    sha256sum: eb9ccc8bf59ed068e7eff73e154e4f5ee7eec0a47a610fb864e3332a2fdc8b8c
  - URL: 'https://golang.org/dl/go[% c("var/go14_version") %].src.tar.gz'
    name: go14
    sha256sum: 9947fc705b0b841b5938c48b22dc33e9647ec0752bae66e50278df4f23f64959
  - filename: 0001-Use-fixed-go-build-tmp-directory.patch
    enable: '[% c("var/android") %]'
  - filename: 90a3ce02dc25adcf1598faf11a66b151ada3f637.patch
    enable: '[% c("var/android") %]'
+4 −3
Original line number Diff line number Diff line
@@ -7,6 +7,9 @@ mkdir -p $PTDIR

[% IF c("var/android") -%]
  [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  # We need to explicitly set CGO_ENABLED with Go 1.13.x as the Android build
  # breaks otherwise.
  export CGO_ENABLED=1
[% END -%]

tar -C /var/tmp/dist -xf [% c('input_files_by_name/goptlib') %]
@@ -22,11 +25,9 @@ mkdir -p /var/tmp/build
tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
cd /var/tmp/build/[% project %]-[% c('version') %]

# Remove go.mod and go.sum files until we can build using Go module
# versioning (see bug 28325).
rm -f go.mod go.sum
mkdir -p "$GOPATH/src/gitlab.com/yawning"
ln -sf "$PWD" "$GOPATH/src/gitlab.com/yawning/obfs4.git"

cd obfs4proxy
go build -ldflags '-s'
cp -a obfs4proxy[% IF c("var/windows") %].exe[% END %] $PTDIR
Loading