On Tue, Sep 7, 2021 at 9:25 AM Thor Odinson <thorodinsoraven...@gmail.com> wrote: > > I've built an executable file using Go compiler, but the target environments > loader expects the program sections to be in specific order and fails to > execute. > > As a result, I'm trying to compile the Go source using 'go tool compile' to > generate object files, which I want to link using the clang linker option > instead of 'go tool link'. > > Tried building a archive/shared library using go buildmode option, but this > includes lot of Go runtime in the built library. If I have to link this > library along with other libraries using clang toolchain, this would not > resolve the symbols as the statically built library (built using buildmode) > has glibc dependency. > > " > /usr/lib/llvm-5.0/bin/ld.lld: error: undefined symbol: stderr > >>> referenced by gcc_libinit.c:29 > >>> 000006.o:(x_cgo_sys_thread_create) in archive ./sdlgotest.a > " > > Is there a way to build Go runtime without glibc symbols, so that I can use > the archive without relying on gcc toolchain ?
I'm not aware of any way to do that. The Go compiler generates a Go-specific object file format, which the clang linker does not understand. The normal way to handle this is to use -buildmode=c-archve, which produces an object that the clang linker does understand; however, as you noted, that assumes that the Go code will be linked with C code and more generally with the C library, which I guess you don't want to do. I'm a bit surprised that the ordinary "go build" output doesn't work for you, as the order of sections is the default one. What section ordering do you need? Ian -- 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 on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcX%2B82t9x%2B__msnAqYEdrG5eGnC0SyA4X5i5fyy5xkGvww%40mail.gmail.com.