]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add Solaris assembler syntax for gccgo buildid file
authorIan Lance Taylor <iant@golang.org>
Tue, 24 Apr 2018 22:09:38 +0000 (15:09 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 8 Jun 2018 22:44:03 +0000 (22:44 +0000)
The Solaris assembler uses a different syntax for section directives.

Fixes https://gcc.gnu.org/PR85429.

Change-Id: I1e54dffee3290046dbb68ba4e90ab795c6b72571
Reviewed-on: https://go-review.googlesource.com/109140
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/internal/work/buildid.go

index f1c538c3093e9c4aafff566fd0c3bb3fde2395aa..04ff01a350a8c3c865c9c725ffa1daca4c97d6b2 100644 (file)
@@ -294,13 +294,32 @@ func (b *Builder) gccgoToolID(name, language string) (string, error) {
        return id, nil
 }
 
+// Check if assembler used by gccgo is GNU as.
+func assemblerIsGas() bool {
+       cmd := exec.Command(BuildToolchain.compiler(), "-print-prog-name=as")
+       assembler, err := cmd.Output()
+       if err == nil {
+               cmd := exec.Command(strings.TrimSpace(string(assembler)), "--version")
+               out, err := cmd.Output()
+               return err == nil && strings.Contains(string(out), "GNU")
+       } else {
+               return false
+       }
+}
+
 // gccgoBuildIDELFFile creates an assembler file that records the
 // action's build ID in an SHF_EXCLUDE section.
 func (b *Builder) gccgoBuildIDELFFile(a *Action) (string, error) {
        sfile := a.Objdir + "_buildid.s"
 
        var buf bytes.Buffer
-       fmt.Fprintf(&buf, "\t"+`.section .go.buildid,"e"`+"\n")
+       if cfg.Goos != "solaris" || assemblerIsGas() {
+               fmt.Fprintf(&buf, "\t"+`.section .go.buildid,"e"`+"\n")
+       } else if cfg.Goarch == "sparc" || cfg.Goarch == "sparc64" {
+               fmt.Fprintf(&buf, "\t"+`.section ".go.buildid",#exclude`+"\n")
+       } else { // cfg.Goarch == "386" || cfg.Goarch == "amd64"
+               fmt.Fprintf(&buf, "\t"+`.section .go.buildid,#exclude`+"\n")
+       }
        fmt.Fprintf(&buf, "\t.byte ")
        for i := 0; i < len(a.buildID); i++ {
                if i > 0 {
@@ -313,8 +332,10 @@ func (b *Builder) gccgoBuildIDELFFile(a *Action) (string, error) {
                fmt.Fprintf(&buf, "%#02x", a.buildID[i])
        }
        fmt.Fprintf(&buf, "\n")
-       fmt.Fprintf(&buf, "\t"+`.section .note.GNU-stack,"",@progbits`+"\n")
-       fmt.Fprintf(&buf, "\t"+`.section .note.GNU-split-stack,"",@progbits`+"\n")
+       if cfg.Goos != "solaris" {
+               fmt.Fprintf(&buf, "\t"+`.section .note.GNU-stack,"",@progbits`+"\n")
+               fmt.Fprintf(&buf, "\t"+`.section .note.GNU-split-stack,"",@progbits`+"\n")
+       }
 
        if cfg.BuildN || cfg.BuildX {
                for _, line := range bytes.Split(buf.Bytes(), []byte("\n")) {