@@ -642,8 +642,12 @@ func TestTrampoline(t *testing.T) {
642
642
// For stress test, we set -debugtramp=2 flag, which sets a very low
643
643
// threshold for trampoline generation, and essentially all cross-package
644
644
// calls will use trampolines.
645
+ buildmodes := []string {"default" }
645
646
switch runtime .GOARCH {
646
- case "arm" , "arm64" , "ppc64" , "ppc64le" :
647
+ case "arm" , "arm64" , "ppc64" :
648
+ case "ppc64le" :
649
+ // Trampolines are generated differently when internal linking PIE, test them too.
650
+ buildmodes = append (buildmodes , "pie" )
647
651
default :
648
652
t .Skipf ("trampoline insertion is not implemented on %s" , runtime .GOARCH )
649
653
}
@@ -661,18 +665,20 @@ func TestTrampoline(t *testing.T) {
661
665
}
662
666
exe := filepath .Join (tmpdir , "hello.exe" )
663
667
664
- cmd := exec .Command (testenv .GoToolPath (t ), "build" , "-ldflags=-debugtramp=2" , "-o" , exe , src )
665
- out , err := cmd .CombinedOutput ()
666
- if err != nil {
667
- t .Fatalf ("build failed: %v\n %s" , err , out )
668
- }
669
- cmd = exec .Command (exe )
670
- out , err = cmd .CombinedOutput ()
671
- if err != nil {
672
- t .Errorf ("executable failed to run: %v\n %s" , err , out )
673
- }
674
- if string (out ) != "hello\n " {
675
- t .Errorf ("unexpected output:\n %s" , out )
668
+ for _ , mode := range buildmodes {
669
+ cmd := exec .Command (testenv .GoToolPath (t ), "build" , "-buildmode=" + mode , "-ldflags=-debugtramp=2" , "-o" , exe , src )
670
+ out , err := cmd .CombinedOutput ()
671
+ if err != nil {
672
+ t .Fatalf ("build (%s) failed: %v\n %s" , mode , err , out )
673
+ }
674
+ cmd = exec .Command (exe )
675
+ out , err = cmd .CombinedOutput ()
676
+ if err != nil {
677
+ t .Errorf ("executable failed to run (%s): %v\n %s" , mode , err , out )
678
+ }
679
+ if string (out ) != "hello\n " {
680
+ t .Errorf ("unexpected output (%s):\n %s" , mode , out )
681
+ }
676
682
}
677
683
}
678
684
@@ -693,8 +699,12 @@ func TestTrampolineCgo(t *testing.T) {
693
699
// For stress test, we set -debugtramp=2 flag, which sets a very low
694
700
// threshold for trampoline generation, and essentially all cross-package
695
701
// calls will use trampolines.
702
+ buildmodes := []string {"default" }
696
703
switch runtime .GOARCH {
697
- case "arm" , "arm64" , "ppc64" , "ppc64le" :
704
+ case "arm" , "arm64" , "ppc64" :
705
+ case "ppc64le" :
706
+ // Trampolines are generated differently when internal linking PIE, test them too.
707
+ buildmodes = append (buildmodes , "pie" )
698
708
default :
699
709
t .Skipf ("trampoline insertion is not implemented on %s" , runtime .GOARCH )
700
710
}
@@ -713,37 +723,39 @@ func TestTrampolineCgo(t *testing.T) {
713
723
}
714
724
exe := filepath .Join (tmpdir , "hello.exe" )
715
725
716
- cmd := exec .Command (testenv .GoToolPath (t ), "build" , "-ldflags=-debugtramp=2" , "-o" , exe , src )
717
- out , err := cmd .CombinedOutput ()
718
- if err != nil {
719
- t .Fatalf ("build failed: %v\n %s" , err , out )
720
- }
721
- cmd = exec .Command (exe )
722
- out , err = cmd .CombinedOutput ()
723
- if err != nil {
724
- t .Errorf ("executable failed to run: %v\n %s" , err , out )
725
- }
726
- if string (out ) != "hello\n " && string (out ) != "hello\r \n " {
727
- t .Errorf ("unexpected output:\n %s" , out )
728
- }
726
+ for _ , mode := range buildmodes {
727
+ cmd := exec .Command (testenv .GoToolPath (t ), "build" , "-buildmode=" + mode , "-ldflags=-debugtramp=2" , "-o" , exe , src )
728
+ out , err := cmd .CombinedOutput ()
729
+ if err != nil {
730
+ t .Fatalf ("build (%s) failed: %v\n %s" , mode , err , out )
731
+ }
732
+ cmd = exec .Command (exe )
733
+ out , err = cmd .CombinedOutput ()
734
+ if err != nil {
735
+ t .Errorf ("executable failed to run (%s): %v\n %s" , mode , err , out )
736
+ }
737
+ if string (out ) != "hello\n " && string (out ) != "hello\r \n " {
738
+ t .Errorf ("unexpected output (%s):\n %s" , mode , out )
739
+ }
729
740
730
- // Test internal linking mode.
741
+ // Test internal linking mode.
731
742
732
- if runtime .GOARCH == "ppc64" || runtime .GOARCH == "ppc64le" || (runtime .GOARCH == "arm64" && runtime .GOOS == "windows" ) || ! testenv .CanInternalLink () {
733
- return // internal linking cgo is not supported
734
- }
735
- cmd = exec .Command (testenv .GoToolPath (t ), "build" , "-ldflags=-debugtramp=2 -linkmode=internal" , "-o" , exe , src )
736
- out , err = cmd .CombinedOutput ()
737
- if err != nil {
738
- t .Fatalf ("build failed: %v\n %s" , err , out )
739
- }
740
- cmd = exec .Command (exe )
741
- out , err = cmd .CombinedOutput ()
742
- if err != nil {
743
- t .Errorf ("executable failed to run: %v\n %s" , err , out )
744
- }
745
- if string (out ) != "hello\n " && string (out ) != "hello\r \n " {
746
- t .Errorf ("unexpected output:\n %s" , out )
743
+ if runtime .GOARCH == "ppc64" || (runtime .GOARCH == "arm64" && runtime .GOOS == "windows" ) || ! testenv .CanInternalLink () {
744
+ return // internal linking cgo is not supported
745
+ }
746
+ cmd = exec .Command (testenv .GoToolPath (t ), "build" , "-buildmode=" + mode , "-ldflags=-debugtramp=2 -linkmode=internal" , "-o" , exe , src )
747
+ out , err = cmd .CombinedOutput ()
748
+ if err != nil {
749
+ t .Fatalf ("build (%s) failed: %v\n %s" , mode , err , out )
750
+ }
751
+ cmd = exec .Command (exe )
752
+ out , err = cmd .CombinedOutput ()
753
+ if err != nil {
754
+ t .Errorf ("executable failed to run (%s): %v\n %s" , mode , err , out )
755
+ }
756
+ if string (out ) != "hello\n " && string (out ) != "hello\r \n " {
757
+ t .Errorf ("unexpected output (%s):\n %s" , mode , out )
758
+ }
747
759
}
748
760
}
749
761
0 commit comments