When does golang use libc for syscall implementation

248 views
Skip to first unread message

eme...@gmail.com

unread,
Aug 7, 2020, 1:13:53 AM8/7/20
to golang-nuts
I read somewhere (Very sorry I couldn't get the link now) that golang uses libc to implement syscalls when the code is built in c-shared mode. I want to check if this true. 

I was using a go c-shared library as a plugin in my C code, and I wanted to interpose some of the syscalls. If go really implements the syscalls using libc, it would be easier to implement it, but it doesn't seem go uses libc. At some point I got a deadlock, and the deadlock happens at a point where go implemented the futex syscall without libc (). 
TEXT runtime·futex(SB),NOSPLIT,$0
MOVQ addr+0(FP), DI
MOVL op+8(FP), SI
MOVL val+12(FP), DX
MOVQ ts+16(FP), R10
MOVQ addr2+24(FP), R8
MOVL val3+32(FP), R9
MOVL $SYS_futex, AX
SYSCALL
MOVL AX, ret+40(FP)
   RET
 

Ian Lance Taylor

unread,
Aug 7, 2020, 12:35:49 PM8/7/20
to eme...@gmail.com, golang-nuts
On Thu, Aug 6, 2020 at 10:13 PM <eme...@gmail.com> wrote:
>
> I read somewhere (Very sorry I couldn't get the link now) that golang uses libc to implement syscalls when the code is built in c-shared mode. I want to check if this true.

When writing to this mailing list, please always send code as plain
text or as a link to the Go playground or some other web site. Please
don't send white on black text as it is difficult to read in many
e-mail readers. Thanks.

When using the standard Go compiler, system calls are made in the same
way whether the code is built as -buildmode=c-shared or not. You
didn't mention what platform you are using, but, for example, on
GNU/Linux Go code does not use libc for syscalls, neither for a normal
executable nor for a -buildmode=c-shared shared library.

Ian
Reply all
Reply to author
Forward
0 new messages