-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: c-shared library compatible with independent Go application #71099
Comments
To use a Go shared library with a Go program, you need to use either |
@ianlancetaylor Will you remove shared build mode soon: #47788 Is there an example of how I can build a shared library and consume it (for Win, Mac and Linux, independently of course) |
I think the consensus on #47788, which is closed, is that we would work toward supporting a single The overall intent is that plugins are the way to build a Go shared library and use it in a Go program. That said, the plugin package unfortunately has a lot of problems. So unfortunately there is not at present any good way to build a Go shared library and use it in a Go program. But it's never going to be the case that using |
What is your actual goal? |
My ultimate goal is to create closed-source package that are written in Go and consumable only by Go applications. I was exploring different options and @ianlancetaylor |
Why is an optional build option that dedepulicates the Go runtime symbols, memory mappings etc be bad? It seems doable and can be used by people who are willing to accept the risks (which can be documented). |
To the best of my knowledge
That was our (really my) attitude about |
I'm assuming you mean |
My apologies, I did mean |
@ianlancetaylor Is there a penchant within the Go team for some way to obfuscate Go packages so that IP can be protected and packages can be sold. Go was originally designed to replace C/C++ according to Rob Pike. C/C++ devs don't have this problem. |
We have actually moved in the other direction. We used to support binary-only packages, but we dropped support for them in the 1.12 release. #28152 I know that people won't find this convincing but my personal experience is that once you ship object files your code is available. There are tools out there that will take the object file and recreate an approximation of the source code from which it was generated. This is more true for Go than for languages like C/C++, because Go stack traces mean that Go object files include comprehensive source file and line number information. The only actual aspect of code that can't be extracted from an object file is the comments. That is not nothing, but it is not a lot. So if you want to somehow protect your code, you need to use licensing agreements, not technical obfuscation measures, simply because technical obfuscation measures do not work. As I say, I know that people won't find that convincing. I'll also add that I would certainly like to make plugins work. But to make them practical is going to take a complete rethink of the current approach, and that is hard. |
@ianlancetaylor Are you saying |
As far as recreating the original source code goes, a shared library provides the same information as an object file. |
@ianlancetaylor Would that be the case of the official |
If you mean: would an official plugin also permit end users to decompile the plugin to get an approximation of the original source code (without comments), then the answer is yes. |
@ianlancetaylor Would it be as easier or harder to decompile an official |
Hi @pjebs, FWIW, in some markets & language ecosystems, it's relatively common for commercially-distributed software to use an obfuscator and not really rely on a "binary" distribution being human unreadable (for example, see here or here). This is mainly for the reasons Ian outlined above -- people can reverse a binary without too much difficulty for almost any language, and some languages make it easier than others. In the Go world, it seems at least some commercial libraries like unipdf are distributed in obfuscated source code form (e.g., see a sample obfuscated unipdf file here). From a brief look, it seems the people behind unipdf might have their own proprietary obfuscator. An open source Go obfuscator that I am somewhat familiar with is https://github.com/burrowers/garble. (4k stars, and the primary maintainer is Daniel Martí, a well-known and prolific Go contributor). The main use case for garble I think is a complete Go binary, but they are also considering tweaking things to be more friendly to obfuscating a Go library whose source is private or purchased, which sounds close to your use case. See burrowers/garble#369 for details. I think legal protections and respect for IP are more meaningful, but in my experience with commercial software, a technical measure can reduce accidental abuse. Distributing a binary or obfuscated source code can both be defeated, but both are enough of an obstacle that both should be roughly equivalent at reducing accidental abuse (and with less plausible deniability for "Oops!", an individual at a company is more concerned about later manager disapproval, or concerned about lawyers within a large company, or at least trigger some consciousness of wrong doing for a lone actor). Also FWIW, personally I think obfuscated source code is a greater obstacle for someone malicious than a normal Go binary (in part because the massive security industry has many, many free & commercial tools for reversing binaries). Based on your questions, I'm assuming there are some commercial interests involved, so perhaps it could be worthwhile to sponsor a garble maintainer to add support for burrowers/garble#369, or you could wait to see if it is implemented. Or maybe there is another Go obfuscator project out there that might be close to what you want. My best guess, though, is that an obfuscated-source code solution is likely much closer than the Go project rethinking how to approach plugins and shared Go libraries and whatnot. Finally, whether or not reducing accidental use is important I think depends on the software, the audience, the marketing strategy, and so on. A more user-friendly license enforcement strategy can literally be a competitive differentiator, or help find users that later turn to paying customers, but that's really for your business to determine what makes most sense. In any event, sorry for the long post, and best of luck. |
With the current implementation of plugins, decompiling a plugin is essentially the same as decompiling a |
Proposal Details
I built a Go library:
I then built a Go application to consume the library:
I used
purego
package to build it to avoid cgo for my application. But the error is the same using cgo in the application.I get a runtime error:
It would be great if
c-shared
libraries could be made to be consumable by other Go applications in some way.I understand it may be something about have the Go runtime running twice causing conflicts.
In the unrelated https://github.com/pkujhd/goloader package (which works as a linker), it does say that it shares the same Go runtime. Maybe some technique used in that package can be borrowed.
Maybe a build option to instruct the Go runtime to use different symbols.
The text was updated successfully, but these errors were encountered: