Documentation/tutorials on building and including precompiled .syso files in packages

729 views
Skip to first unread message

jc...@protonmail.com

unread,
Oct 28, 2018, 4:21:16 PM10/28/18
to golang-nuts
There is an initiative to remove the requirement of having a C compiler for certain CGO packages and this seems like a somewhat common thing to do, even the Go race condition detector ships as a pre-built C blob in the Go source tree. Yet I can't find any documentation on how to actually do this.

How should .syso files be built? Where should the C code live (Go complains if C source files exist in the package directory)? How does the Go linker find the correct symbols? Is there any concrete documentation or a tutorial on how to do this?

Ian Lance Taylor

unread,
Oct 30, 2018, 12:33:21 AM10/30/18
to jc...@protonmail.com, golang-nuts
There are no guidelines for how to build .syso files, and the C code
can live anywhere. The .syso file will be built by some mechanism
other than the go tool, such as make. The .syso file can be copied
into the Go package. It will be linked into the Go program. A
typical use would involve using cgo (https://golang.org/cmd/cgo) to
call into the .syso.

Ian

jc...@protonmail.com

unread,
Dec 4, 2018, 9:22:35 AM12/4/18
to golang-nuts
I'm very sorry for replying to this old thread, I forgot to post a reply earlier.

Unfortunately your reply doesn't really explain much that I didn't already know. Simply put, I have two questions.

Firstly, can precompiled .syso files be used to obviate the need for a C-compiler entirely for the package user, or will you still need a C-compiler and/or linker if a Go package has .syso files?

Secondly, is there a concrete example of a project where some source files are compiled into a .syso file? If someone could just point me to a makefile, that would probably show me all I need to know. I recall seeing some .syso files in the compiler source tree but could not find a makefile or sources for them.

Ian Lance Taylor

unread,
Dec 4, 2018, 11:02:15 AM12/4/18
to jc...@protonmail.com, golang-nuts
On Tue, Dec 4, 2018 at 6:22 AM jclc via golang-nuts
<golan...@googlegroups.com> wrote:
>
> I'm very sorry for replying to this old thread, I forgot to post a reply earlier.
>
> Unfortunately your reply doesn't really explain much that I didn't already know. Simply put, I have two questions.
>
> Firstly, can precompiled .syso files be used to obviate the need for a C-compiler entirely for the package user, or will you still need a C-compiler and/or linker if a Go package has .syso files?

Yes, in general you will need a C compiler if the Go package has .syso
files. The compiler will be run to invoke the C linker.


> Secondly, is there a concrete example of a project where some source files are compiled into a .syso file? If someone could just point me to a makefile, that would probably show me all I need to know. I recall seeing some .syso files in the compiler source tree but could not find a makefile or sources for them.

If it helps, the .syso files in the standard library are built by
https://github.com/llvm-mirror/compiler-rt/blob/master/lib/tsan/go/buildgo.sh
.

Ian

jc...@protonmail.com

unread,
Dec 4, 2018, 12:07:31 PM12/4/18
to golang-nuts
Thank you very much!
Reply all
Reply to author
Forward
Message has been deleted
0 new messages