gollvm: update cmake rules for go 1.17

Updates to cmake rules to bring libgo into sync with Go 1.17
changes in gofrontend.

Change-Id: I90608f08647427af581898f0f27a1e1bd5b079f5
Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/349551
Trust: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/cmake/modules/AutoGenGo.cmake b/cmake/modules/AutoGenGo.cmake
index 3e3ab83..5872d79 100644
--- a/cmake/modules/AutoGenGo.cmake
+++ b/cmake/modules/AutoGenGo.cmake
@@ -24,15 +24,6 @@
   # not currently supported -- the install prefix has to be set properly
   # as part of the original build.
 
-  # Compiler version
-  file(STRINGS "${srcroot}/../VERSION" rawver)
-  string(STRIP ${rawver} ver)
-  # Default GOROOT var initialization.
-  file(APPEND ${outfile} "func init() { DefaultGoroot = \"${CMAKE_INSTALL_PREFIX}\" }\n")
-  file(APPEND ${outfile} "const TheVersion = ")
-  emitversionstring(${outfile} ${srcroot})
-  file(APPEND ${outfile} "\n")
-
   # FIXME:
   # GccgoToolDir is set to the gccgo installation directory that contains
   # (among other things) "go1", "cgo", "cc1", and other auxiliary
@@ -41,6 +32,8 @@
   # 'DefaultGoRoot' above.
   file(APPEND ${outfile} "const GccgoToolDir = \"${CMAKE_INSTALL_PREFIX}/tools\"\n")
 
+  file(APPEND ${outfile} "const StackGuardMultiplierDefault = 1\n")
+
   # FIXME: add a real switch base on configuration params here.
 
   if( ${goarch} STREQUAL "amd64")
@@ -69,7 +62,6 @@
   file(APPEND ${outfile} "const GOARCH = \"${goarch}\"\n")
   file(APPEND ${outfile} "const GOOS = \"${goos}\"\n")
   file(APPEND ${outfile} "\n")
-  file(APPEND ${outfile} "type ArchFamilyType int\n\n")
   file(APPEND ${outfile} "const (\n")
   file(APPEND ${outfile} "\tUNKNOWN ArchFamilyType = iota\n")
 
@@ -88,7 +80,7 @@
   endforeach()
   file(APPEND ${outfile} "\n")
 
-  set(constants "ArchFamily:family" "BigEndian:bigendian" "CacheLineSize:cachelinesize" "PhysPageSize:defaultphyspagesize" "PCQuantum:pcquantum" "Int64Align:int64align" "MinFrameSize:minframesize")
+  set(constants "ArchFamily:family" "BigEndian:bigendian" "DefaultPhysPageSize:defaultphyspagesize" "PCQuantum:pcquantum" "Int64Align:int64align" "MinFrameSize:minframesize" "StackAlign:stackalign")
 
   file(APPEND ${outfile} "const (\n")
   foreach(item ${constants})
@@ -106,7 +98,7 @@
       ERROR_VARIABLE errmsg
       RESULT_VARIABLE exitstatus)
     if(${exitstatus} MATCHES 0)
-      file(APPEND ${outfile} "\t${constname} = ${result}")
+      file(APPEND ${outfile} "\t_${constname} = ${result}")
     else()
       message(FATAL_ERROR "goarch.sh invocation failed: ${errmsg}")
     endif()
@@ -125,7 +117,6 @@
   endforeach()
 
   file(APPEND ${outfile} "\n")
-  file(APPEND ${outfile} "type Uintreg uintptr\n")
 endfunction()
 
 #----------------------------------------------------------------------
@@ -258,6 +249,42 @@
 endfunction()
 
 #----------------------------------------------------------------------
+# Emit 'buildcfg.go', containing default settings for various GO* vars.
+#
+# Unnamed parameters:
+#
+#   * output file to target
+#   * libgo cmake binary directory
+#   * libgo source code root directory
+#
+function(mkbuildcfg outfile binroot srcroot)
+
+  file(REMOVE ${outfile})
+  file(WRITE ${outfile} "package buildcfg\n\n")
+  file(APPEND ${outfile} "import \"runtime\"\n")
+
+  # Compiler version
+  file(STRINGS "${srcroot}/../VERSION" rawver)
+  string(STRIP ${rawver} ver)
+  file(APPEND ${outfile} "const version = ")
+  emitversionstring(${outfile} ${srcroot})
+  file(APPEND ${outfile} "\n")
+
+  file(APPEND ${outfile} "func defaultGOROOTValue() string { return \"${GOLLVM_INSTALL_DIR}\" }\n")
+  file(APPEND ${outfile} "const defaultGO386 = `sse2`\n")
+  file(APPEND ${outfile} "const defaultGOARM = `5`\n")
+  file(APPEND ${outfile} "const defaultGOMIPS = `hardfloat`\n")
+  file(APPEND ${outfile} "const defaultGOMIPS64 = `hardfloat`\n")
+  file(APPEND ${outfile} "const defaultGOOS = runtime.GOOS\n")
+  file(APPEND ${outfile} "const defaultGOPPC64 = `power8`\n")
+  file(APPEND ${outfile} "const defaultGOARCH = runtime.GOARCH\n")
+  file(APPEND ${outfile} "const defaultGO_EXTLINK_ENABLED = ``\n")
+  file(APPEND ${outfile} "const defaultGO_LDSO = ``\n")
+  file(APPEND ${outfile} "const defaultGOEXPERIMENT = `fieldtrack`\n")
+endfunction()
+
+
+#----------------------------------------------------------------------
 # Emit 'objabi.go', containing default settings for various GO* vars.
 #
 # Unnamed parameters:
@@ -270,24 +297,8 @@
 
   file(REMOVE ${outfile})
   file(WRITE ${outfile} "package objabi\n\n")
-  file(APPEND ${outfile} "import \"runtime\"\n")
 
-  file(APPEND ${outfile} "func defaultGOROOTValue() string { return \"${GOLLVM_INSTALL_DIR}\" }\n")
-
-  file(APPEND ${outfile} "const defaultGO386 = `sse2`\n")
-  file(APPEND ${outfile} "const defaultGOARM = `5`\n")
-  file(APPEND ${outfile} "const defaultGOMIPS = `hardfloat`\n")
-  file(APPEND ${outfile} "const defaultGOMIPS64 = `hardfloat`\n")
-  file(APPEND ${outfile} "const defaultGOOS = runtime.GOOS\n")
-  file(APPEND ${outfile} "const defaultGOPPC64 = `power8`\n")
-  file(APPEND ${outfile} "const defaultGOARCH = runtime.GOARCH\n")
-  file(APPEND ${outfile} "const defaultGO_EXTLINK_ENABLED = ``\n")
-  file(APPEND ${outfile} "const defaultGO_LDSO = ``\n")
-  file(APPEND ${outfile} "const version = ")
-  emitversionstring(${outfile} ${srcroot})
-  file(APPEND ${outfile} "\n")
   file(APPEND ${outfile} "const stackGuardMultiplierDefault = 1\n")
-  file(APPEND ${outfile} "const goexperiment = ``\n")
 endfunction()
 
 #----------------------------------------------------------------------
@@ -310,7 +321,6 @@
     endif()
   endforeach()
   file(APPEND ${outfile} "\"unsafe\": true,\n")
-  file(APPEND ${outfile} "\"runtime/cgo\": true,\n")
   file(APPEND ${outfile} "}\n")
 endfunction()
 
diff --git a/libgo/CMakeLists.txt b/libgo/CMakeLists.txt
index 26e32b6..b86b1f8 100644
--- a/libgo/CMakeLists.txt
+++ b/libgo/CMakeLists.txt
@@ -102,6 +102,7 @@
 # that <pkg>_extra_go_files holds the additional sources for <pkg>.
 set(runtime_extra_go_files "runtime_linknames.go" "runtime_sysinfo.go" "sigtab.go")
 set(cmd_internal_objabi_extra_go_files "objabi.go")
+set(internal_buildcfg_extra_go_files "buildcfg.go")
 set(internal_goroot_extra_go_files "zstdpkglist.go")
 set(internal_cpu_extra_go_files "cpugen.go")
 set(golang_org_x_sys_cpu_extra_go_files "gcpugen.go")
@@ -228,6 +229,12 @@
 mkobjabi(${objabitmp} ${libgo_binroot} ${libgo_gosrcroot})
 copy_if_different(${objabitmp} ${objabidotgo})
 
+# Rules for buildcfg.go
+set(buildcfgdotgo "${libgo_binroot}/buildcfg.go")
+set(buildcfgtmp "${libgo_binroot}/buildcfg.go.tmp")
+mkbuildcfg(${buildcfgtmp} ${libgo_binroot} ${libgo_gosrcroot})
+copy_if_different(${buildcfgtmp} ${buildcfgdotgo})
+
 # Rules for zstdpkglist.go
 set(zstdpkglistdotgo "${libgo_binroot}/zstdpkglist.go")
 set(zstdpkglisttmp "${libgo_binroot}/zstdpkglist.go.tmp")