You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
garble/scripts/gen-go-std-tables.sh

70 lines
2.1 KiB
Bash

#!/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 <<EOF
// Code generated by scripts/gen-go-std-tables.sh; DO NOT EDIT.
// Generated from Go version ${go_version}.
package main
var runtimeAndDeps = map[string]bool{
$(for path in ${runtime_and_deps}; do
echo "\"${path}\": true,"
done)
// Not runtime dependencies, but still use tricks allowed by import path.
// TODO: collect directly from cmd/internal/objabi/pkgspecial.go,
// in this particular case from allowAsmABIPkgs.
"reflect": true,
"syscall": true,
"runtime/internal/startlinetest": true,
}
var runtimeLinknamed = []string{
$(for path in ${runtime_linknamed}; do
echo "\"${path}\"",
done)
// The net package linknames to the runtime, not the other way around.
// TODO: support this automatically via our script.
"net",
}
var compilerIntrinsicsPkgs = map[string]bool{
$(for path in ${compiler_intrinsics_paths}; do
echo "\"${path}\": true,"
done)
}
var compilerIntrinsicsFuncs = map[string]bool{
$(while read path name; do
echo "\"${path}.${name}\": true,"
done <<<"${compiler_intrinsics_table}")
}
var reflectSkipPkg = map[string]bool{
"fmt": true,
}
EOF