From 2259abb89f7b96fa51482e75b7572a9ecd5f8592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 26 Aug 2024 23:51:28 +0100 Subject: [PATCH] rewrite generation of go_std_tables.go from Bash to Go This makes it portable and easier to maintain for any Go developers. I also want to improve its logic, which would have been harder in shell. --- go_std_tables.go | 40 ++++---- scripts/gen-go-std-tables.sh | 63 ------------ scripts/gen_go_std_tables.go | 182 +++++++++++++++++++++++++++++++++++ shared.go | 2 +- 4 files changed, 203 insertions(+), 84 deletions(-) delete mode 100755 scripts/gen-go-std-tables.sh create mode 100644 scripts/gen_go_std_tables.go diff --git a/go_std_tables.go b/go_std_tables.go index 01e22df..d5cabbc 100644 --- a/go_std_tables.go +++ b/go_std_tables.go @@ -1,25 +1,25 @@ -// Code generated by scripts/gen-go-std-tables.sh; DO NOT EDIT. +// Code generated by scripts/gen_go_std_tables.go; DO NOT EDIT. // Generated from Go version go1.22.0. package main var runtimeAndDeps = map[string]bool{ - "internal/goarch": true, - "unsafe": true, "internal/abi": true, - "internal/cpu": true, "internal/bytealg": true, "internal/chacha8rand": true, "internal/coverage/rtcov": true, + "internal/cpu": true, + "internal/goarch": true, "internal/godebugs": true, "internal/goexperiment": true, "internal/goos": true, + "runtime": true, "runtime/internal/atomic": true, "runtime/internal/math": true, "runtime/internal/sys": true, "runtime/internal/syscall": true, - "runtime": true, + "unsafe": true, } var runtimeLinknamed = []string{ @@ -67,6 +67,14 @@ var compilerIntrinsicsPkgs = map[string]bool{ var compilerIntrinsicsFuncs = map[string]bool{ "math.Abs": true, + "math.Ceil": true, + "math.Copysign": true, + "math.FMA": true, + "math.Floor": true, + "math.Round": true, + "math.RoundToEven": true, + "math.Trunc": true, + "math.sqrt": true, "math/big.mulWW": true, "math/bits.Add": true, "math/bits.Add64": true, @@ -103,22 +111,15 @@ var compilerIntrinsicsFuncs = map[string]bool{ "math/bits.TrailingZeros32": true, "math/bits.TrailingZeros64": true, "math/bits.TrailingZeros8": true, - "math.Ceil": true, - "math.Copysign": true, - "math.Floor": true, - "math.FMA": true, - "math.Round": true, - "math.RoundToEven": true, - "math.sqrt": true, - "math.Trunc": true, + "runtime.publicationBarrier": true, "runtime/internal/atomic.And": true, "runtime/internal/atomic.And8": true, "runtime/internal/atomic.Cas": true, "runtime/internal/atomic.Cas64": true, + "runtime/internal/atomic.CasRel": true, "runtime/internal/atomic.Casint32": true, "runtime/internal/atomic.Casint64": true, "runtime/internal/atomic.Casp1": true, - "runtime/internal/atomic.CasRel": true, "runtime/internal/atomic.Casuintptr": true, "runtime/internal/atomic.Load": true, "runtime/internal/atomic.Load64": true, @@ -136,12 +137,12 @@ var compilerIntrinsicsFuncs = map[string]bool{ "runtime/internal/atomic.Store": true, "runtime/internal/atomic.Store64": true, "runtime/internal/atomic.Store8": true, - "runtime/internal/atomic.Storeint32": true, - "runtime/internal/atomic.Storeint64": true, - "runtime/internal/atomic.StorepNoWB": true, "runtime/internal/atomic.StoreRel": true, "runtime/internal/atomic.StoreRel64": true, "runtime/internal/atomic.StoreReluintptr": true, + "runtime/internal/atomic.Storeint32": true, + "runtime/internal/atomic.Storeint64": true, + "runtime/internal/atomic.StorepNoWB": true, "runtime/internal/atomic.Storeuintptr": true, "runtime/internal/atomic.Xadd": true, "runtime/internal/atomic.Xadd64": true, @@ -166,7 +167,8 @@ var compilerIntrinsicsFuncs = map[string]bool{ "runtime/internal/sys.TrailingZeros32": true, "runtime/internal/sys.TrailingZeros64": true, "runtime/internal/sys.TrailingZeros8": true, - "runtime.publicationBarrier": true, + "sync.runtime_LoadAcquintptr": true, + "sync.runtime_StoreReluintptr": true, "sync/atomic.AddInt32": true, "sync/atomic.AddInt64": true, "sync/atomic.AddUint32": true, @@ -193,8 +195,6 @@ var compilerIntrinsicsFuncs = map[string]bool{ "sync/atomic.SwapUint32": true, "sync/atomic.SwapUint64": true, "sync/atomic.SwapUintptr": true, - "sync.runtime_LoadAcquintptr": true, - "sync.runtime_StoreReluintptr": true, } var reflectSkipPkg = map[string]bool{ diff --git a/scripts/gen-go-std-tables.sh b/scripts/gen-go-std-tables.sh deleted file mode 100755 index 2ebe255..0000000 --- a/scripts/gen-go-std-tables.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -# We can rewrite this bash script in Go if a dependency on bash and coreutils -# is a problem during development. - -goroot=$(go env GOROOT) -go_version=$(go env GOVERSION) # not "go version", to exclude GOOS/GOARCH - -runtime_and_deps=$(go list -deps runtime) - -# All packages that the runtime linknames to, except runtime and its dependencies. -# This resulting list is what we need to "go list" when obfuscating the runtime, -# as they are the packages that we may be missing. -runtime_linknamed=$(comm -23 <( - sed -rn 's@//go:linkname .* ([^.]*)\.[^.]*@\1@p' "${goroot}"/src/runtime/*.go | grep -vE '^main|^runtime\.|_test$' | sort -u -) <( - # Note that we assume this is constant across platforms. - go list -deps runtime | sort -u -)) - -compiler_intrinsics_table="$(sed -rn 's@.*\b(addF|alias)\("([^"]*)", "([^"]*)",.*@\2 \3@p' "${goroot}"/src/cmd/compile/internal/ssagen/ssa.go | sort -u)" -compiler_intrinsics_paths="$(while read path name; do - echo ${path} -done <<<"${compiler_intrinsics_table}" | sort -u)" - -gofmt >go_std_tables.go <