|
|
315b776 |
From 3502496d03bcd842fd7aac95ec0d7096d581cd26 Mon Sep 17 00:00:00 2001
|
|
|
315b776 |
From: Lynn Boger <laboger@linux.vnet.ibm.com>
|
|
|
315b776 |
Date: Wed, 11 Oct 2017 16:02:59 -0400
|
|
|
315b776 |
Subject: [PATCH] misc/cgo/testcarchive: use -no-pie where needed
|
|
|
315b776 |
|
|
|
315b776 |
Starting in gcc 6, -pie is passed to the linker by default
|
|
|
315b776 |
on some platforms, including ppc64le. If the objects
|
|
|
315b776 |
being linked are not built for -pie then in some cases the
|
|
|
315b776 |
executable could be in error. To avoid that problem, -no-pie
|
|
|
315b776 |
should be used with gcc to override the default -pie option
|
|
|
315b776 |
and generate a correct executable that can be run without error.
|
|
|
315b776 |
|
|
|
315b776 |
Fixes #22126
|
|
|
315b776 |
|
|
|
315b776 |
Change-Id: I4a052bba8b9b3bd6706f5d27ca9a7cebcb504c95
|
|
|
315b776 |
Reviewed-on: https://go-review.googlesource.com/70072
|
|
|
315b776 |
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
|
|
|
315b776 |
TryBot-Result: Gobot Gobot <gobot@golang.org>
|
|
|
315b776 |
Reviewed-by: Ian Lance Taylor <iant@golang.org>
|
|
|
315b776 |
---
|
|
|
315b776 |
misc/cgo/testcarchive/carchive_test.go | 20 +++++++++++++++++++-
|
|
|
315b776 |
1 file changed, 19 insertions(+), 1 deletion(-)
|
|
|
315b776 |
|
|
|
315b776 |
diff --git a/misc/cgo/testcarchive/carchive_test.go b/misc/cgo/testcarchive/carchive_test.go
|
|
|
315b776 |
index b5123154e79..ac637c06007 100644
|
|
|
315b776 |
--- a/misc/cgo/testcarchive/carchive_test.go
|
|
|
315b776 |
+++ b/misc/cgo/testcarchive/carchive_test.go
|
|
|
315b776 |
@@ -6,6 +6,7 @@ package carchive_test
|
|
|
315b776 |
|
|
|
315b776 |
import (
|
|
|
315b776 |
"bufio"
|
|
|
315b776 |
+ "bytes"
|
|
|
315b776 |
"debug/elf"
|
|
|
315b776 |
"fmt"
|
|
|
315b776 |
"io/ioutil"
|
|
|
315b776 |
@@ -609,9 +610,26 @@ func TestCompileWithoutShared(t *testing.T) {
|
|
|
315b776 |
}
|
|
|
315b776 |
|
|
|
315b776 |
exe := "./testnoshared" + exeSuffix
|
|
|
315b776 |
- ccArgs := append(cc, "-o", exe, "main5.c", "libgo2.a")
|
|
|
315b776 |
+
|
|
|
315b776 |
+ // In some cases, -no-pie is needed here, but not accepted everywhere. First try
|
|
|
315b776 |
+ // if -no-pie is accepted. See #22126.
|
|
|
315b776 |
+ ccArgs := append(cc, "-o", exe, "-no-pie", "main5.c", "libgo2.a")
|
|
|
315b776 |
t.Log(ccArgs)
|
|
|
315b776 |
out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput()
|
|
|
315b776 |
+
|
|
|
315b776 |
+ // If -no-pie unrecognized, try -nopie if this is possibly clang
|
|
|
315b776 |
+ if err != nil && bytes.Contains(out, []byte("unknown")) && !strings.Contains(cc[0], "gcc") {
|
|
|
315b776 |
+ ccArgs = append(cc, "-o", exe, "-nopie", "main5.c", "libgo2.a")
|
|
|
315b776 |
+ t.Log(ccArgs)
|
|
|
315b776 |
+ out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput()
|
|
|
315b776 |
+ }
|
|
|
315b776 |
+
|
|
|
315b776 |
+ // Don't use either -no-pie or -nopie
|
|
|
315b776 |
+ if err != nil && bytes.Contains(out, []byte("unrecognized")) {
|
|
|
315b776 |
+ ccArgs := append(cc, "-o", exe, "main5.c", "libgo2.a")
|
|
|
315b776 |
+ t.Log(ccArgs)
|
|
|
315b776 |
+ out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput()
|
|
|
315b776 |
+ }
|
|
|
315b776 |
t.Logf("%s", out)
|
|
|
315b776 |
if err != nil {
|
|
|
315b776 |
t.Fatal(err)
|