Skip to content

Commit

Permalink
all: support Go 1.21 for Linux
Browse files Browse the repository at this point in the history
* Update patches for Go 1.21.
* Apply NOFRAME for amd64 assembly files. See https://go.dev/doc/go1.21#assembler.

Updates #25
  • Loading branch information
hajimehoshi committed Aug 12, 2023
1 parent e84e78a commit 6e1f588
Show file tree
Hide file tree
Showing 89 changed files with 3,299 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
go: ['1.18.10', '1.19.12', '1.20.7']
go: ['1.18.10', '1.19.12', '1.20.7', '1.21.0']
name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v time"
- name: Test (amd64)
if: ${{ !startsWith(matrix.go, '1.18.') }}
if: ${{ !startsWith(matrix.go, '1.18.') && (runner.os == 'Linux' || !startsWith(matrix.go, '1.21.')) }}
run: |
go run test.go -args="-test.run=^Test -test.v fmt"
go run test.go -args="-test.run=^Test -test.v internal/abi"
Expand Down
1 change: 0 additions & 1 deletion 1.20_linux/runtime/cgo/gcc_sigaction.c.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//--from
// +build linux,amd64 linux,arm64 linux,ppc64le
//--to
// TODO
// +build linux,arm64 linux,ppc64le
5 changes: 5 additions & 0 deletions 1.21_linux/internal/reflectlite/reflect_mirror_test.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//--from
func TestMirrorWithReflect(t *testing.T) {
//--to
func TestMirrorWithReflect(t *testing.T) {
t.Skip("file is not supported in this environment")
12 changes: 12 additions & 0 deletions 1.21_linux/internal/syscall/unix/fcntl_unix.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//--from
func Fcntl(fd int, cmd int, arg int) (int, error) {
val, errno := fcntl(int32(fd), int32(cmd), int32(arg))
if val == -1 {
return int(val), syscall.Errno(errno)
}
return int(val), nil
}
//--to
func Fcntl(fd int, cmd int, arg int) (int, error) {
return 0, syscall.ENOSYS
}
5 changes: 5 additions & 0 deletions 1.21_linux/internal/testenv/exec.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//--from
func tryExec() error {
//--to
func tryExec() error {
return fmt.Errorf("can't probe for exec support")
5 changes: 5 additions & 0 deletions 1.21_linux/internal/testenv/testenv.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//--from
func HasGoBuild() bool {
//--to
func HasGoBuild() bool {
return false
4 changes: 4 additions & 0 deletions 1.21_linux/internal/testenv/testenv_notunix.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//--from
//go:build windows || plan9 || (js && wasm) || wasip1
//--to
//go:build windows || plan9 || (js && wasm) || wasip1 || linux
4 changes: 4 additions & 0 deletions 1.21_linux/internal/testenv/testenv_unix.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//--from
//go:build unix
//--to
//go:build unix && !linux
5 changes: 5 additions & 0 deletions 1.21_linux/math/big/link_test.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//--from
func TestLinkerGC(t *testing.T) {
//--to
func TestLinkerGC(t *testing.T) {
t.Skip("go tools are not supported in this environment")
5 changes: 5 additions & 0 deletions 1.21_linux/math/rand/default_test.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//--from
func TestDefaultRace(t *testing.T) {
//--to
func TestDefaultRace(t *testing.T) {
t.Skip("creating a process is not supported in this environment")
5 changes: 5 additions & 0 deletions 1.21_linux/runtime/align_test.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//--from
func TestAtomicAlignment(t *testing.T) {
//--to
func TestAtomicAlignment(t *testing.T) {
t.Skip("file is not supported in this environment")
15 changes: 15 additions & 0 deletions 1.21_linux/runtime/callers_test.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//--from
func TestCallersNilPointerPanic(t *testing.T) {
//--to
func TestCallersNilPointerPanic(t *testing.T) {
t.Skip("handling nil pointer access is not supported in this environment")
//--from
func TestCallersDeferNilFuncPanic(t *testing.T) {
//--to
func TestCallersDeferNilFuncPanic(t *testing.T) {
t.Skip("handling nil pointer access is not supported in this environment")
//--from
func TestCallersDeferNilFuncPanicWithLoop(t *testing.T) {
//--to
func TestCallersDeferNilFuncPanicWithLoop(t *testing.T) {
t.Skip("handling nil pointer access is not supported in this environment")
9 changes: 9 additions & 0 deletions 1.21_linux/runtime/cgo/cgo.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//--from
*/
import "C"
//--to
#cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all
#cgo darwin LDFLAGS: -Wl,-undefined,dynamic_lookup
#cgo nintendosdk CFLAGS: -D_USE_PTHREAD_AFFINITY_NP
*/
import "C"
31 changes: 31 additions & 0 deletions 1.21_linux/runtime/cgo/gcc_libinit.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//--from
#include <pthread.h>
//--to
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <pthread.h>
//--from
err = pthread_create(thread, attr, pfn, arg);
if (err == 0) {
pthread_detach(*thread);
return 0;
}
//--to
err = pthread_create(thread, attr, pfn, arg);
if (err == 0) {
pthread_detach(*thread);
#ifdef _USE_PTHREAD_AFFINITY_NP
extern int32_t hitsumabushi_getproccount();
int32_t numcpu = hitsumabushi_getproccount();
cpu_set_t *cpu_set = CPU_ALLOC(numcpu);
size_t size = CPU_ALLOC_SIZE(numcpu);
CPU_ZERO_S(size, cpu_set);
for (int i = 0; i < numcpu; i++) {
CPU_SET_S(i, size, cpu_set);
}
pthread_setaffinity_np(*thread, size, cpu_set);
CPU_FREE(cpu_set);
#endif
return 0;
}
59 changes: 59 additions & 0 deletions 1.21_linux/runtime/cgo/gcc_linux_amd64.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//--from
#include <pthread.h>
#include <errno.h>
#include <string.h> // strerror
#include <signal.h>
#include <stdlib.h>
#include "libcgo.h"
#include "libcgo_unix.h"
//--to
#include <pthread.h>
#include <errno.h>
#include <string.h> // strerror
#include <stdlib.h>
#include "libcgo.h"
#include "libcgo_unix.h"
//--from
void
_cgo_sys_thread_start(ThreadStart *ts)
{
pthread_attr_t attr;
sigset_t ign, oset;
pthread_t p;
size_t size;
int err;

sigfillset(&ign);
pthread_sigmask(SIG_SETMASK, &ign, &oset);

pthread_attr_init(&attr);
pthread_attr_getstacksize(&attr, &size);
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
ts->g->stackhi = size;
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);

pthread_sigmask(SIG_SETMASK, &oset, nil);

if (err != 0) {
fatalf("pthread_create failed: %s", strerror(err));
}
}
//--to
void
_cgo_sys_thread_start(ThreadStart *ts)
{
pthread_attr_t attr;
pthread_t p;
size_t size;
int err;

pthread_attr_init(&attr);
pthread_attr_getstacksize(&attr, &size);
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
ts->g->stackhi = size;
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);

if (err != 0) {
fatalf("pthread_create failed: %s", strerror(err));
}
}
126 changes: 126 additions & 0 deletions 1.21_linux/runtime/cgo/gcc_linux_arm64.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//--from
void
_cgo_sys_thread_start(ThreadStart *ts)
{
pthread_attr_t attr;
sigset_t ign, oset;
pthread_t p;
size_t size;
int err;

sigfillset(&ign);
pthread_sigmask(SIG_SETMASK, &ign, &oset);

pthread_attr_init(&attr);
pthread_attr_getstacksize(&attr, &size);
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
ts->g->stackhi = size;
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);

pthread_sigmask(SIG_SETMASK, &oset, nil);

if (err != 0) {
fatalf("pthread_create failed: %s", strerror(err));
}
}
//--to
void
_cgo_sys_thread_start(ThreadStart *ts)
{
pthread_attr_t attr;
sigset_t ign, oset;
pthread_t p;
size_t size;
int err;

sigfillset(&ign);
pthread_sigmask(SIG_SETMASK, &ign, &oset);

pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 16 * 4096); // Hack for some special environments
pthread_attr_getstacksize(&attr, &size);
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
ts->g->stackhi = size;
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);

pthread_sigmask(SIG_SETMASK, &oset, nil);

if (err != 0) {
fatalf("pthread_create failed: %s", strerror(err));
}
}
//--from
void
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
{
pthread_attr_t *attr;
size_t size;

/* The memory sanitizer distributed with versions of clang
before 3.8 has a bug: if you call mmap before malloc, mmap
may return an address that is later overwritten by the msan
library. Avoid this problem by forcing a call to malloc
here, before we ever call malloc.

This is only required for the memory sanitizer, so it's
unfortunate that we always run it. It should be possible
to remove this when we no longer care about versions of
clang before 3.8. The test for this is
misc/cgo/testsanitizers.

GCC works hard to eliminate a seemingly unnecessary call to
malloc, so we actually use the memory we allocate. */

setg_gcc = setg;
attr = (pthread_attr_t*)malloc(sizeof *attr);
if (attr == NULL) {
fatalf("malloc failed: %s", strerror(errno));
}
pthread_attr_init(attr);
pthread_attr_getstacksize(attr, &size);
g->stacklo = (uintptr)&size - size + 4096;
pthread_attr_destroy(attr);
free(attr);

if (x_cgo_inittls) {
x_cgo_inittls(tlsg, tlsbase);
}
}
//--to
void
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
{
pthread_attr_t *attr;
size_t size;

/* The memory sanitizer distributed with versions of clang
before 3.8 has a bug: if you call mmap before malloc, mmap
may return an address that is later overwritten by the msan
library. Avoid this problem by forcing a call to malloc
here, before we ever call malloc.

This is only required for the memory sanitizer, so it's
unfortunate that we always run it. It should be possible
to remove this when we no longer care about versions of
clang before 3.8. The test for this is
misc/cgo/testsanitizers.

GCC works hard to eliminate a seemingly unnecessary call to
malloc, so we actually use the memory we allocate. */

setg_gcc = setg;
attr = (pthread_attr_t*)malloc(sizeof *attr);
if (attr == NULL) {
fatalf("malloc failed: %s", strerror(errno));
}
pthread_attr_init(attr);
pthread_attr_setstacksize(attr, 16 * 4096); // Hack for some special environments
pthread_attr_getstacksize(attr, &size);
g->stacklo = (uintptr)&size - size + 4096;
pthread_attr_destroy(attr);
free(attr);

if (x_cgo_inittls) {
x_cgo_inittls(tlsg, tlsbase);
}
}
26 changes: 26 additions & 0 deletions 1.21_linux/runtime/cgo/gcc_setenv.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//--from
void
x_cgo_setenv(char **arg)
{
_cgo_tsan_acquire();
setenv(arg[0], arg[1], 1);
_cgo_tsan_release();
}
//--to
void
x_cgo_setenv(char **arg)
{
}
//--from
void
x_cgo_unsetenv(char **arg)
{
_cgo_tsan_acquire();
unsetenv(arg[0]);
_cgo_tsan_release();
}
//--to
void
x_cgo_unsetenv(char **arg)
{
}
4 changes: 4 additions & 0 deletions 1.21_linux/runtime/cgo/gcc_sigaction.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//--from
//go:build linux && (amd64 || arm64 || ppc64le)
//--to
//go:build linux && (arm64 || ppc64le)
8 changes: 8 additions & 0 deletions 1.21_linux/runtime/cgo/hitsumabushi_clock_linux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Hitsumabushi Authors

#include <time.h>

int hitsumabushi_clock_gettime(clockid_t clk_id, struct timespec *tp) {
return clock_gettime(clk_id, tp);
}
8 changes: 8 additions & 0 deletions 1.21_linux/runtime/cgo/hitsumabushi_cpu_linux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Hitsumabushi Authors

#include <stdint.h>

int32_t hitsumabushi_getproccount() {
return 1;
}
Loading

0 comments on commit 6e1f588

Please sign in to comment.