Skip to content

Shared object / DLL support #254

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

Open
seadra opened this issue Apr 2, 2019 · 11 comments
Open

Shared object / DLL support #254

seadra opened this issue Apr 2, 2019 · 11 comments
Labels
enhancement New feature or request windows

Comments

@seadra
Copy link

seadra commented Apr 2, 2019

gc compiler has -buildmode=c-shared.
With LLVM, this should be possible, no?

@aykevl
Copy link
Member

aykevl commented Apr 2, 2019

Yes, this is certainly possible. It's just that no one has asked for it yet.
It will need the extra -buildmode flag and some extra hooks, like an extra -static flag to the linker and an extra hook to let the compiler emit PIC code instead of static code:

c.machine = target.CreateTargetMachine(config.Triple, config.CPU, "", llvm.CodeGenLevelDefault, llvm.RelocStatic, llvm.CodeModelDefault)

@deadprogram deadprogram added the enhancement New feature or request label Apr 3, 2019
@JasonWeise
Copy link

This would be a great addition.
I am calling a Go library from Rust and would love to see it compiled with TinyGo instead.

Looking forward to this implementation :)

@sowelipililimute
Copy link

Yes, this is certainly possible. It's just that no one has asked for it yet.
It will need the extra -buildmode flag and some extra hooks, like an extra -static flag to the linker and an extra hook to let the compiler emit PIC code instead of static code:

c.machine = target.CreateTargetMachine(config.Triple, config.CPU, "", llvm.CodeGenLevelDefault, llvm.RelocStatic, llvm.CodeModelDefault)

Is adding this really all that needs to be done? Seems like there would be more to do...

@aykevl
Copy link
Member

aykevl commented Jan 13, 2021

It's likely some more plumbing needs to be done but that's the essence of it I think.

@ansiwen
Copy link

ansiwen commented Feb 11, 2022

I'm using go with c-shared for building a small plugin .so, that basically only calls a rest API. So it mainly uses the http client and json parser. Because of the runtime, it's quite big. I think it would be very useful to compile this with tinygo instead.

@riaan-dau
Copy link

We have an existing C-codebase running bare-metal on 32-bit ARM and would like to make use of the -buildmode=c-archive flag to build a static Go library callable from C. Would this be possible if this feature is implemented?

@Jimmy2099
Copy link

Jimmy2099 commented Dec 31, 2022

It's almost 2023, how is going to support generate .dll or .lib

@wayneforrest
Copy link

I am also interested in this feature.

I am using a go .dll / .lib, called from C++; and the DLL is 13MB, while the C++ code is only 1.5MB.

@31
Copy link

31 commented Jan 1, 2024

The Go c-shared support doesn't allow dlclose (or FreeLibrary on Windows), which makes it not ideal for plugins that need to be reloaded. I don't see any reason it'd be easier to support this with TinyGo than Go, but maybe this scenario has more value here? Go issue about this:

@turbolent
Copy link

turbolent commented Nov 25, 2024

Is there a simple way to do this manually at the moment? For example, compile to e.g. .o or .ll, and link the runtime?

@aykevl
Copy link
Member

aykevl commented Nov 30, 2024

Not easily, you'd have to manually initialize the runtime, run package initializers, pass -scheduler=none because there is no scheduler, and make sure the functions aren't being called from more than one place.

Maybe I'll add support for this at some point since there seems to be demand for this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request windows
Projects
None yet
Development

No branches or pull requests