aboutsummaryrefslogtreecommitdiff
path: root/tests/core/go_binary/pie_darwin_test.go
blob: 2f45b87881e717b231903b6672d679668e296c53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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.")
	}
}