2016-11-27 17:05:01 -07:00
|
|
|
// Copyright 2017 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package cshared_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"debug/elf"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2017-08-19 04:17:46 -06:00
|
|
|
"sync"
|
2016-11-27 17:05:01 -07:00
|
|
|
"testing"
|
|
|
|
"unicode"
|
|
|
|
)
|
|
|
|
|
|
|
|
// C compiler with args (from $(go env CC) $(go env GOGCCFLAGS)).
|
|
|
|
var cc []string
|
|
|
|
|
|
|
|
// An environment with GOPATH=$(pwd).
|
|
|
|
var gopathEnv []string
|
|
|
|
|
|
|
|
// ".exe" on Windows.
|
|
|
|
var exeSuffix string
|
|
|
|
|
|
|
|
var GOOS, GOARCH, GOROOT string
|
2017-08-19 05:11:09 -06:00
|
|
|
var installdir, androiddir string
|
2016-11-27 17:05:01 -07:00
|
|
|
var libSuffix, libgoname string
|
|
|
|
|
2017-08-19 04:17:46 -06:00
|
|
|
func TestMain(m *testing.M) {
|
2016-11-27 17:05:01 -07:00
|
|
|
GOOS = goEnv("GOOS")
|
|
|
|
GOARCH = goEnv("GOARCH")
|
|
|
|
GOROOT = goEnv("GOROOT")
|
|
|
|
|
|
|
|
if _, err := os.Stat(GOROOT); os.IsNotExist(err) {
|
|
|
|
log.Fatalf("Unable able to find GOROOT at '%s'", GOROOT)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Directory where cgo headers and outputs will be installed.
|
|
|
|
// The installation directory format varies depending on the platform.
|
|
|
|
installdir = path.Join("pkg", fmt.Sprintf("%s_%s_testcshared_shared", GOOS, GOARCH))
|
|
|
|
switch GOOS {
|
|
|
|
case "darwin":
|
|
|
|
libSuffix = "dylib"
|
|
|
|
installdir = path.Join("pkg", fmt.Sprintf("%s_%s_testcshared", GOOS, GOARCH))
|
|
|
|
case "windows":
|
|
|
|
libSuffix = "dll"
|
|
|
|
default:
|
|
|
|
libSuffix = "so"
|
|
|
|
}
|
|
|
|
|
|
|
|
androiddir = fmt.Sprintf("/data/local/tmp/testcshared-%d", os.Getpid())
|
2017-09-09 23:26:19 -06:00
|
|
|
if GOOS == "android" {
|
|
|
|
cmd := exec.Command("adb", "shell", "mkdir", "-p", androiddir)
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("setupAndroid failed: %v\n%s\n", err, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 17:05:01 -07:00
|
|
|
libgoname = "libgo." + libSuffix
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
cc = []string{goEnv("CC")}
|
2016-11-27 17:05:01 -07:00
|
|
|
|
|
|
|
out := goEnv("GOGCCFLAGS")
|
|
|
|
quote := '\000'
|
|
|
|
start := 0
|
|
|
|
lastSpace := true
|
|
|
|
backslash := false
|
|
|
|
s := string(out)
|
|
|
|
for i, c := range s {
|
|
|
|
if quote == '\000' && unicode.IsSpace(c) {
|
|
|
|
if !lastSpace {
|
|
|
|
cc = append(cc, s[start:i])
|
|
|
|
lastSpace = true
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if lastSpace {
|
|
|
|
start = i
|
|
|
|
lastSpace = false
|
|
|
|
}
|
|
|
|
if quote == '\000' && !backslash && (c == '"' || c == '\'') {
|
|
|
|
quote = c
|
|
|
|
backslash = false
|
|
|
|
} else if !backslash && quote == c {
|
|
|
|
quote = '\000'
|
|
|
|
} else if (quote == '\000' || quote == '"') && !backslash && c == '\\' {
|
|
|
|
backslash = true
|
|
|
|
} else {
|
|
|
|
backslash = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !lastSpace {
|
|
|
|
cc = append(cc, s[start:])
|
|
|
|
}
|
|
|
|
|
2017-08-19 05:11:09 -06:00
|
|
|
switch GOOS {
|
|
|
|
case "darwin":
|
2016-11-27 17:05:01 -07:00
|
|
|
// For Darwin/ARM.
|
|
|
|
// TODO(crawshaw): can we do better?
|
|
|
|
cc = append(cc, []string{"-framework", "CoreFoundation", "-framework", "Foundation"}...)
|
2017-08-19 05:11:09 -06:00
|
|
|
case "android":
|
|
|
|
cc = append(cc, "-pie", "-fuse-ld=gold")
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
libgodir := GOOS + "_" + GOARCH
|
|
|
|
switch GOOS {
|
|
|
|
case "darwin":
|
|
|
|
if GOARCH == "arm" || GOARCH == "arm64" {
|
|
|
|
libgodir += "_shared"
|
|
|
|
}
|
|
|
|
case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
|
|
|
|
libgodir += "_shared"
|
|
|
|
}
|
|
|
|
cc = append(cc, "-I", filepath.Join("pkg", libgodir))
|
|
|
|
|
|
|
|
// Build an environment with GOPATH=$(pwd)
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
gopathEnv = append(os.Environ(), "GOPATH="+dir)
|
|
|
|
|
|
|
|
if GOOS == "windows" {
|
|
|
|
exeSuffix = ".exe"
|
|
|
|
}
|
2017-08-19 04:17:46 -06:00
|
|
|
|
|
|
|
st := m.Run()
|
|
|
|
|
|
|
|
os.Remove(libgoname)
|
|
|
|
os.RemoveAll("pkg")
|
|
|
|
cleanupHeaders()
|
|
|
|
cleanupAndroid()
|
|
|
|
|
|
|
|
os.Exit(st)
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func goEnv(key string) string {
|
|
|
|
out, err := exec.Command("go", "env", key).Output()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "go env %s failed:\n%s", key, err)
|
|
|
|
fmt.Fprintf(os.Stderr, "%s", err.(*exec.ExitError).Stderr)
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(string(out))
|
|
|
|
}
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
func cmdToRun(name string) string {
|
|
|
|
return "./" + name + exeSuffix
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func adbPush(t *testing.T, filename string) {
|
|
|
|
if GOOS != "android" {
|
|
|
|
return
|
|
|
|
}
|
2017-08-17 22:55:05 -06:00
|
|
|
args := []string{"adb", "push", filename, fmt.Sprintf("%s/%s", androiddir, filename)}
|
2016-11-27 17:05:01 -07:00
|
|
|
cmd := exec.Command(args[0], args[1:]...)
|
|
|
|
if out, err := cmd.CombinedOutput(); err != nil {
|
|
|
|
t.Fatalf("adb command failed: %v\n%s\n", err, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-19 05:11:09 -06:00
|
|
|
func adbRun(t *testing.T, env []string, adbargs ...string) string {
|
2016-11-27 17:05:01 -07:00
|
|
|
if GOOS != "android" {
|
|
|
|
t.Fatalf("trying to run adb command when operating system is not android.")
|
|
|
|
}
|
2017-08-17 22:55:05 -06:00
|
|
|
args := []string{"adb", "shell"}
|
2017-08-19 05:11:09 -06:00
|
|
|
// Propagate LD_LIBRARY_PATH to the adb shell invocation.
|
|
|
|
for _, e := range env {
|
|
|
|
if strings.Index(e, "LD_LIBRARY_PATH=") != -1 {
|
|
|
|
adbargs = append([]string{e}, adbargs...)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2017-08-18 00:34:44 -06:00
|
|
|
shellcmd := fmt.Sprintf("cd %s; %s", androiddir, strings.Join(adbargs, " "))
|
|
|
|
args = append(args, shellcmd)
|
2016-11-27 17:05:01 -07:00
|
|
|
cmd := exec.Command(args[0], args[1:]...)
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("adb command failed: %v\n%s\n", err, out)
|
|
|
|
}
|
|
|
|
return strings.Replace(string(out), "\r", "", -1)
|
|
|
|
}
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
func run(t *testing.T, env []string, args ...string) string {
|
2016-11-27 17:05:01 -07:00
|
|
|
cmd := exec.Command(args[0], args[1:]...)
|
|
|
|
cmd.Env = env
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("command failed: %v\n%v\n%s\n", args, err, out)
|
|
|
|
} else {
|
|
|
|
t.Logf("run: %v", args)
|
|
|
|
}
|
|
|
|
return string(out)
|
|
|
|
}
|
|
|
|
|
2017-08-19 05:11:09 -06:00
|
|
|
func runExe(t *testing.T, env []string, args ...string) string {
|
|
|
|
if GOOS == "android" {
|
|
|
|
return adbRun(t, env, args...)
|
|
|
|
}
|
2017-09-10 19:58:17 -06:00
|
|
|
return run(t, env, args...)
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
func runCC(t *testing.T, args ...string) string {
|
|
|
|
return run(t, nil, append(cc, args...)...)
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
|
2017-08-19 04:17:46 -06:00
|
|
|
func createHeaders() error {
|
|
|
|
args := []string{"go", "install", "-buildmode=c-shared",
|
|
|
|
"-installsuffix", "testcshared", "libgo"}
|
|
|
|
cmd := exec.Command(args[0], args[1:]...)
|
|
|
|
cmd.Env = gopathEnv
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("command failed: %v\n%v\n%s\n", args, err, out)
|
|
|
|
}
|
2016-11-27 17:05:01 -07:00
|
|
|
|
2017-08-19 04:17:46 -06:00
|
|
|
args = []string{"go", "build", "-buildmode=c-shared",
|
|
|
|
"-installsuffix", "testcshared",
|
|
|
|
"-o", libgoname,
|
|
|
|
filepath.Join("src", "libgo", "libgo.go")}
|
|
|
|
cmd = exec.Command(args[0], args[1:]...)
|
|
|
|
cmd.Env = gopathEnv
|
|
|
|
out, err = cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("command failed: %v\n%v\n%s\n", args, err, out)
|
|
|
|
}
|
2016-11-27 17:05:01 -07:00
|
|
|
|
2017-08-19 04:17:46 -06:00
|
|
|
if GOOS == "android" {
|
|
|
|
args = []string{"adb", "push", libgoname, fmt.Sprintf("%s/%s", androiddir, libgoname)}
|
|
|
|
cmd = exec.Command(args[0], args[1:]...)
|
|
|
|
out, err = cmd.CombinedOutput()
|
2016-11-27 17:05:01 -07:00
|
|
|
if err != nil {
|
2017-08-19 04:17:46 -06:00
|
|
|
return fmt.Errorf("adb command failed: %v\n%s\n", err, out)
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
}
|
2017-08-19 04:17:46 -06:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
headersOnce sync.Once
|
|
|
|
headersErr error
|
|
|
|
)
|
|
|
|
|
|
|
|
func createHeadersOnce(t *testing.T) {
|
|
|
|
headersOnce.Do(func() {
|
|
|
|
headersErr = createHeaders()
|
|
|
|
})
|
|
|
|
if headersErr != nil {
|
|
|
|
t.Fatal(headersErr)
|
|
|
|
}
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func cleanupHeaders() {
|
|
|
|
os.Remove("libgo.h")
|
|
|
|
}
|
|
|
|
|
2017-08-19 04:17:46 -06:00
|
|
|
func cleanupAndroid() {
|
2016-11-27 17:05:01 -07:00
|
|
|
if GOOS != "android" {
|
|
|
|
return
|
|
|
|
}
|
2017-08-19 04:17:46 -06:00
|
|
|
cmd := exec.Command("adb", "shell", "rm", "-rf", androiddir)
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("cleanupAndroid failed: %v\n%s\n", err, out)
|
|
|
|
}
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// test0: exported symbols in shared lib are accessible.
|
|
|
|
func TestExportedSymbols(t *testing.T) {
|
2017-09-09 23:26:19 -06:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cmd := "testp0"
|
2016-11-27 17:05:01 -07:00
|
|
|
|
2017-08-19 04:17:46 -06:00
|
|
|
createHeadersOnce(t)
|
2016-11-27 17:05:01 -07:00
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
runCC(t, "-I", installdir, "-o", cmd, "main0.c", libgoname)
|
2016-11-27 17:05:01 -07:00
|
|
|
adbPush(t, cmd)
|
|
|
|
|
2017-09-09 23:26:19 -06:00
|
|
|
defer os.Remove(cmd)
|
2016-11-27 17:05:01 -07:00
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
out := run(t, append(gopathEnv, "LD_LIBRARY_PATH=."), cmdToRun(cmd))
|
2016-11-27 17:05:01 -07:00
|
|
|
if strings.TrimSpace(out) != "PASS" {
|
|
|
|
t.Error(out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// test1: shared library can be dynamically loaded and exported symbols are accessible.
|
|
|
|
func TestExportedSymbolsWithDynamicLoad(t *testing.T) {
|
2017-09-09 23:26:19 -06:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cmd := "testp1"
|
2016-11-27 17:05:01 -07:00
|
|
|
|
2017-08-19 04:17:46 -06:00
|
|
|
createHeadersOnce(t)
|
2016-11-27 17:05:01 -07:00
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
runCC(t, "-o", cmd, "main1.c", "-ldl")
|
2016-11-27 17:05:01 -07:00
|
|
|
adbPush(t, cmd)
|
|
|
|
|
|
|
|
defer os.Remove(cmd)
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
out := runExe(t, nil, cmdToRun(cmd), "./"+libgoname)
|
2016-11-27 17:05:01 -07:00
|
|
|
if strings.TrimSpace(out) != "PASS" {
|
|
|
|
t.Error(out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// test2: tests libgo2 which does not export any functions.
|
|
|
|
func TestUnexportedSymbols(t *testing.T) {
|
2017-09-09 23:26:19 -06:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-11-27 17:05:01 -07:00
|
|
|
cmd := "testp2"
|
|
|
|
libname := "libgo2." + libSuffix
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
run(t,
|
|
|
|
gopathEnv,
|
2016-11-27 17:05:01 -07:00
|
|
|
"go", "build",
|
|
|
|
"-buildmode=c-shared",
|
|
|
|
"-installsuffix", "testcshared",
|
|
|
|
"-o", libname, "libgo2",
|
|
|
|
)
|
|
|
|
adbPush(t, libname)
|
|
|
|
|
|
|
|
linkFlags := "-Wl,--no-as-needed"
|
|
|
|
if GOOS == "darwin" {
|
|
|
|
linkFlags = ""
|
|
|
|
}
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
runCC(t, "-o", cmd, "main2.c", linkFlags, libname)
|
2016-11-27 17:05:01 -07:00
|
|
|
adbPush(t, cmd)
|
|
|
|
|
|
|
|
defer os.Remove(libname)
|
|
|
|
defer os.Remove(cmd)
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
out := run(t, append(gopathEnv, "LD_LIBRARY_PATH=."), cmdToRun(cmd))
|
2016-11-27 17:05:01 -07:00
|
|
|
|
|
|
|
if strings.TrimSpace(out) != "PASS" {
|
|
|
|
t.Error(out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// test3: tests main.main is exported on android.
|
|
|
|
func TestMainExportedOnAndroid(t *testing.T) {
|
2017-09-09 23:26:19 -06:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-11-27 17:05:01 -07:00
|
|
|
if GOOS != "android" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := "testp3"
|
|
|
|
|
2017-08-19 04:17:46 -06:00
|
|
|
createHeadersOnce(t)
|
2016-11-27 17:05:01 -07:00
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
runCC(t, "-o", cmd, "main3.c", "-ldl")
|
2016-11-27 17:05:01 -07:00
|
|
|
adbPush(t, cmd)
|
|
|
|
|
|
|
|
defer os.Remove(cmd)
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
out := runExe(t, nil, cmdToRun(cmd), "./"+libgoname)
|
2016-11-27 17:05:01 -07:00
|
|
|
if strings.TrimSpace(out) != "PASS" {
|
|
|
|
t.Error(out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
func testSignalHandlers(t *testing.T, pkgname, cfile, cmd string) {
|
|
|
|
libname := pkgname + "." + libSuffix
|
|
|
|
run(t,
|
|
|
|
gopathEnv,
|
2016-11-27 17:05:01 -07:00
|
|
|
"go", "build",
|
|
|
|
"-buildmode=c-shared",
|
|
|
|
"-installsuffix", "testcshared",
|
2017-09-10 19:58:17 -06:00
|
|
|
"-o", libname, pkgname,
|
2016-11-27 17:05:01 -07:00
|
|
|
)
|
|
|
|
adbPush(t, libname)
|
2017-09-10 19:58:17 -06:00
|
|
|
runCC(t, "-pthread", "-o", cmd, cfile, "-ldl")
|
2016-11-27 17:05:01 -07:00
|
|
|
adbPush(t, cmd)
|
|
|
|
|
|
|
|
defer os.Remove(libname)
|
|
|
|
defer os.Remove(cmd)
|
2017-09-10 19:58:17 -06:00
|
|
|
defer os.Remove(pkgname + ".h")
|
2016-11-27 17:05:01 -07:00
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
bin := cmdToRun(cmd)
|
|
|
|
out := runExe(t, nil, bin, "./"+libname)
|
2016-11-27 17:05:01 -07:00
|
|
|
if strings.TrimSpace(out) != "PASS" {
|
2017-09-10 19:58:17 -06:00
|
|
|
t.Error(run(t, nil, bin, libname, "verbose"))
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-10 19:58:17 -06:00
|
|
|
// test4: test signal handlers
|
|
|
|
func TestSignalHandlers(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
testSignalHandlers(t, "libgo4", "main4.c", "testp4")
|
|
|
|
}
|
|
|
|
|
2016-11-27 17:05:01 -07:00
|
|
|
// test5: test signal handlers with os/signal.Notify
|
|
|
|
func TestSignalHandlersWithNotify(t *testing.T) {
|
2017-09-09 23:26:19 -06:00
|
|
|
t.Parallel()
|
2017-09-10 19:58:17 -06:00
|
|
|
testSignalHandlers(t, "libgo5", "main5.c", "testp5")
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPIE(t *testing.T) {
|
2017-09-09 23:26:19 -06:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-11-27 17:05:01 -07:00
|
|
|
switch GOOS {
|
|
|
|
case "linux", "android":
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
t.Logf("Skipping TestPIE on %s", GOOS)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-19 04:17:46 -06:00
|
|
|
createHeadersOnce(t)
|
2016-11-27 17:05:01 -07:00
|
|
|
|
|
|
|
f, err := elf.Open(libgoname)
|
|
|
|
if err != nil {
|
2017-08-19 04:17:46 -06:00
|
|
|
t.Fatalf("elf.Open failed: %v", err)
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
ds := f.SectionByType(elf.SHT_DYNAMIC)
|
|
|
|
if ds == nil {
|
2017-08-19 04:17:46 -06:00
|
|
|
t.Fatalf("no SHT_DYNAMIC section")
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
d, err := ds.Data()
|
|
|
|
if err != nil {
|
2017-08-19 04:17:46 -06:00
|
|
|
t.Fatalf("can't read SHT_DYNAMIC contents: %v", err)
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
for len(d) > 0 {
|
2017-08-19 04:17:46 -06:00
|
|
|
var tag elf.DynTag
|
2016-11-27 17:05:01 -07:00
|
|
|
switch f.Class {
|
|
|
|
case elf.ELFCLASS32:
|
2017-08-19 04:17:46 -06:00
|
|
|
tag = elf.DynTag(f.ByteOrder.Uint32(d[:4]))
|
2016-11-27 17:05:01 -07:00
|
|
|
d = d[8:]
|
|
|
|
case elf.ELFCLASS64:
|
2017-08-19 04:17:46 -06:00
|
|
|
tag = elf.DynTag(f.ByteOrder.Uint64(d[:8]))
|
2016-11-27 17:05:01 -07:00
|
|
|
d = d[16:]
|
|
|
|
}
|
2017-08-19 04:17:46 -06:00
|
|
|
if tag == elf.DT_TEXTREL {
|
|
|
|
t.Fatalf("%s has DT_TEXTREL flag", libgoname)
|
2016-11-27 17:05:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|