-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: c-shared with LD_PRELOAD does not work for some programs #12465
Comments
A backtrace extracted from a core of
The bug occurs when |
Thanks for the backtrace. This is the Go signal handler receiving a SIGCHLD signal. It's not a problem for getg to return nil in sigtrampgo. That just means that a signal occurred on a non-Go thread. The Go code is going to do some shuffling and eventually raise the signal on a C thread, with the C signal handler installed. That should cause the right thing to happen. However, in this backtrace, the shuffling fails because the sigaltstack system call fails. I think that sigaltstack must be returning EPERM: an attempt was made to change the alternate signal stack while the process was already executing on the alternate signal stack. That could happen if the C program create a thread, called sigaltstack on that thread, and then received a signal. That might explain why you are not seeing a problem with relatively simple programs, but only with relatively complex ones. If that is indeed the problem, the solution may be relatively simple: if sigaltstack fails due to EPERM, we should fetch the current alternative signal stack and use it to set the value of m.gsignal.stack. |
Hi, @ianlancetaylor Thank you very much for your comment. After applying this fix (for commit dab0da), diff --git a/src/runtime/os1_linux.go b/src/runtime/os1_linux.go
index c23dc30..99a2560 100644
--- a/src/runtime/os1_linux.go
+++ b/src/runtime/os1_linux.go
@@ -326,7 +326,15 @@ func getsig(i int32) uintptr {
}
func signalstack(s *stack) {
- var st sigaltstackt
+ var st, oldst sigaltstackt
+ sigaltstack(nil, &oldst)
+ if oldst.ss_flags & _SS_ONSTACK != 0 {
+ if s != nil {
+ s.lo = uintptr(unsafe.Pointer(oldst.ss_sp))
+ s.hi = s.lo + oldst.ss_size
+ }
+ return
+ }
if s == nil {
st.ss_flags = _SS_DISABLE
} else {
diff --git a/src/runtime/os2_linux.go b/src/runtime/os2_linux.go
index 71f36eb..6ce5e40 100644
--- a/src/runtime/os2_linux.go
+++ b/src/runtime/os2_linux.go
@@ -5,6 +5,7 @@
package runtime
const (
+ _SS_ONSTACK = 1
_SS_DISABLE = 2
_NSIG = 65
_SI_USER = 0 However, When I run these ones with gdb, I can get various kinds of strange error messages. Could you please look on this?
|
CL https://golang.org/cl/17903 mentions this issue. |
…dlers Only install signal handlers for synchronous signals that become run-time panics. Set the SA_ONSTACK flag for other signal handlers as needed. Fixes #13028. Update #12465. Update #13034. Update #13042. Change-Id: I28375e70641f60630e10f3c86e24b6e4f8a35cc9 Reviewed-on: https://go-review.googlesource.com/17903 Reviewed-by: Russ Cox <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
Guys, I have the same problem with LD_PRELOAD firefox, google-chrome and some other programs. Is there any solution for that? I appreciate your response in advance. |
I'm trying to make my own LD_PRELOAD-able library like this:
This
example.so
works well with several simple programs such asls
,cat
,cp
and so on.However, some programs such as
firefox
,google-chrome
,gdb
get segfault immediately (or sometimes just get hung up).I suspect this is a bug of the Go runtime.
Anyone can please look on this?
Note that C-implementation seems working well with any program:
The text was updated successfully, but these errors were encountered: