public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@golang.org>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
		"gofrontend-dev@googlegroups.com"
	<gofrontend-dev@googlegroups.com>
Subject: libgo patch committed: Fixes for go tool for other build modes
Date: Thu, 29 Jun 2017 15:14:00 -0000	[thread overview]
Message-ID: <CAOyqgcUyXDRh19vJEuerBU-LZty_Zakzf-jD5WamK4ZChGgE8g@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 260 bytes --]

This libgo patch fixes the go tool when using
-buildmode={c-archive,c-shared,pie} with gccgo.  The tests are
misc/cgo tests that are not currently run but will be
run soon.  Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.
Committed to mainline.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3450 bytes --]

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 249713)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-66d14d95a5a453682fe387319c80bc4fc40d96ad
+8c4d6fd19f6d5dc9b41be384c60507f2236f05ec
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/cmd/go/build.go
===================================================================
--- libgo/go/cmd/go/build.go	(revision 249205)
+++ libgo/go/cmd/go/build.go	(working copy)
@@ -342,16 +342,20 @@ func buildModeInit() {
 			}
 			return p
 		}
-		switch platform {
-		case "darwin/arm", "darwin/arm64":
-			codegenArg = "-shared"
-		default:
-			switch goos {
-			case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
-				// Use -shared so that the result is
-				// suitable for inclusion in a PIE or
-				// shared library.
+		if gccgo {
+			codegenArg = "-fPIC"
+		} else {
+			switch platform {
+			case "darwin/arm", "darwin/arm64":
 				codegenArg = "-shared"
+			default:
+				switch goos {
+				case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
+					// Use -shared so that the result is
+					// suitable for inclusion in a PIE or
+					// shared library.
+					codegenArg = "-shared"
+				}
 			}
 		}
 		exeSuffix = ".a"
@@ -374,10 +378,14 @@ func buildModeInit() {
 	case "default":
 		switch platform {
 		case "android/arm", "android/arm64", "android/amd64", "android/386":
-			codegenArg = "-shared"
+			if !gccgo {
+				codegenArg = "-shared"
+			}
 			ldBuildmode = "pie"
 		case "darwin/arm", "darwin/arm64":
-			codegenArg = "-shared"
+			if !gccgo {
+				codegenArg = "-shared"
+			}
 			fallthrough
 		default:
 			ldBuildmode = "exe"
@@ -387,7 +395,7 @@ func buildModeInit() {
 		ldBuildmode = "exe"
 	case "pie":
 		if gccgo {
-			fatalf("-buildmode=pie not supported by gccgo")
+			codegenArg = "-fPIE"
 		} else {
 			switch platform {
 			case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x",
@@ -1053,7 +1061,7 @@ func (b *builder) action1(mode buildMode
 		// Install header for cgo in c-archive and c-shared modes.
 		if p.usesCgo() && (buildBuildmode == "c-archive" || buildBuildmode == "c-shared") {
 			hdrTarget := a.target[:len(a.target)-len(filepath.Ext(a.target))] + ".h"
-			if buildContext.Compiler == "gccgo" {
+			if buildContext.Compiler == "gccgo" && *buildO == "" {
 				// For the header file, remove the "lib"
 				// added by go/build, so we generate pkg.h
 				// rather than libpkg.h.
@@ -3025,6 +3033,8 @@ func (tools gccgoToolchain) link(b *buil
 		ldflags = append(ldflags, "-shared", "-nostdlib", "-Wl,--whole-archive", "-lgolibbegin", "-Wl,--no-whole-archive", "-lgo", "-lgcc_s", "-lgcc", "-lc", "-lgcc")
 	case "shared":
 		ldflags = append(ldflags, "-zdefs", "-shared", "-nostdlib", "-lgo", "-lgcc_s", "-lgcc", "-lc")
+	case "pie":
+		ldflags = append(ldflags, "-pie")
 
 	default:
 		fatalf("-buildmode=%s not supported for gccgo", buildmode)
@@ -3100,7 +3110,7 @@ func (tools gccgoToolchain) cc(b *builde
 // maybePIC adds -fPIC to the list of arguments if needed.
 func (tools gccgoToolchain) maybePIC(args []string) []string {
 	switch buildBuildmode {
-	case "c-shared", "shared", "plugin":
+	case "c-archive", "c-shared", "shared", "plugin":
 		args = append(args, "-fPIC")
 	}
 	return args

                 reply	other threads:[~2017-06-29 15:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOyqgcUyXDRh19vJEuerBU-LZty_Zakzf-jD5WamK4ZChGgE8g@mail.gmail.com \
    --to=iant@golang.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gofrontend-dev@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).