Dlopen without Cgo on Darwin (#18296)

457 views
Skip to first unread message

Ivan Trubach

unread,
Dec 13, 2019, 1:55:20 AM12/13/19
to golan...@googlegroups.com
Hi, I’ve stubbled upon issue 18296 (dlopen/dlsym without CGo). The discussion focuses on Linux, but since Go on Darwin already co-exists with libSystem, wouldn’t it be trivial to add Darwin dlopen support to e.g. x/sys/unix?

I’ve also set up a small standalone dlopen demo: https://github.com/tie/dyld

Ian Lance Taylor

unread,
Dec 13, 2019, 2:08:07 AM12/13/19
to Ivan Trubach, golang-nuts
Yes, it's likely doable, and it looks like you've done it. I
recommend that you set that up as a go-gettable package for anyone who
wants to use it. I don't think there is a need for it to live in
x/sys/unix.

Ian

Ivan Trubach

unread,
Dec 13, 2019, 12:17:24 PM12/13/19
to Ian Lance Taylor, golan...@googlegroups.com
Sure, I will. The dyld package should work for dlsym C calls, however I don’t think it’s possible to do callbacks with the functionality runtime exposes (i.e. I am talking about API that sys/windows package provides).

So, yeah, while there is no need for Darwin dlopen in x/sys/unix, we still need callbacks for non-trivial code. And at this point adding Dlopen to sys may come in handy.

Either that, or there is a way to make a callback without Cgo that I don’t know about. I would be grateful for any hints.

Jimmy Tang

unread,
Dec 13, 2019, 4:20:14 PM12/13/19
to golang-nuts
A readme to make it discoverable would be nice as well.

Ivan Trubach

unread,
Dec 13, 2019, 7:10:06 PM12/13/19
to jcf...@gmail.com, golan...@googlegroups.com
I plan to finish FFI (the Call/Invoke method) and add dladdr(3) for the sake of completeness, and then the usual README/LICENSE stuff.

Still not sure what to do about the C to Go callbacks. Though it seems doable now (runtime.cgocallback).

Reply all
Reply to author
Forward
0 new messages