aboutsummaryrefslogtreecommitdiff
path: root/tests/core/go_binary/pie_darwin_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/core/go_binary/pie_darwin_test.go')
-rw-r--r--tests/core/go_binary/pie_darwin_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/core/go_binary/pie_darwin_test.go b/tests/core/go_binary/pie_darwin_test.go
new file mode 100644
index 00000000..2f45b878
--- /dev/null
+++ b/tests/core/go_binary/pie_darwin_test.go
@@ -0,0 +1,35 @@
+package test
+
+import (
+ "debug/macho"
+ "fmt"
+ "os"
+ "testing"
+
+ "github.com/bazelbuild/rules_go/go/tools/bazel"
+)
+
+func openMachO(dir, bin string) (*macho.File, error) {
+ bin, ok := bazel.FindBinary(dir, bin)
+ if !ok {
+ return nil, fmt.Errorf("could not find binary: %s", bin)
+ }
+
+ f, err := os.Open(bin)
+ if err != nil {
+ return nil, err
+ }
+
+ return macho.NewFile(f)
+}
+
+func TestPIE(t *testing.T) {
+ m, err := openMachO("tests/core/go_binary", "hello_pie_bin")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if m.Flags&macho.FlagPIE == 0 {
+ t.Error("ELF binary is not position-independent.")
+ }
+}