Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Add check to see if gcc supports -no-pie. (#607) #655

Merged
merged 1 commit into from
Nov 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
Expand Down Expand Up @@ -278,6 +279,9 @@ func rungcc3(pkg *Package, dir string, ofile string, ofiles []string) error {
args = append(args, "-o", ofile)
args = append(args, ofiles...)
args = append(args, "-Wl,-r", "-nostdlib")
if gccSupportsNoPie(pkg) {
args = append(args, "-no-pie")
}
var cmd []string
if len(pkg.CXXFiles) > 0 || len(pkg.SwigCXXFiles) > 0 {
cmd = gxxCmd(pkg, dir)
Expand Down Expand Up @@ -313,6 +317,20 @@ func libgcc(ctx *Context) (string, error) {
return strings.TrimSpace(buf.String()), err
}

// gccSupportsNoPie check if the -no-pie option is supported. On systems with
// PIE (position independent executables) enabled by default, -no-pie must be
// passed when doing a partial link with -Wl,-r.
func gccSupportsNoPie(pkg *Package) bool {
cmd := gccCmd(pkg, "")
args := []string{
"-no-pie",
"-fsyntax-only",
"-xc",
"-",
}
return exec.Command(cmd[0], append(cmd[1:], args...)...).Run() == nil
}

func cgotool(ctx *Context) string {
return filepath.Join(runtime.GOROOT(), "pkg", "tool", ctx.gohostos+"_"+ctx.gohostarch, "cgo")
}
Expand Down