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: Go application segfaults when calling a symbol in a gcc compiled library #50185
Comments
How do you call the C symbol from Go? Could you share the source code of a complete example? Thanks. |
CC @Helflym |
I do not call
I set a break point in gdb. It looks like
call stack:
If I execute the program without the library preloaded, I see |
Indeed, |
Change https://golang.org/cl/373074 mentions this issue: |
Thanks for your quick response. I tried the fix from the linked review and can confirm that it solves the problem with my reproducer. |
The function asmsyscall6 must follow AIX stack layout. It means that its first local variable must be stored after its arguments area, ie after offset 112. Fixes golang#50185 Change-Id: I897731ddd2a9faad8218443a4c2f4b204ad7e173 Reviewed-on: https://go-review.googlesource.com/c/go/+/373074 Trust: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes, same problem with 1.17.3
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
no segfault, file handle will be leaked but no other problem expected.
What did you see instead?
go application (test) segfaults.
I did some analysis with gdb. The segfaults happens in
/opt/freeware/lib/golang/src/runtime/sys_aix_ppc64.s
, line 57I think this is happening:
R3 is saved in line 40:
and restored in line 57.
The location where R3 was saved gets overriden when
callCfunction
callsclose
. The preloaded librarylibltest.so
provides a symbolclose
which is used. This is expected.gcc creates the following code for
close
inlibltest.so
:The problem is caused in line
The stack is increased by 64 in
<close+4>
, but it is accessed with an offset 112. As far as I see, gcc uses the "parameter save area" which is mentioned in the PPC specification, for example https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#STACK. According to this spec, the parameter save area shall be allocated by the caller. Therefore, the code created by gcc looks valid. Seems like the parameter save area is not allocated in the go code.testfiles.zip
The text was updated successfully, but these errors were encountered: