[go] runtime: fixes using go .so and .a libraries with musl/uclinux

9 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
May 8, 2024, 8:21:07 AM5/8/24
to goph...@pubsubhelper.golang.org, Alex Eaton, golang-co...@googlegroups.com

Gerrit Bot has uploaded the change for review

Commit message

runtime: fixes using go .so and .a libraries with musl/uclinux

This works around the segfault seen when compiling a shared archive and linking it on a musl/uclinux system.

The issue is that the go runtime is doing some magic to extract the program arguments even though the go side is compiled as a library.

By including my changes the glibc behavior remains unchanged, and for musl/uclinux systems we simply do not get any arguments if we are linked as a shared library.

I've attempted to get these changes included in the past and have been manually patching my go releases for alpine. I believe the issue raised previously was that in theory we could parse the arguments from /proc but honestly I don't have time to mess with that and don't see the need for a library to be aware of argc/argv unless someone here thinks otherwise.
Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
GitHub-Last-Rev: a25b7aca2ec70a18c40375bf30467c831a491e16
GitHub-Pull-Request: golang/go#67254

Change diff

diff --git a/src/cmd/cgo/internal/testcarchive/testdata/libgo/libgo.go b/src/cmd/cgo/internal/testcarchive/testdata/libgo/libgo.go
index 37b30c1..3a0684e 100644
--- a/src/cmd/cgo/internal/testcarchive/testdata/libgo/libgo.go
+++ b/src/cmd/cgo/internal/testcarchive/testdata/libgo/libgo.go
@@ -46,7 +46,11 @@

//export CheckArgs
func CheckArgs() {
- if len(os.Args) != 3 || os.Args[1] != "arg1" || os.Args[2] != "arg2" {
+ // Dynamic linkers which supply the library initialization functions with the
+ // main program's argc / argc should have 3 args here, else they should have
+ // none.
+ valid := (len(os.Args) == 3 && os.Args[1] == "arg1" && os.Args[2] == "arg2") || (len(os.Args) == 0)
+ if !valid {
fmt.Printf("CheckArgs: want [_, arg1, arg2], got: %v\n", os.Args)
os.Exit(2)
}
diff --git a/src/runtime/cgo.go b/src/runtime/cgo.go
index 40c8c74..65c4e76 100644
--- a/src/runtime/cgo.go
+++ b/src/runtime/cgo.go
@@ -12,6 +12,7 @@

//go:linkname _cgo_init _cgo_init
//go:linkname _cgo_thread_start _cgo_thread_start
+//go:linkname _cgo_sys_lib_args_valid _cgo_sys_lib_args_valid
//go:linkname _cgo_sys_thread_create _cgo_sys_thread_create
//go:linkname _cgo_notify_runtime_init_done _cgo_notify_runtime_init_done
//go:linkname _cgo_callers _cgo_callers
@@ -24,6 +25,7 @@
var (
_cgo_init unsafe.Pointer
_cgo_thread_start unsafe.Pointer
+ _cgo_sys_lib_args_valid unsafe.Pointer
_cgo_sys_thread_create unsafe.Pointer
_cgo_notify_runtime_init_done unsafe.Pointer
_cgo_callers unsafe.Pointer
diff --git a/src/runtime/cgo/callbacks.go b/src/runtime/cgo/callbacks.go
index 3c246a8..6a53f2b 100644
--- a/src/runtime/cgo/callbacks.go
+++ b/src/runtime/cgo/callbacks.go
@@ -59,6 +59,14 @@
var x_cgo_thread_start byte
var _cgo_thread_start = &x_cgo_thread_start

+// Determines if the argc / argv passed to the library initialization functions
+// are valid.
+//go:cgo_import_static x_cgo_sys_lib_args_valid
+//go:linkname x_cgo_sys_lib_args_valid x_cgo_sys_lib_args_valid
+//go:linkname _cgo_sys_lib_args_valid _cgo_sys_lib_args_valid
+var x_cgo_sys_lib_args_valid byte
+var _cgo_sys_lib_args_valid = &x_cgo_sys_lib_args_valid
+
// Creates a new system thread without updating any Go state.
//
// This method is invoked during shared library loading to create a new OS
diff --git a/src/runtime/cgo/gcc_libinit.c b/src/runtime/cgo/gcc_libinit.c
index 33a9ff9..97dc7b4 100644
--- a/src/runtime/cgo/gcc_libinit.c
+++ b/src/runtime/cgo/gcc_libinit.c
@@ -13,6 +13,7 @@

#include <pthread.h>
#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // strerror
@@ -35,6 +36,20 @@
// The context function, used when tracing back C calls into Go.
static void (*cgo_context_function)(struct context_arg*);

+// Detect if using glibc
+int
+x_cgo_sys_lib_args_valid()
+{
+ // The ELF gABI doesn't require an argc / argv to be passed to the functions
+ // in the DT_INIT_ARRAY. However, glibc always does.
+ // Ignore uClibc masquerading as glibc.
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+ return 1;
+#else
+ return 0;
+#endif
+}
+
void
x_cgo_sys_thread_create(void* (*func)(void*), void* arg) {
pthread_t p;
diff --git a/src/runtime/cgo/gcc_libinit_windows.c b/src/runtime/cgo/gcc_libinit_windows.c
index 9a8c65e..a4693fb 100644
--- a/src/runtime/cgo/gcc_libinit_windows.c
+++ b/src/runtime/cgo/gcc_libinit_windows.c
@@ -62,6 +62,11 @@
}
}

+int
+x_cgo_sys_lib_args_valid() {
+ return 1;
+}
+
void
x_cgo_sys_thread_create(void (*func)(void*), void* arg) {
_cgo_beginthread(func, arg);
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go
index 6ce656c..0a97b44 100644
--- a/src/runtime/os_linux.go
+++ b/src/runtime/os_linux.go
@@ -233,21 +233,44 @@
func sysargs(argc int32, argv **byte) {
n := argc + 1

- // skip over argv, envp to get to auxv
- for argv_index(argv, n) != nil {
+ argsValid := true
+ if islibrary || isarchive {
+ if !sysLibArgsValid() {
+ argsValid = false
+ }
+ }
+
+ if argsValid {
+ // skip over argv, envp to get to auxv
+ for argv_index(argv, n) != nil {
+ n++
+ }
+
+ // skip NULL separator
n++
+
+ // now argv+n is auxv
+ auxvp := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*goarch.PtrSize))
+
+ if pairs := sysauxv(auxvp[:]); pairs != 0 {
+ auxv = auxvp[: pairs*2 : pairs*2]
+ return
+ }
+ } else {
+ args := unsafe.Pointer(persistentalloc(goarch.PtrSize*4, 0, &memstats.other_sys))
+ // argv pointer
+ *(**byte)(args) = (*byte)(add(args, goarch.PtrSize*1))
+ // argv data
+ *(**byte)(add(args, goarch.PtrSize*1)) = (*byte)(nil) // end argv TODO: READ FROM /proc/
+ *(**byte)(add(args, goarch.PtrSize*2)) = (*byte)(nil) // end envp TODO: READ FROM /proc/
+ *(**byte)(add(args, goarch.PtrSize*3)) = (*byte)(nil) // end auxv TODO: READ FROM /proc/
+ argc = 0
+ argv = (**byte)(args)
+
+ // argc = 0
+ // argv = (**byte)(&[3]*byte{nil, nil, nil})
}
-
- // skip NULL separator
- n++
-
- // now argv+n is auxv
- auxvp := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*goarch.PtrSize))
-
- if pairs := sysauxv(auxvp[:]); pairs != 0 {
- auxv = auxvp[: pairs*2 : pairs*2]
- return
- }
+
// In some situations we don't get a loader-provided
// auxv, such as when loaded as a library on Android.
// Fall back to /proc/self/auxv.
diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go
index 5b37d23..81dcb35 100644
--- a/src/runtime/runtime1.go
+++ b/src/runtime/runtime1.go
@@ -56,10 +56,28 @@
argv **byte
)

+// when using -buildmode=c-archive or -buildmode=c-shared on linux
+// we have to first make sure that glibc is being used or else
+// we cannot rely on argc/argv/auxv to be accurate
+func sysLibArgsValid() bool {
+ if _cgo_sys_lib_args_valid != nil {
+ ret := asmcgocall(_cgo_sys_lib_args_valid, nil)
+ if ret != 1 {
+ return false
+ }
+ }
+ return true
+}
+
// nosplit for use in linux startup sysargs.
//
//go:nosplit
func argv_index(argv **byte, i int32) *byte {
+ if islibrary || isarchive {
+ if !sysLibArgsValid() {
+ return nil
+ }
+ }
return *(**byte)(add(unsafe.Pointer(argv), uintptr(i)*goarch.PtrSize))
}

@@ -73,6 +91,13 @@
if GOOS == "windows" {
return
}
+
+ if islibrary || isarchive {
+ if !sysLibArgsValid() {
+ return
+ }
+ }
+
argslice = make([]string, argc)
for i := int32(0); i < argc; i++ {
argslice[i] = gostringnocopy(argv_index(argv, i))
@@ -80,6 +105,13 @@
}

func goenvs_unix() {
+ if islibrary || isarchive {
+ if !sysLibArgsValid() {
+ envs = make([]string, 0)
+ return
+ }
+ }
+
// TODO(austin): ppc64 in dynamic linking mode doesn't
// guarantee env[] will immediately follow argv. Might cause
// problems.

Change information

Files:
  • M src/cmd/cgo/internal/testcarchive/testdata/libgo/libgo.go
  • M src/runtime/cgo.go
  • M src/runtime/cgo/callbacks.go
  • M src/runtime/cgo/gcc_libinit.c
  • M src/runtime/cgo/gcc_libinit_windows.c
  • M src/runtime/os_linux.go
  • M src/runtime/runtime1.go
Change size: M
Delta: 7 files changed, 103 insertions(+), 14 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
Gerrit-Change-Number: 584115
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: Alex Eaton <1800...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
May 8, 2024, 8:21:07 AM5/8/24
to Alex Eaton, Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Gopher Robot . unresolved

I spotted some possible problems.

These findings are based on simple heuristics. If a finding appears wrong, briefly reply here saying so. Otherwise, please address any problems and update the GitHub PR. When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above.

Possible problems detected:
1. Lines in the commit message should be wrapped at ~76 characters unless needed for things like URLs or tables. You have a 361 character line.
2. You usually need to reference a bug number for all but trivial or cosmetic fixes. For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message. Should you have a bug reference?

The commit title and commit message body come from the GitHub PR title and description, and must be edited in the GitHub web interface (not via git). For instructions, see [here](https://go.dev/wiki/GerritBot/#how-does-gerritbot-determine-the-final-commit-message). For guidelines on commit messages for the Go project, see [here](https://go.dev/doc/contribute#commit_messages).


(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Alex Eaton <1800...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Wed, 08 May 2024 12:21:02 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Ian Lance Taylor (Gerrit)

    unread,
    May 8, 2024, 2:36:27 PM5/8/24
    to Alex Eaton, Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Keith Randall, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Keith Randall and Michael Knyszek

    Ian Lance Taylor added 5 comments

    Commit Message
    Line 7, Patchset 1 (Latest):runtime: fixes using go .so and .a libraries with musl/uclinux
    Ian Lance Taylor . unresolved

    runtime: don't fetch c-archive/c-shared os.Args on musl/uclinux

    Line 15, Patchset 1 (Latest):I've attempted to get these changes included in the past and have been manually patching my go releases for alpine. I believe the issue raised previously was that in theory we could parse the arguments from /proc but honestly I don't have time to mess with that and don't see the need for a library to be aware of argc/argv unless someone here thinks otherwise.
    Ian Lance Taylor . unresolved

    Please add line breaks here and elsewhere. Thanks.

    File src/runtime/cgo/gcc_libinit.c
    Line 16, Patchset 1 (Latest):#include <limits.h>
    Ian Lance Taylor . unresolved

    Why include <limits.h> ?

    Line 39, Patchset 1 (Latest):// Detect if using glibc
    Ian Lance Taylor . unresolved

    This needs a better comment explaining when it is called and what it does.

    Line 46, Patchset 1 (Latest):#if defined(__GLIBC__) && !defined(__UCLIBC__)
    Ian Lance Taylor . unresolved

    What about other operating systems that don't use glibc?

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-CC: Alex Eaton <1800...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Wed, 08 May 2024 18:36:20 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Gerrit Bot (Gerrit)

    unread,
    May 9, 2024, 11:23:10 AM5/9/24
    to Alex Eaton, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Ian Lance Taylor, Keith Randall and Michael Knyszek

    Gerrit Bot uploaded new patchset

    Gerrit Bot uploaded patch set #2 to this change.
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Lance Taylor
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-CC: Alex Eaton <1800...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    unsatisfied_requirement
    open
    diffy

    Gerrit Bot (Gerrit)

    unread,
    May 9, 2024, 11:30:04 AM5/9/24
    to Alex Eaton, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Ian Lance Taylor, Keith Randall and Michael Knyszek

    Gerrit Bot uploaded new patchset

    Gerrit Bot uploaded patch set #3 to this change.
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Lance Taylor
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 3
    unsatisfied_requirement
    open
    diffy

    Gerrit Bot (Gerrit)

    unread,
    May 9, 2024, 11:36:57 AM5/9/24
    to Alex Eaton, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Ian Lance Taylor, Keith Randall and Michael Knyszek

    Gerrit Bot uploaded new patchset

    Gerrit Bot uploaded patch set #4 to this change.
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Lance Taylor
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 4
    unsatisfied_requirement
    open
    diffy

    Alex Eaton (Gerrit)

    unread,
    May 9, 2024, 11:38:43 AM5/9/24
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Keith Randall, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Ian Lance Taylor, Keith Randall and Michael Knyszek

    Alex Eaton added 3 comments

    File src/runtime/cgo/gcc_libinit.c
    Line 16, Patchset 1:#include <limits.h>
    Ian Lance Taylor . unresolved

    Why include <limits.h> ?

    Alex Eaton

    Good catch, it should have been <features.h>

    Line 39, Patchset 1:// Detect if using glibc
    Ian Lance Taylor . unresolved

    This needs a better comment explaining when it is called and what it does.

    Alex Eaton

    Pushed with more detail, let me know if that is sufficient

    Line 46, Patchset 1:#if defined(__GLIBC__) && !defined(__UCLIBC__)
    Ian Lance Taylor . unresolved

    What about other operating systems that don't use glibc?

    Alex Eaton

    My understanding is that the DT_INIT_ARRAY is optional per https://www.sco.com/developers/gabi/latest/ch5.dynamic.html#init_fini

    So glibc may be the only library that optionally passes these arguments - I know that neither musl/uclibc do however

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Lance Taylor
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 4
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-CC: Alex Eaton <1800...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Thu, 09 May 2024 15:38:35 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Ian Lance Taylor <ia...@golang.org>
    unsatisfied_requirement
    open
    diffy

    Alex Eaton (Gerrit)

    unread,
    May 9, 2024, 2:28:28 PM5/9/24
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Keith Randall, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Ian Lance Taylor, Keith Randall and Michael Knyszek

    Alex Eaton added 1 comment

    Patchset-level comments
    File-level comment, Patchset 4 (Latest):
    Alex Eaton . resolved

    I created an example sandbox repository to demonstrate the issue before/after the patch has been applied https://github.com/1800alex/go-cshared-example

    Gerrit-Comment-Date: Thu, 09 May 2024 18:28:23 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Ian Lance Taylor (Gerrit)

    unread,
    May 9, 2024, 2:34:27 PM5/9/24
    to Alex Eaton, Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Keith Randall, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Alex Eaton, Keith Randall and Michael Knyszek

    Ian Lance Taylor added 2 comments

    File src/runtime/cgo/gcc_libinit.c
    Line 16, Patchset 1:#include <limits.h>
    Ian Lance Taylor . unresolved

    Why include <limits.h> ?

    Alex Eaton

    Good catch, it should have been <features.h>

    Ian Lance Taylor

    <features.h> isn't a standard header file as far as I know. It's unlikely to be present on all operating systems. And it shouldn't be necessary to #include it here, as the other headers are bound to bring it in.

    Line 46, Patchset 1:#if defined(__GLIBC__) && !defined(__UCLIBC__)
    Ian Lance Taylor . unresolved

    What about other operating systems that don't use glibc?

    Alex Eaton

    My understanding is that the DT_INIT_ARRAY is optional per https://www.sco.com/developers/gabi/latest/ch5.dynamic.html#init_fini

    So glibc may be the only library that optionally passes these arguments - I know that neither musl/uclibc do however

    Ian Lance Taylor

    glibc is not the only library that passes these arguments. They are also passed on at least some *BSD systems. I think this function must return 1 _except_ for the case of uclibc.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Alex Eaton
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 4
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-CC: Alex Eaton <1800...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Alex Eaton <1800...@gmail.com>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Thu, 09 May 2024 18:34:22 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Alex Eaton <1800...@gmail.com>
    unsatisfied_requirement
    open
    diffy

    Gerrit Bot (Gerrit)

    unread,
    May 9, 2024, 2:47:09 PM5/9/24
    to Alex Eaton, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Alex Eaton, Ian Lance Taylor, Keith Randall and Michael Knyszek

    Gerrit Bot uploaded new patchset

    Gerrit Bot uploaded patch set #5 to this change.
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Alex Eaton
    • Ian Lance Taylor
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 5
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-CC: Alex Eaton <1800...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Alex Eaton <1800...@gmail.com>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    unsatisfied_requirement
    open
    diffy

    Alex Eaton (Gerrit)

    unread,
    May 9, 2024, 2:58:17 PM5/9/24
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Keith Randall, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Ian Lance Taylor, Keith Randall and Michael Knyszek

    Alex Eaton added 2 comments

    File src/runtime/cgo/gcc_libinit.c
    Line 16, Patchset 1:#include <limits.h>
    Ian Lance Taylor . unresolved

    Why include <limits.h> ?

    Alex Eaton

    Good catch, it should have been <features.h>

    Ian Lance Taylor

    <features.h> isn't a standard header file as far as I know. It's unlikely to be present on all operating systems. And it shouldn't be necessary to #include it here, as the other headers are bound to bring it in.

    Alex Eaton

    My mistake, you are correct - removed

    Line 46, Patchset 1:#if defined(__GLIBC__) && !defined(__UCLIBC__)
    Ian Lance Taylor . unresolved

    What about other operating systems that don't use glibc?

    Alex Eaton

    My understanding is that the DT_INIT_ARRAY is optional per https://www.sco.com/developers/gabi/latest/ch5.dynamic.html#init_fini

    So glibc may be the only library that optionally passes these arguments - I know that neither musl/uclibc do however

    Ian Lance Taylor

    glibc is not the only library that passes these arguments. They are also passed on at least some *BSD systems. I think this function must return 1 _except_ for the case of uclibc.

    Alex Eaton

    It seems that musl does defined a macro such as __MUSL__ so an explicit check for __GLIBC__ may be required. I pushed a change to wrap this with __linux__ so I think bsd systems would be unaffected

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Lance Taylor
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 5
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-CC: Alex Eaton <1800...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Thu, 09 May 2024 18:58:09 +0000
    unsatisfied_requirement
    open
    diffy

    Gerrit Bot (Gerrit)

    unread,
    May 9, 2024, 3:00:38 PM5/9/24
    to Alex Eaton, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Ian Lance Taylor, Keith Randall and Michael Knyszek

    Gerrit Bot uploaded new patchset

    Gerrit Bot uploaded patch set #6 to this change.
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Lance Taylor
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 6
    unsatisfied_requirement
    open
    diffy

    Alex Eaton (Gerrit)

    unread,
    May 9, 2024, 3:01:35 PM5/9/24
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Keith Randall, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Ian Lance Taylor, Keith Randall and Michael Knyszek

    Alex Eaton added 1 comment

    File src/runtime/cgo/gcc_libinit.c
    Line 46, Patchset 1:#if defined(__GLIBC__) && !defined(__UCLIBC__)
    Ian Lance Taylor . unresolved

    What about other operating systems that don't use glibc?

    Alex Eaton

    My understanding is that the DT_INIT_ARRAY is optional per https://www.sco.com/developers/gabi/latest/ch5.dynamic.html#init_fini

    So glibc may be the only library that optionally passes these arguments - I know that neither musl/uclibc do however

    Ian Lance Taylor

    glibc is not the only library that passes these arguments. They are also passed on at least some *BSD systems. I think this function must return 1 _except_ for the case of uclibc.

    Alex Eaton

    It seems that musl does defined a macro such as __MUSL__ so an explicit check for __GLIBC__ may be required. I pushed a change to wrap this with __linux__ so I think bsd systems would be unaffected

    Alex Eaton

    typo - there is NOT a macro to detect MUSL and they did that by design
    https://wiki.musl-libc.org/faq.html

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Lance Taylor
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 6
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-CC: Alex Eaton <1800...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Thu, 09 May 2024 19:01:29 +0000
    unsatisfied_requirement
    open
    diffy

    Ian Lance Taylor (Gerrit)

    unread,
    May 9, 2024, 3:14:42 PM5/9/24
    to Alex Eaton, Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Keith Randall, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Keith Randall and Michael Knyszek

    Ian Lance Taylor voted Commit-Queue+1

    Commit-Queue+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
    Gerrit-Change-Number: 584115
    Gerrit-PatchSet: 6
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-CC: Alex Eaton <1800...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Thu, 09 May 2024 19:14:36 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    open
    diffy

    Ian Lance Taylor (Gerrit)

    unread,
    May 9, 2024, 4:53:19 PM5/9/24
    to Alex Eaton, Gerrit Bot, goph...@pubsubhelper.golang.org, Go LUCI, Ian Lance Taylor, Keith Randall, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Alex Eaton, Keith Randall and Michael Knyszek

    Ian Lance Taylor added 5 comments

    File src/runtime/cgo/gcc_libinit.c
    Line 16, Patchset 1:#include <limits.h>
    Ian Lance Taylor . resolved

    Why include <limits.h> ?

    Alex Eaton

    Good catch, it should have been <features.h>

    Ian Lance Taylor

    <features.h> isn't a standard header file as far as I know. It's unlikely to be present on all operating systems. And it shouldn't be necessary to #include it here, as the other headers are bound to bring it in.

    Alex Eaton

    My mistake, you are correct - removed

    Ian Lance Taylor

    Done

    Line 39, Patchset 1:// Detect if using glibc
    Ian Lance Taylor . resolved

    This needs a better comment explaining when it is called and what it does.

    Alex Eaton

    Pushed with more detail, let me know if that is sufficient

    Ian Lance Taylor

    Done

    Line 46, Patchset 1:#if defined(__GLIBC__) && !defined(__UCLIBC__)
    Ian Lance Taylor . unresolved

    What about other operating systems that don't use glibc?

    Alex Eaton

    My understanding is that the DT_INIT_ARRAY is optional per https://www.sco.com/developers/gabi/latest/ch5.dynamic.html#init_fini

    So glibc may be the only library that optionally passes these arguments - I know that neither musl/uclibc do however

    Ian Lance Taylor

    glibc is not the only library that passes these arguments. They are also passed on at least some *BSD systems. I think this function must return 1 _except_ for the case of uclibc.

    Alex Eaton

    It seems that musl does defined a macro such as __MUSL__ so an explicit check for __GLIBC__ may be required. I pushed a change to wrap this with __linux__ so I think bsd systems would be unaffected

    Alex Eaton

    typo - there is NOT a macro to detect MUSL and they did that by design
    https://wiki.musl-libc.org/faq.html

    Ian Lance Taylor

    This nested #if is somewhat confusing. How about something like

    // On Linux systems, uClibc does not pass argc/argv to libraries.
    #define hasSharedArgs !defined(__linux__) || (defined(__GLIBC__) && !defined(__UCLIBC__))

      return hasSharedArgs;
    File src/runtime/os_linux.go
    Line 260, Patchset 6 (Latest): args := unsafe.Pointer(persistentalloc(goarch.PtrSize*4, 0, &memstats.other_sys))
    Ian Lance Taylor . unresolved

    Do we really need to allocate this memory? Perhaps instead anything that might use can check whether the arguments are valid.

    Ian Lance Taylor . unresolved

    Remove trailing whitespace.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Alex Eaton
    • Keith Randall
    • Michael Knyszek
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
      Gerrit-Change-Number: 584115
      Gerrit-PatchSet: 6
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
      Gerrit-CC: Alex Eaton <1800...@gmail.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Alex Eaton <1800...@gmail.com>
      Gerrit-Attention: Michael Knyszek <mkny...@google.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Comment-Date: Thu, 09 May 2024 20:53:12 +0000
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      Nov 20, 2024, 7:49:10 AM11/20/24
      to Alex Eaton, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Alex Eaton, Ian Lance Taylor, Keith Randall and Michael Knyszek

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #7 to this change.
      Following approvals got outdated and were removed:
      • TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Alex Eaton
      • Ian Lance Taylor
      • Keith Randall
      • Michael Knyszek
      Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: newpatchset
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
        Gerrit-Change-Number: 584115
        Gerrit-PatchSet: 7
        Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
        Gerrit-CC: Alex Eaton <1800...@gmail.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Alex Eaton <1800...@gmail.com>
        Gerrit-Attention: Michael Knyszek <mkny...@google.com>
        unsatisfied_requirement
        open
        diffy

        Quentin Quaadgras (Gerrit)

        unread,
        Jan 17, 2026, 6:04:09 PM (15 hours ago) Jan 17
        to Alex Eaton, Gerrit Bot, goph...@pubsubhelper.golang.org, Go LUCI, Ian Lance Taylor, Keith Randall, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Alex Eaton, Ian Lance Taylor, Keith Randall and Michael Knyszek

        Quentin Quaadgras added 1 comment

        Patchset-level comments
        File-level comment, Patchset 7 (Latest):
        Quentin Quaadgras . resolved

        Is it worth reading the program's arguments from proc/self on Linux?

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Alex Eaton
        • Ian Lance Taylor
        • Keith Randall
        • Michael Knyszek
        Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Id8de9d2c21e97ac0ee28328dc69643593aaf54f5
        Gerrit-Change-Number: 584115
        Gerrit-PatchSet: 7
        Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
        Gerrit-CC: Alex Eaton <1800...@gmail.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-CC: Quentin Quaadgras <que...@splizard.com>
        Gerrit-Attention: Keith Randall <k...@golang.org>
        Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Attention: Alex Eaton <1800...@gmail.com>
        Gerrit-Attention: Michael Knyszek <mkny...@google.com>
        Gerrit-Comment-Date: Sat, 17 Jan 2026 23:04:00 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        unsatisfied_requirement
        open
        diffy
        Reply all
        Reply to author
        Forward
        0 new messages