// Test internal linking of PIE binaries where it is supported.
if t.internalLinkPIE() && !disablePIE {
- t.registerTest("internal linking of -buildmode=pie",
+ t.registerTest("internal linking, -buildmode=pie",
&goTest{
variant: "pie_internal",
timeout: 60 * time.Second,
env: []string{"CGO_ENABLED=0"},
pkg: "reflect",
})
+ t.registerTest("internal linking, -buildmode=pie",
+ &goTest{
+ variant: "pie_internal",
+ timeout: 60 * time.Second,
+ buildmode: "pie",
+ ldflags: "-linkmode=internal",
+ env: []string{"CGO_ENABLED=0"},
+ pkg: "crypto/internal/fips/check",
+ })
// Also test a cgo package.
if t.cgoEnabled && t.internalLink() && !disablePIE {
- t.registerTest("internal linking of -buildmode=pie",
+ t.registerTest("internal linking, -buildmode=pie",
&goTest{
variant: "pie_internal",
timeout: 60 * time.Second,
}
}
+ if t.extLink() && !t.compileOnly {
+ t.registerTest("external linking, -buildmode=exe",
+ &goTest{
+ variant: "exe_external",
+ timeout: 60 * time.Second,
+ buildmode: "exe",
+ ldflags: "-linkmode=external",
+ env: []string{"CGO_ENABLED=1"},
+ pkg: "crypto/internal/fips/check",
+ })
+ if t.externalLinkPIE() && !disablePIE {
+ t.registerTest("external linking, -buildmode=pie",
+ &goTest{
+ variant: "pie_external",
+ timeout: 60 * time.Second,
+ buildmode: "pie",
+ ldflags: "-linkmode=external",
+ env: []string{"CGO_ENABLED=1"},
+ pkg: "crypto/internal/fips/check",
+ })
+ }
+ }
+
// sync tests
if t.hasParallelism() {
t.registerTest("sync -cpu=10",
}
// extLink reports whether the current goos/goarch supports
-// external linking. This should match the test in determineLinkMode
-// in cmd/link/internal/ld/config.go.
+// external linking.
func (t *tester) extLink() bool {
+ if !cgoEnabled[goos+"/"+goarch] {
+ return false
+ }
if goarch == "ppc64" && goos != "aix" {
return false
}
return false
}
+func (t *tester) externalLinkPIE() bool {
+ // General rule is if -buildmode=pie and -linkmode=external both work, then they work together.
+ // Handle exceptions and then fall back to the general rule.
+ switch goos + "-" + goarch {
+ case "linux-s390x":
+ return true
+ }
+ return t.internalLinkPIE() && t.extLink()
+}
+
// supportedBuildMode reports whether the given build mode is supported.
func (t *tester) supportedBuildmode(mode string) bool {
switch mode {