On Wed, May 14, 2025 at 4:17 PM rudeus greyrat <rudeusquagmir...@gmail.com> wrote:
> I am still a beginner in Linux internals so please bear with me. > > I have a ".so" that export "helloworld" function. > > I load the ".so" using CGO by: > > 1. Creating a file descriptor > 2. using ```write``` to write the so to it > > A shared library (".so" file) has a complex structure. You normally create one using a compiler and related tools. For example, the Go compiler can create a .so file from Go source code using a command like go build -buildmode=c-shared -o mylib.so It seems unlikely you are creating a valid .so file by opening an empty file and writing to it unless you are simply copying one .so file to another file. > > 1. Get a handle using ```dlopen``` > 2. Get the address of ```helloworld``` symbol using ```dlsym``` > > The address of "helloworld" is saved in a go variable called ```address``` > > How to call ```address``` ? > > On windows I am able to call address using ```syscall.SyscallN```. On > Linux I tried with > ``` > r1, r2, err := syscall.Syscall(address, 0, 0, 0) > ``` > > And I get "function not implemented" error. > I can't speak to Windows but on Unix like operating systems, such as Linux, a function in a shared library is a user space function, not a kernel entry point. A syscall is the way you call OS kernel functions, not user space functions. I wouldn't expect syscall.Syscall() to work on Windows when passed the address of a function in a DLL. Did you actually confirm that it does work when passed the address of a DLL user space function? In any case this definitely won't work on Linux. I searched for "how to call a function in a shared library in go" in Chrome and the results included an AI generated example of how to do this along with links to many articles and other sources such as StackOverflow. If you're still having problems ask again but show us the source code you wrote and the commands you ran to compile it. -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD_ktVZjfAhtsMoprRs7Fm719EocWM_BwebQvUXcoKnVLg%40mail.gmail.com.