Unverified Commit 41228b71 authored by Martin Weinelt's avatar Martin Weinelt Committed by GitHub
Browse files

go: revert default PIE changes (#461615)

parents 38ab204b ce37d840
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -253,9 +253,6 @@ lib.extendMkDerivation {
            if [ -f "$NIX_CC_FOR_TARGET/nix-support/dynamic-linker" ]; then
              export GO_LDSO=$(cat $NIX_CC_FOR_TARGET/nix-support/dynamic-linker)
            fi
            if [ "$CGO_ENABLED" = "0" ]; then
              export GOFLAGS="-buildmode=exe $GOFLAGS"
            fi
            cd "$modRoot"
          ''
          + lib.optionalString (finalAttrs.vendorHash != null) ''
+0 −29
Original line number Diff line number Diff line
@@ -21,30 +21,6 @@ let
  targetCC = pkgsBuildTarget.targetPackages.stdenv.cc;

  isCross = stdenv.buildPlatform != stdenv.targetPlatform;

  # In order for buildmode=pie to work either Go's internal linker must know how
  # to produce position-independent executables or Go must be using an external linker.
  #
  # go-default-pie.patch tries to enable position-independent codegen (PIE) only when the platform
  # reports support (via BuildModeSupported(..., "pie", ...)).
  #
  # That probe is not fully reliable: for example, `pkgsi686Linux.go` can fail during bootstrap
  # with message 'default PIE binary requires external (cgo) linking, but cgo is not enabled'
  # despite CGO being enabled. (we set `CGO_ENABLED=1`).
  #
  # To avoid such breakage, limit this patch to a small set of explicitly tested platforms
  # rather than relying on the general BuildModeSupported("pie") check.
  supportsDefaultPie =
    let
      hasPie = {
        "amd64" = true;
        "arm64" = true;
        "ppc64le" = true;
        "riscv64" = true;
      };
    in
    hasPie.${stdenv.hostPlatform.go.GOARCH} or false
    && hasPie.${stdenv.targetPlatform.go.GOARCH} or false;
in
stdenv.mkDerivation (finalAttrs: {
  pname = "go";
@@ -86,11 +62,6 @@ stdenv.mkDerivation (finalAttrs: {
    ./remove-tools-1.11.patch
    ./go_no_vendor_checks-1.23.patch
    ./go-env-go_ldso.patch
  ]
  ++ lib.optionals supportsDefaultPie [
    (replaceVars ./go-default-pie.patch {
      inherit (stdenv.targetPlatform.go) GOARCH;
    })
  ];

  inherit (stdenv.targetPlatform.go) GOOS GOARCH GOARM;
+0 −29
Original line number Diff line number Diff line
@@ -22,30 +22,6 @@ let
  targetCC = pkgsBuildTarget.targetPackages.stdenv.cc;

  isCross = stdenv.buildPlatform != stdenv.targetPlatform;

  # go-default-pie.patch tries to enable position-independent codegen (PIE) only when the platform
  # reports support (via BuildModeSupported(..., "pie", ...)).
  #
  # In order for buildmode=pie to work either Go's internal linker must know how
  # to produce position-independent executables or Go must be using an external linker.
  #
  # That probe is not fully reliable: for example, `pkgsi686Linux.go` can fail during bootstrap
  # with message 'default PIE binary requires external (cgo) linking, but cgo is not enabled'
  # despite CGO being enabled. (we set `CGO_ENABLED=1`).
  #
  # To avoid such breakage, limit this patch to a small set of explicitly tested platforms
  # rather than relying on the general BuildModeSupported("pie") check.
  supportsDefaultPie =
    let
      hasPie = {
        "amd64" = true;
        "arm64" = true;
        "ppc64le" = true;
        "riscv64" = true;
      };
    in
    hasPie.${stdenv.hostPlatform.go.GOARCH} or false
    && hasPie.${stdenv.targetPlatform.go.GOARCH} or false;
in
stdenv.mkDerivation (finalAttrs: {
  pname = "go";
@@ -87,11 +63,6 @@ stdenv.mkDerivation (finalAttrs: {
    ./remove-tools-1.11.patch
    ./go_no_vendor_checks-1.23.patch
    ./go-env-go_ldso.patch
  ]
  ++ lib.optionals supportsDefaultPie [
    (replaceVars ./go-default-pie.patch {
      inherit (stdenv.targetPlatform.go) GOARCH;
    })
  ];

  inherit (stdenv.targetPlatform.go) GOOS GOARCH GOARM;
+0 −13
Original line number Diff line number Diff line
diff --git a/src/internal/platform/supported.go b/src/internal/platform/supported.go
index f9706a6988..abac42d550 100644
--- a/src/internal/platform/supported.go
+++ b/src/internal/platform/supported.go
@@ -249,7 +253,7 @@ func DefaultPIE(goos, goarch string, isRace bool) bool {
 	case "darwin":
 		return true
 	}
-	return false
+	return goarch == "@GOARCH@" && BuildModeSupported("gc", "pie", goos, goarch)
 }
 
 // ExecutableHasDWARF reports whether the linked executable includes DWARF