0002-build-bootstrap-set-environment-before-generating-bu.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. From 4d43f7c4dd06e6f62be446996019d4505af54764 Mon Sep 17 00:00:00 2001
  2. From: Christian Stewart <christian@paral.in>
  3. Date: Thu, 14 Apr 2022 13:34:26 -0700
  4. Subject: [PATCH] build: bootstrap: set environment before generating buildcfg
  5. The GOOS and GOARCH environment variables should be unset before calling
  6. mkbuildcfg. This change fixes a build failure when GOARCH=riscv64.
  7. Building Go toolchain1 using go-1.4-bootstrap-20171003.
  8. src/cmd/compile/internal/ssa/rewriteRISCV64.go:4814
  9. invalid operation: y << x (shift count type int64, must be unsigned integer)
  10. There is a build issue with go1.4 with the riscv64 code: however, why is the
  11. riscv64 code being compiled at all?
  12. GOARCH is set when calling mkbuildcfg, so go1.4 is trying to compile riscv64.
  13. [Buildroot]: submitted to upstream:
  14. - https://github.com/golang/go/issues/52583
  15. - https://go-review.googlesource.com/c/go/+/400376
  16. - GitHub-Pull-Request: golang/go#52362
  17. Signed-off-by: Christian Stewart <christian@paral.in>
  18. ---
  19. src/cmd/dist/buildtool.go | 56 ++++++++++++++++++++-------------------
  20. 1 file changed, 29 insertions(+), 27 deletions(-)
  21. diff --git a/src/cmd/dist/buildtool.go b/src/cmd/dist/buildtool.go
  22. index f1f3d50b6f..dabf01cf84 100644
  23. --- a/src/cmd/dist/buildtool.go
  24. +++ b/src/cmd/dist/buildtool.go
  25. @@ -116,9 +116,6 @@ func bootstrapBuildTools() {
  26. }
  27. xprintf("Building Go toolchain1 using %s.\n", goroot_bootstrap)
  28. - mkbuildcfg(pathf("%s/src/internal/buildcfg/zbootstrap.go", goroot))
  29. - mkobjabi(pathf("%s/src/cmd/internal/objabi/zbootstrap.go", goroot))
  30. -
  31. // Use $GOROOT/pkg/bootstrap as the bootstrap workspace root.
  32. // We use a subdirectory of $GOROOT/pkg because that's the
  33. // space within $GOROOT where we store all generated objects.
  34. @@ -130,6 +127,34 @@ func bootstrapBuildTools() {
  35. base := pathf("%s/src/bootstrap", workspace)
  36. xmkdirall(base)
  37. + // Set up environment for invoking Go 1.4 go command.
  38. + // GOROOT points at Go 1.4 GOROOT,
  39. + // GOPATH points at our bootstrap workspace,
  40. + // GOBIN is empty, so that binaries are installed to GOPATH/bin,
  41. + // and GOOS, GOHOSTOS, GOARCH, and GOHOSTOS are empty,
  42. + // so that Go 1.4 builds whatever kind of binary it knows how to build.
  43. + // Restore GOROOT, GOPATH, and GOBIN when done.
  44. + // Don't bother with GOOS, GOHOSTOS, GOARCH, and GOHOSTARCH,
  45. + // because setup will take care of those when bootstrapBuildTools returns.
  46. +
  47. + defer os.Setenv("GOROOT", os.Getenv("GOROOT"))
  48. + os.Setenv("GOROOT", goroot_bootstrap)
  49. +
  50. + defer os.Setenv("GOPATH", os.Getenv("GOPATH"))
  51. + os.Setenv("GOPATH", workspace)
  52. +
  53. + defer os.Setenv("GOBIN", os.Getenv("GOBIN"))
  54. + os.Setenv("GOBIN", "")
  55. +
  56. + os.Setenv("GOOS", "")
  57. + os.Setenv("GOHOSTOS", "")
  58. + os.Setenv("GOARCH", "")
  59. + os.Setenv("GOHOSTARCH", "")
  60. +
  61. + // Create the build config files.
  62. + mkbuildcfg(pathf("%s/src/internal/buildcfg/zbootstrap.go", goroot))
  63. + mkobjabi(pathf("%s/src/cmd/internal/objabi/zbootstrap.go", goroot))
  64. +
  65. // Copy source code into $GOROOT/pkg/bootstrap and rewrite import paths.
  66. writefile("module bootstrap\n", pathf("%s/%s", base, "go.mod"), 0)
  67. for _, dir := range bootstrapDirs {
  68. @@ -176,30 +201,6 @@ func bootstrapBuildTools() {
  69. })
  70. }
  71. - // Set up environment for invoking Go 1.4 go command.
  72. - // GOROOT points at Go 1.4 GOROOT,
  73. - // GOPATH points at our bootstrap workspace,
  74. - // GOBIN is empty, so that binaries are installed to GOPATH/bin,
  75. - // and GOOS, GOHOSTOS, GOARCH, and GOHOSTOS are empty,
  76. - // so that Go 1.4 builds whatever kind of binary it knows how to build.
  77. - // Restore GOROOT, GOPATH, and GOBIN when done.
  78. - // Don't bother with GOOS, GOHOSTOS, GOARCH, and GOHOSTARCH,
  79. - // because setup will take care of those when bootstrapBuildTools returns.
  80. -
  81. - defer os.Setenv("GOROOT", os.Getenv("GOROOT"))
  82. - os.Setenv("GOROOT", goroot_bootstrap)
  83. -
  84. - defer os.Setenv("GOPATH", os.Getenv("GOPATH"))
  85. - os.Setenv("GOPATH", workspace)
  86. -
  87. - defer os.Setenv("GOBIN", os.Getenv("GOBIN"))
  88. - os.Setenv("GOBIN", "")
  89. -
  90. - os.Setenv("GOOS", "")
  91. - os.Setenv("GOHOSTOS", "")
  92. - os.Setenv("GOARCH", "")
  93. - os.Setenv("GOHOSTARCH", "")
  94. -
  95. // Run Go 1.4 to build binaries. Use -gcflags=-l to disable inlining to
  96. // workaround bugs in Go 1.4's compiler. See discussion thread:
  97. // https://groups.google.com/d/msg/golang-dev/Ss7mCKsvk8w/Gsq7VYI0AwAJ
  98. @@ -221,6 +222,7 @@ func bootstrapBuildTools() {
  99. cmd = append(cmd, "-toolexec="+tool)
  100. }
  101. cmd = append(cmd, "bootstrap/cmd/...")
  102. +
  103. run(base, ShowOutput|CheckExit, cmd...)
  104. // Copy binaries into tool binary directory.
  105. --
  106. 2.35.1