Ian, Thanks for the clarification. To confirm, setting go env CC=clang CXX=clang++, won't be effective for -buildmode option.
On Thursday, 9 September 2021 at 05:23:45 UTC+5:30 Ian Lance Taylor wrote: > On Wed, Sep 8, 2021 at 4:19 AM Thor Odinson > <thorodins...@gmail.com> wrote: > > > > I'm bit confused with this, > > > 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. > > > > Command used to build archive: > > CC=clang go build -buildmode=c-archive -o main.a main.go > > > > I have tried with buildmode=c-archive and linking with C library only > using clang toolchain. > > > > Command used: > > clang test-go.c main.a -lpthread > > > > But, I'm getting undefined symbols from gcc_*: > > > > ld: error: undefined symbol: stderr > > >>> referenced by gcc_libinit.c:29 > > >>> 000006.o:(x_cgo_sys_thread_create) in archive main.a > > >>> referenced by gcc_fatalf.c:17 > > >>> 000005.o:(fatalf) in archive main.a > > >>> referenced by gcc_util.c:18 > > >>> 000012.o:(x_cgo_thread_start) in archive main.a > > > > ld: error: undefined symbol: __errno_location > > >>> referenced by gcc_linux_amd64.c:43 > > >>> 000007.o:(x_cgo_init) in archive main.a > > >>> referenced by gcc_mmap.c:23 > > >>> 000008.o:(x_cgo_mmap) in archive main.a > > >>> referenced by gcc_sigaction.c:62 > > >>> 000010.o:(x_cgo_sigaction) in archive main.a > > clang: error: linker command failed with exit code 1 (use -v to see > invocation) > > > > Is it possible to compile the Go runtime without glibc dependency so I > can use the archive with clang toolchain without relying on gcc > toolchain/glibc ? > > Using -buildmode=c-archive implies a dependency on glibc. > > Does it help if you use the -pthread option with clang? You should > use that option in any case. > > Ian > > > > > > On Wednesday, 8 September 2021 at 01:19:50 UTC+5:30 Ian Lance Taylor > wrote: > >> > >> On Tue, Sep 7, 2021 at 9:25 AM Thor Odinson > >> <thorodins...@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...@googlegroups.com. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/984ec245-11a3-41b9-a362-a899d75d5e74n%40googlegroups.com > . > -- 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/6333e2c4-37e0-4da7-ad23-9080e9592839n%40googlegroups.com.