diff mbox

[libgo,build] Use convenience libraries to create .gox files

Message ID yddwrll86oq.fsf@manam.CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth Jan. 31, 2011, 2:54 p.m. UTC
Prompted by Ralf's suggestion in PR go/47515, I had a look at using
libtool convenience libraries to create .gox files.  This proved to be
remarkably simple, as can be seen below.

Instead of going from .a -> .gox in one step, I'm now creating a libtool
object (via ld -r, effectively, but using libtool) from a libtool
archive, and then use objcopy to extract the .go_export section as .gox.

It would be nice if the second step could be implemented using
e.g. simple-object to avoid the external dependency.  Any suggestions on
how to handle .go_object on non-ELF platforms without named sections
(Tru64 UNIX with ECOFF in my case)?  I suppose I should have a look at
LTO on PE-COFF for ideas.

Testing with Sun ld worked just fine (but had worked before since
Solaris 11 ld implements --whole-archive directly), for both multilibs:
Sun ld detects the word size of the link from the first input object,
and uses that for the whole link.

GNU ld testing failed initially for the 64-bit multilib:

libtool: link: /vol/gcc/obj/gcc-4.6.0-20110128/11-gcc-gas-gld-go/./gcc/collect-ld -r -o crypto/libsubtle.o    --whole-archive crypto/.libs/libsubtle.a --no-whole-archive
/vol/gcc/bin/gld-2.21: Relocatable linking with relocations from format elf64-x86-64-sol2 (sort/.libs/libsort.a(libsort.a.o)) to format elf32-i386-sol2 (sort/libsort.o) is not supported
make[7]: *** [sort/libsort.lo] Error 1

Ultimately, this turned out to be a libtool issue: it doesn't handle
Solaris 2/x86 at all, and Solaris 2/SPARC with GNU ld is incomplete in
that it doesn't account for the new *_sol2 emulations in gld 2.21.  All
this second-guessing the compiler suggests to me that it's a bad idea to
call the linker directly if gcc is in use.

With the patch below (mostly mechanical), I could bootstrap all
languages (with ada and go included) on i386-pc-solaris2.11 with Sun
as/Sun ld, GNU as/Sun ld, and GNU as/GNU ld.

With very few exceptions, both the gcc/testsuite/go* and libgo
testsuites passed for both multilibs.

I suppose I need to submit the libtool patch upstream first (will do so
anyway)?

Ok for mainline after that has been integrated?

	Rainer


2011-01-30  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* Makefile.am (.la.lo): New suffix rule.
	(BUILDGOX): Just call $(OBJCOPY).
	(*.gox): Depend on .lo files.
        * Makefile.in: Regenerate.
	* config/libtool.m4 (*-*-solaris*): Determine GNU ld options for
	64-bit Solaris 2/x86.
	Detect gld 2.21 _sol2 emulations.
	* configure: Regenerate.
diff mbox

Patch

diff -r eb4d48c6f093 libgo/Makefile.am
--- a/libgo/Makefile.am	Sun Jan 30 12:31:01 2011 +0100
+++ b/libgo/Makefile.am	Sun Jan 30 16:26:01 2011 +0100
@@ -2511,284 +2511,283 @@ 
 syscalls/libsyscall.la: syscalls/libsyscall.a
 	$(LINK) syscalls/syscall.lo syscalls/errno.lo
 
-# How to build a .gox file from a .a file.
+# Build a .lo file from a .la file.
+.la.lo:
+	$(LINK) $<
+
+# How to build a .gox file from a .lo file.
 BUILDGOX = \
-	set -e; \
-	rm -f $@.$(OBJEXT); \
-	$(CC) -r -nostdlib -o $@.$(OBJEXT) -Wl,--whole-archive $<; \
-	$(OBJCOPY) -j .go_export $@.$(OBJEXT) $@.tmp; \
-	mv -f $@.tmp $@; \
-	rm -f $@.$(OBJEXT)
+	$(OBJCOPY) -j .go_export $< $@
 
-asn1.gox: asn1/libasn1.a
+asn1.gox: asn1/libasn1.lo
 	$(BUILDGOX)
-big.gox: big/libbig.a
+big.gox: big/libbig.lo
 	$(BUILDGOX)
-bufio.gox: bufio/libbufio.a
+bufio.gox: bufio/libbufio.lo
 	$(BUILDGOX)
-bytes.gox: bytes/libbytes.a
+bytes.gox: bytes/libbytes.lo
 	$(BUILDGOX)
-cmath.gox: cmath/libcmath.a
+cmath.gox: cmath/libcmath.lo
 	$(BUILDGOX)
-ebnf.gox: ebnf/libebnf.a
+ebnf.gox: ebnf/libebnf.lo
 	$(BUILDGOX)
-exec.gox: exec/libexec.a
+exec.gox: exec/libexec.lo
 	$(BUILDGOX)
-expvar.gox: expvar/libexpvar.a
+expvar.gox: expvar/libexpvar.lo
 	$(BUILDGOX)
-flag.gox: flag/libflag.a
+flag.gox: flag/libflag.lo
 	$(BUILDGOX)
-fmt.gox: fmt/libfmt.a
+fmt.gox: fmt/libfmt.lo
 	$(BUILDGOX)
-gob.gox: gob/libgob.a
+gob.gox: gob/libgob.lo
 	$(BUILDGOX)
-hash.gox: hash/libhash.a
+hash.gox: hash/libhash.lo
 	$(BUILDGOX)
-html.gox: html/libhtml.a
+html.gox: html/libhtml.lo
 	$(BUILDGOX)
-http.gox: http/libhttp.a
+http.gox: http/libhttp.lo
 	$(BUILDGOX)
-image.gox: image/libimage.a
+image.gox: image/libimage.lo
 	$(BUILDGOX)
-io.gox: io/libio.a
+io.gox: io/libio.lo
 	$(BUILDGOX)
-json.gox: json/libjson.a
+json.gox: json/libjson.lo
 	$(BUILDGOX)
-log.gox: log/liblog.a
+log.gox: log/liblog.lo
 	$(BUILDGOX)
-math.gox: math/libmath.a
+math.gox: math/libmath.lo
 	$(BUILDGOX)
-mime.gox: mime/libmime.a
+mime.gox: mime/libmime.lo
 	$(BUILDGOX)
-net.gox: net/libnet.a
+net.gox: net/libnet.lo
 	$(BUILDGOX)
-netchan.gox: netchan/libnetchan.a
+netchan.gox: netchan/libnetchan.lo
 	$(BUILDGOX)
-os.gox: os/libos.a
+os.gox: os/libos.lo
 	$(BUILDGOX)
-patch.gox: patch/libpatch.a
+patch.gox: patch/libpatch.lo
 	$(BUILDGOX)
-path.gox: path/libpath.a
+path.gox: path/libpath.lo
 	$(BUILDGOX)
-rand.gox: rand/librand.a
+rand.gox: rand/librand.lo
 	$(BUILDGOX)
-reflect.gox: reflect/libreflect.a
+reflect.gox: reflect/libreflect.lo
 	$(BUILDGOX)
-regexp.gox: regexp/libregexp.a
+regexp.gox: regexp/libregexp.lo
 	$(BUILDGOX)
-rpc.gox: rpc/librpc.a
+rpc.gox: rpc/librpc.lo
 	$(BUILDGOX)
-runtime.gox: runtime/libruntime.a
+runtime.gox: runtime/libruntime.lo
 	$(BUILDGOX)
-scanner.gox: scanner/libscanner.a
+scanner.gox: scanner/libscanner.lo
 	$(BUILDGOX)
-smtp.gox: smtp/libsmtp.a
+smtp.gox: smtp/libsmtp.lo
 	$(BUILDGOX)
-sort.gox: sort/libsort.a
+sort.gox: sort/libsort.lo
 	$(BUILDGOX)
-strconv.gox: strconv/libstrconv.a
+strconv.gox: strconv/libstrconv.lo
 	$(BUILDGOX)
-strings.gox: strings/libstrings.a
+strings.gox: strings/libstrings.lo
 	$(BUILDGOX)
-sync.gox: sync/libsync.a
+sync.gox: sync/libsync.lo
 	$(BUILDGOX)
-syslog.gox: syslog/libsyslog.a
+syslog.gox: syslog/libsyslog.lo
 	$(BUILDGOX)
-syscall.gox: syscalls/libsyscall.a
+syscall.gox: syscalls/libsyscall.lo
 	$(BUILDGOX)
-tabwriter.gox: tabwriter/libtabwriter.a
+tabwriter.gox: tabwriter/libtabwriter.lo
 	$(BUILDGOX)
-template.gox: template/libtemplate.a
+template.gox: template/libtemplate.lo
 	$(BUILDGOX)
-testing.gox: testing/libtesting.a
+testing.gox: testing/libtesting.lo
 	$(BUILDGOX)
-time.gox: time/libtime.a
+time.gox: time/libtime.lo
 	$(BUILDGOX)
-try.gox: try/libtry.a
+try.gox: try/libtry.lo
 	$(BUILDGOX)
-unicode.gox: unicode/libunicode.a
+unicode.gox: unicode/libunicode.lo
 	$(BUILDGOX)
-utf16.gox: utf16/libutf16.a
+utf16.gox: utf16/libutf16.lo
 	$(BUILDGOX)
-utf8.gox: utf8/libutf8.a
+utf8.gox: utf8/libutf8.lo
 	$(BUILDGOX)
-websocket.gox: websocket/libwebsocket.a
+websocket.gox: websocket/libwebsocket.lo
 	$(BUILDGOX)
-xml.gox: xml/libxml.a
+xml.gox: xml/libxml.lo
 	$(BUILDGOX)
 
-archive/tar.gox: archive/libtar.a
+archive/tar.gox: archive/libtar.lo
 	$(BUILDGOX)
-archive/zip.gox: archive/libzip.a
+archive/zip.gox: archive/libzip.lo
 	$(BUILDGOX)
 
-compress/flate.gox: compress/libflate.a
+compress/flate.gox: compress/libflate.lo
 	$(BUILDGOX)
-compress/gzip.gox: compress/libgzip.a
+compress/gzip.gox: compress/libgzip.lo
 	$(BUILDGOX)
-compress/zlib.gox: compress/libzlib.a
+compress/zlib.gox: compress/libzlib.lo
 	$(BUILDGOX)
 
-container/heap.gox: container/libheap.a
+container/heap.gox: container/libheap.lo
 	$(BUILDGOX)
-container/list.gox: container/liblist.a
+container/list.gox: container/liblist.lo
 	$(BUILDGOX)
-container/ring.gox: container/libring.a
+container/ring.gox: container/libring.lo
 	$(BUILDGOX)
-container/vector.gox: container/libvector.a
+container/vector.gox: container/libvector.lo
 	$(BUILDGOX)
 
-crypto/aes.gox: crypto/libaes.a
+crypto/aes.gox: crypto/libaes.lo
 	$(BUILDGOX)
-crypto/block.gox: crypto/libblock.a
+crypto/block.gox: crypto/libblock.lo
 	$(BUILDGOX)
-crypto/blowfish.gox: crypto/libblowfish.a
+crypto/blowfish.gox: crypto/libblowfish.lo
 	$(BUILDGOX)
-crypto/cast5.gox: crypto/libcast5.a
+crypto/cast5.gox: crypto/libcast5.lo
 	$(BUILDGOX)
-crypto/cipher.gox: crypto/libcipher.a
+crypto/cipher.gox: crypto/libcipher.lo
 	$(BUILDGOX)
-crypto/elliptic.gox: crypto/libelliptic.a
+crypto/elliptic.gox: crypto/libelliptic.lo
 	$(BUILDGOX)
-crypto/hmac.gox: crypto/libhmac.a
+crypto/hmac.gox: crypto/libhmac.lo
 	$(BUILDGOX)
-crypto/md4.gox: crypto/libmd4.a
+crypto/md4.gox: crypto/libmd4.lo
 	$(BUILDGOX)
-crypto/md5.gox: crypto/libmd5.a
+crypto/md5.gox: crypto/libmd5.lo
 	$(BUILDGOX)
-crypto/ocsp.gox: crypto/libocsp.a
+crypto/ocsp.gox: crypto/libocsp.lo
 	$(BUILDGOX)
-crypto/rand.gox: crypto/librand.a
+crypto/rand.gox: crypto/librand.lo
 	$(BUILDGOX)
-crypto/rc4.gox: crypto/librc4.a
+crypto/rc4.gox: crypto/librc4.lo
 	$(BUILDGOX)
-crypto/ripemd160.gox: crypto/libripemd160.a
+crypto/ripemd160.gox: crypto/libripemd160.lo
 	$(BUILDGOX)
-crypto/rsa.gox: crypto/librsa.a
+crypto/rsa.gox: crypto/librsa.lo
 	$(BUILDGOX)
-crypto/sha1.gox: crypto/libsha1.a
+crypto/sha1.gox: crypto/libsha1.lo
 	$(BUILDGOX)
-crypto/sha256.gox: crypto/libsha256.a
+crypto/sha256.gox: crypto/libsha256.lo
 	$(BUILDGOX)
-crypto/sha512.gox: crypto/libsha512.a
+crypto/sha512.gox: crypto/libsha512.lo
 	$(BUILDGOX)
-crypto/subtle.gox: crypto/libsubtle.a
+crypto/subtle.gox: crypto/libsubtle.lo
 	$(BUILDGOX)
-crypto/tls.gox: crypto/libtls.a
+crypto/tls.gox: crypto/libtls.lo
 	$(BUILDGOX)
-crypto/twofish.gox: crypto/libtwofish.a
+crypto/twofish.gox: crypto/libtwofish.lo
 	$(BUILDGOX)
-crypto/x509.gox: crypto/libx509.a
+crypto/x509.gox: crypto/libx509.lo
 	$(BUILDGOX)
-crypto/xtea.gox: crypto/libxtea.a
+crypto/xtea.gox: crypto/libxtea.lo
 	$(BUILDGOX)
 
-crypto/openpgp/armor.gox: crypto/openpgp/libarmor.a
+crypto/openpgp/armor.gox: crypto/openpgp/libarmor.lo
 	$(BUILDGOX)
-crypto/openpgp/error.gox: crypto/openpgp/liberror.a
+crypto/openpgp/error.gox: crypto/openpgp/liberror.lo
 	$(BUILDGOX)
-crypto/openpgp/s2k.gox: crypto/openpgp/libs2k.a
+crypto/openpgp/s2k.gox: crypto/openpgp/libs2k.lo
 	$(BUILDGOX)
 
-debug/dwarf.gox: debug/libdwarf.a
+debug/dwarf.gox: debug/libdwarf.lo
 	$(BUILDGOX)
-debug/elf.gox: debug/libelf.a
+debug/elf.gox: debug/libelf.lo
 	$(BUILDGOX)
-debug/gosym.gox: debug/libgosym.a
+debug/gosym.gox: debug/libgosym.lo
 	$(BUILDGOX)
-debug/macho.gox: debug/libmacho.a
+debug/macho.gox: debug/libmacho.lo
 	$(BUILDGOX)
-debug/pe.gox: debug/libpe.a
+debug/pe.gox: debug/libpe.lo
 	$(BUILDGOX)
-debug/proc.gox: debug/libproc.a
+debug/proc.gox: debug/libproc.lo
 	$(BUILDGOX)
 
-encoding/ascii85.gox: encoding/libascii85.a
+encoding/ascii85.gox: encoding/libascii85.lo
 	$(BUILDGOX)
-encoding/base32.gox: encoding/libbase32.a
+encoding/base32.gox: encoding/libbase32.lo
 	$(BUILDGOX)
-encoding/base64.gox: encoding/libbase64.a
+encoding/base64.gox: encoding/libbase64.lo
 	$(BUILDGOX)
-encoding/binary.gox: encoding/libbinary.a
+encoding/binary.gox: encoding/libbinary.lo
 	$(BUILDGOX)
-encoding/git85.gox: encoding/libgit85.a
+encoding/git85.gox: encoding/libgit85.lo
 	$(BUILDGOX)
-encoding/hex.gox: encoding/libhex.a
+encoding/hex.gox: encoding/libhex.lo
 	$(BUILDGOX)
-encoding/line.gox: encoding/libline.a
+encoding/line.gox: encoding/libline.lo
 	$(BUILDGOX)
-encoding/pem.gox: encoding/libpem.a
+encoding/pem.gox: encoding/libpem.lo
 	$(BUILDGOX)
 
-exp/datafmt.gox: exp/libdatafmt.a
+exp/datafmt.gox: exp/libdatafmt.lo
 	$(BUILDGOX)
-exp/draw.gox: exp/libdraw.a
+exp/draw.gox: exp/libdraw.lo
 	$(BUILDGOX)
-exp/eval.gox: exp/libeval.a
+exp/eval.gox: exp/libeval.lo
 	$(BUILDGOX)
 
-go/ast.gox: go/libast.a
+go/ast.gox: go/libast.lo
 	$(BUILDGOX)
-go/doc.gox: go/libdoc.a
+go/doc.gox: go/libdoc.lo
 	$(BUILDGOX)
-go/parser.gox: go/libparser.a
+go/parser.gox: go/libparser.lo
 	$(BUILDGOX)
-go/printer.gox: go/libprinter.a
+go/printer.gox: go/libprinter.lo
 	$(BUILDGOX)
-go/scanner.gox: go/libscanner.a
+go/scanner.gox: go/libscanner.lo
 	$(BUILDGOX)
-go/token.gox: go/libtoken.a
+go/token.gox: go/libtoken.lo
 	$(BUILDGOX)
-go/typechecker.gox: go/libtypechecker.a
+go/typechecker.gox: go/libtypechecker.lo
 	$(BUILDGOX)
 
-hash/adler32.gox: hash/libadler32.a
+hash/adler32.gox: hash/libadler32.lo
 	$(BUILDGOX)
-hash/crc32.gox: hash/libcrc32.a
+hash/crc32.gox: hash/libcrc32.lo
 	$(BUILDGOX)
-hash/crc64.gox: hash/libcrc64.a
+hash/crc64.gox: hash/libcrc64.lo
 	$(BUILDGOX)
 
-http/pprof.gox: http/libpprof.a
+http/pprof.gox: http/libpprof.lo
 	$(BUILDGOX)
 
-image/jpeg.gox: image/libjpeg.a
+image/jpeg.gox: image/libjpeg.lo
 	$(BUILDGOX)
-image/png.gox: image/libpng.a
+image/png.gox: image/libpng.lo
 	$(BUILDGOX)
 
-index/suffixarray.gox: index/libsuffixarray.a
+index/suffixarray.gox: index/libsuffixarray.lo
 	$(BUILDGOX)
 
-io/ioutil.gox: io/libioutil.a
+io/ioutil.gox: io/libioutil.lo
 	$(BUILDGOX)
 
-mime/multipart.gox: mime/libmultipart.a
+mime/multipart.gox: mime/libmultipart.lo
 	$(BUILDGOX)
 
-net/dict.gox: net/libdict.a
+net/dict.gox: net/libdict.lo
 	$(BUILDGOX)
-net/textproto.gox: net/libtextproto.a
+net/textproto.gox: net/libtextproto.lo
 	$(BUILDGOX)
 
-os/inotify.gox: os/libinotify.a
+os/inotify.gox: os/libinotify.lo
 	$(BUILDGOX)
-os/signal.gox: os/libsignal.a
+os/signal.gox: os/libsignal.lo
 	$(BUILDGOX)
 
-rpc/jsonrpc.gox: rpc/libjsonrpc.a
+rpc/jsonrpc.gox: rpc/libjsonrpc.lo
 	$(BUILDGOX)
 
-runtime/debug.gox: runtime/libdebug.a
+runtime/debug.gox: runtime/libdebug.lo
 	$(BUILDGOX)
-runtime/pprof.gox: runtime/libpprof.a
+runtime/pprof.gox: runtime/libpprof.lo
 	$(BUILDGOX)
 
-testing/iotest.gox: testing/libiotest.a
+testing/iotest.gox: testing/libiotest.lo
 	$(BUILDGOX)
-testing/quick.gox: testing/libquick.a
+testing/quick.gox: testing/libquick.lo
 	$(BUILDGOX)
-testing/script.gox: testing/libscript.a
+testing/script.gox: testing/libscript.lo
 	$(BUILDGOX)
 
 if LIBGO_IS_LINUX
diff -r eb4d48c6f093 libgo/config/libtool.m4
--- a/libgo/config/libtool.m4	Sun Jan 30 12:31:01 2011 +0100
+++ b/libgo/config/libtool.m4	Sun Jan 30 16:26:01 2011 +0100
@@ -1,7 +1,7 @@ 
 # libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
 #
 #   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
-#                 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+#                 2006, 2007, 2008, 2009, 2011 Free Software Foundation, Inc.
 #   Written by Gordon Matzigkeit, 1996
 #
 # This file is free software; the Free Software Foundation gives
@@ -1287,14 +1287,27 @@ 
     CFLAGS="$SAVE_CFLAGS"
   fi
   ;;
-sparc*-*solaris*)
+*-*solaris*)
   # Find out which ABI we are using.
   echo 'int i;' > conftest.$ac_ext
   if AC_TRY_EVAL(ac_compile); then
     case `/usr/bin/file conftest.o` in
     *64-bit*)
       case $lt_cv_prog_gnu_ld in
-      yes*) LD="${LD-ld} -m elf64_sparc" ;;
+      yes*)
+        case $host in
+	  i?86-*-solaris*)
+	    LD="${LD-ld} -m elf_x86_64"
+	    ;;
+	  sparc*-*-solaris*)
+	    LD="${LD-ld} -m elf64_sparc"
+	    ;;
+	esac
+	# GNU ld 2.21 introduced _sol2 emulations.  Use them if available.
+	if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then
+	  LD="${LD-ld}_sol2"
+	fi
+	;;
       *)
 	if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
 	  LD="${LD-ld} -64"