add and test initial support for Go 1.22

The Go 1.21 linker patches luckily rebased on master as of
de5b418bea70aaf27de1f47e9b5813940d1e15a4 just fine.
The addition of the strings import in the second patch was removed,
since the file in Go 1.22 now has this package import.

We can remove the Go 1.20 linker patches too, since we no longer support
that Go version in the upcoming release.

Start treating runtime/internal/startlinetest as part of the runtime,
since otherwise its test-only trickery breaks "garble build std":

    # runtime/internal/startlinetest
    [...]/XS7r7lPHkTG.s:23: ABI selector only permitted when compiling runtime, reference was to "HGoWHDsKwh.AlfA2or7Nnb"
    asm: assembly of $WORK/.tmp/garble-shared1535203339/HGoWHDsKwh/XS7r7lPHkTG.s failed

While here, update actions/checkout and staticcheck in CI.
pull/815/head
Daniel Martí 6 months ago committed by pagran
parent 9378ec959a
commit d283d8479c

@ -29,7 +29,7 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
@ -66,7 +66,7 @@ jobs:
- if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.21.x'
uses: dominikh/staticcheck-action@v1
with:
version: "2023.1.3"
version: "2023.1.6"
install-go: false
# We don't care about GOARCH=386 particularly, hence -short,
@ -78,7 +78,7 @@ jobs:
env:
GOARCH: 386
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 1.21.x
@ -86,13 +86,12 @@ jobs:
- run: go test -short ./...
test-gotip:
if: false # let tip for 1.22 settle first
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Go
env:
GO_COMMIT: a031f4ef83edc132d5f49382bfef491161de2476 # 2023-06-24
GO_COMMIT: de5b418bea70aaf27de1f47e9b5813940d1e15a4 # 2023-12-02
run: |
cd $HOME
mkdir $HOME/gotip
@ -100,7 +99,7 @@ jobs:
wget -O gotip.tar.gz https://go.googlesource.com/go/+archive/${GO_COMMIT}.tar.gz
tar -xf gotip.tar.gz
echo "devel go1.21-${GO_COMMIT}" >VERSION
echo "devel go1.22-${GO_COMMIT}" >VERSION
cd src
./make.bash

@ -1,6 +1,6 @@
// Code generated by scripts/gen-go-std-tables.sh; DO NOT EDIT.
// Generated from Go version devel go1.22-8da6405e0d Sat Nov 11 02:02:35 2023 +0000.
// Generated from Go version devel go1.22-de5b418bea Sat Dec 2 03:15:03 2023 +0000.
package main
@ -19,6 +19,9 @@ var runtimeAndDeps = map[string]bool{
"runtime/internal/sys": true,
"runtime/internal/syscall": true,
"runtime": true,
// Not a runtime dependency, but still uses tricks allowed by import path.
// Not a big deal either way, given that it's only imported in test packages.
"runtime/internal/startlinetest": true,
}
var runtimeLinknamed = []string{

@ -120,10 +120,7 @@ func applyPatches(srcDir, workingDir string, modFiles map[string]bool, patches [
cmd.Stdin = bytes.NewReader(bytes.Join(patches, []byte("\n")))
out, err := cmd.CombinedOutput()
if err != nil {
if err, ok := err.(*exec.ExitError); ok {
return nil, fmt.Errorf("%v:\n%s", err, out)
}
return nil, err
return nil, fmt.Errorf("failed to 'git apply' patches: %v:\n%s", err, out)
}
// Running git without errors does not guarantee that all patches have been applied.

@ -1,73 +0,0 @@
From 32d5f31bf11858d9282271980a923bdde2ed5ffe Mon Sep 17 00:00:00 2001
From: pagran <pagran@protonmail.com>
Date: Mon, 9 Jan 2023 13:30:36 +0100
Subject: [PATCH 2/3] add unexported function name removing
---
cmd/link/internal/ld/pcln.go | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/cmd/link/internal/ld/pcln.go b/cmd/link/internal/ld/pcln.go
index b89a4d650c..ab13b15042 100644
--- a/cmd/link/internal/ld/pcln.go
+++ b/cmd/link/internal/ld/pcln.go
@@ -4,6 +4,8 @@
package ld
+import "unicode"
+
import (
"cmd/internal/goobj"
"cmd/internal/objabi"
@@ -321,10 +323,19 @@ func (state *pclntab) generateFuncnametab(ctxt *Link, funcs []loader.Sym) map[lo
return name[:i], "[...]", name[j+1:]
}
+ garbleTiny := os.Getenv("GARBLE_LINK_TINY") == "true"
+
// Write the null terminated strings.
writeFuncNameTab := func(ctxt *Link, s loader.Sym) {
symtab := ctxt.loader.MakeSymbolUpdater(s)
+ if garbleTiny {
+ symtab.AddStringAt(0, "")
+ }
+
for s, off := range nameOffsets {
+ if garbleTiny && off == 0 {
+ continue
+ }
a, b, c := nameParts(ctxt.loader.SymName(s))
o := int64(off)
o = symtab.AddStringAt(o, a)
@@ -335,9 +346,26 @@ func (state *pclntab) generateFuncnametab(ctxt *Link, funcs []loader.Sym) map[lo
// Loop through the CUs, and calculate the size needed.
var size int64
+
+ if garbleTiny {
+ size = 1 // first byte is reserved for empty string used for all non-exportable method names
+ }
+ isExported := func(name string) bool {
+ for _, r := range name[strings.LastIndexByte(name, '.')+1:] {
+ return unicode.IsUpper(r)
+ }
+ return false
+ }
+
walkFuncs(ctxt, funcs, func(s loader.Sym) {
- nameOffsets[s] = uint32(size)
a, b, c := nameParts(ctxt.loader.SymName(s))
+
+ if garbleTiny && !isExported(a) {
+ nameOffsets[s] = 0 // redirect name to empty string
+ return
+ }
+
+ nameOffsets[s] = uint32(size)
size += int64(len(a) + len(b) + len(c) + 1) // NULL terminate
})
--
2.40.1

@ -1,4 +1,4 @@
From ea90dd90688b91b280933e1543594d3d2639482e Mon Sep 17 00:00:00 2001
From ef30d58213cf765d0e02eb3b4e151b170fb9fd6b Mon Sep 17 00:00:00 2001
From: pagran <pagran@protonmail.com>
Date: Mon, 9 Jan 2023 13:30:00 +0100
Subject: [PATCH 1/3] add custom magic value
@ -8,10 +8,10 @@ Subject: [PATCH 1/3] add custom magic value
1 file changed, 13 insertions(+)
diff --git a/cmd/link/internal/ld/pcln.go b/cmd/link/internal/ld/pcln.go
index 34ab86cf12..b89a4d650c 100644
index 5734b92507..0f95ad928b 100644
--- a/cmd/link/internal/ld/pcln.go
+++ b/cmd/link/internal/ld/pcln.go
@@ -249,6 +249,19 @@ func (state *pclntab) generatePCHeader(ctxt *Link) {
@@ -263,6 +263,19 @@ func (state *pclntab) generatePCHeader(ctxt *Link) {
if off != size {
panic(fmt.Sprintf("pcHeader size: %d != %d", off, size))
}
@ -32,5 +32,5 @@ index 34ab86cf12..b89a4d650c 100644
state.pcheader = state.addGeneratedSym(ctxt, "runtime.pcheader", size, writeHeader)
--
2.40.1
2.43.0

@ -0,0 +1,85 @@
From fef657296f1f1b51b73b4e715af4ce9569d05bae Mon Sep 17 00:00:00 2001
From: pagran <pagran@protonmail.com>
Date: Mon, 9 Jan 2023 13:30:36 +0100
Subject: [PATCH 2/3] add unexported function name removing
---
cmd/link/internal/ld/pcln.go | 43 +++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/cmd/link/internal/ld/pcln.go b/cmd/link/internal/ld/pcln.go
index 0f95ad928b..6bfa03da87 100644
--- a/cmd/link/internal/ld/pcln.go
+++ b/cmd/link/internal/ld/pcln.go
@@ -4,6 +4,10 @@
package ld
+import (
+ "unicode"
+)
+
import (
"cmd/internal/goobj"
"cmd/internal/objabi"
@@ -315,19 +319,56 @@ func walkFuncs(ctxt *Link, funcs []loader.Sym, f func(loader.Sym)) {
func (state *pclntab) generateFuncnametab(ctxt *Link, funcs []loader.Sym) map[loader.Sym]uint32 {
nameOffsets := make(map[loader.Sym]uint32, state.nfunc)
+ garbleTiny := os.Getenv("GARBLE_LINK_TINY") == "true"
+
// Write the null terminated strings.
writeFuncNameTab := func(ctxt *Link, s loader.Sym) {
symtab := ctxt.loader.MakeSymbolUpdater(s)
+ if garbleTiny {
+ symtab.AddStringAt(0, "")
+ }
+
for s, off := range nameOffsets {
+ if garbleTiny && off == 0 {
+ continue
+ }
symtab.AddCStringAt(int64(off), ctxt.loader.SymName(s))
}
}
// Loop through the CUs, and calculate the size needed.
var size int64
+
+ if garbleTiny {
+ size = 1 // first byte is reserved for empty string used for all non-exportable method names
+ }
+ // Kinds of SymNames found in the wild:
+ //
+ // * reflect.Value.CanAddr
+ // * reflect.(*Value).String
+ // * reflect.w6cEoKc
+ // * internal/abi.(*RegArgs).IntRegArgAddr
+ // * type:.eq.runtime.special
+ // * runtime/internal/atomic.(*Pointer[go.shape.string]).Store
+ //
+ // Checking whether the first rune after the last dot is uppercase seems enough.
+ isExported := func(name string) bool {
+ for _, r := range name[strings.LastIndexByte(name, '.')+1:] {
+ return unicode.IsUpper(r)
+ }
+ return false
+ }
+
walkFuncs(ctxt, funcs, func(s loader.Sym) {
+ name := ctxt.loader.SymName(s)
+
+ if garbleTiny && !isExported(name) {
+ nameOffsets[s] = 0 // redirect name to empty string
+ return
+ }
+
nameOffsets[s] = uint32(size)
- size += int64(len(ctxt.loader.SymName(s)) + 1) // NULL terminate
+ size += int64(len(name) + 1) // NULL terminate
})
state.funcnametab = state.addGeneratedSym(ctxt, "runtime.funcnametab", size, writeFuncNameTab)
--
2.43.0

@ -1,4 +1,4 @@
From bd2adb2221c87bd80d4593473b2b45904dc8e8fc Mon Sep 17 00:00:00 2001
From 49f31a321c5b2d082981428abbb5d53e244c4200 Mon Sep 17 00:00:00 2001
From: pagran <pagran@protonmail.com>
Date: Sat, 14 Jan 2023 21:36:16 +0100
Subject: [PATCH 3/3] add entryOff encryption
@ -8,10 +8,10 @@ Subject: [PATCH 3/3] add entryOff encryption
1 file changed, 20 insertions(+)
diff --git a/cmd/link/internal/ld/pcln.go b/cmd/link/internal/ld/pcln.go
index ab13b15042..8e2fa09434 100644
index 6bfa03da87..538cba32db 100644
--- a/cmd/link/internal/ld/pcln.go
+++ b/cmd/link/internal/ld/pcln.go
@@ -790,6 +790,26 @@ func writeFuncs(ctxt *Link, sb *loader.SymbolBuilder, funcs []loader.Sym, inlSym
@@ -803,6 +803,26 @@ func writeFuncs(ctxt *Link, sb *loader.SymbolBuilder, funcs []loader.Sym, inlSym
sb.SetUint32(ctxt.Arch, dataoff, uint32(ldr.SymValue(fdsym)-gofuncBase))
}
}
@ -39,5 +39,5 @@ index ab13b15042..8e2fa09434 100644
// pclntab initializes the pclntab symbol with
--
2.40.1
2.43.0

@ -34,6 +34,9 @@ var runtimeAndDeps = map[string]bool{
$(for path in ${runtime_and_deps}; do
echo "\"${path}\": true,"
done)
// Not a runtime dependency, but still uses tricks allowed by import path.
// Not a big deal either way, given that it's only imported in test packages.
"runtime/internal/startlinetest": true,
}
var runtimeLinknamed = []string{

Loading…
Cancel
Save