Subject: pkg/36568: [patch] devel/glib2 linker error on Darwin/OS X with certain linker flags
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <idart@performancedesign.no>
List: pkgsrc-bugs
Date: 06/27/2007 19:45:00
>Number:         36568
>Category:       pkg
>Synopsis:       [patch] devel/glib2 linker error on Darwin/OS X with certain linker flags
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 27 19:45:00 +0000 2007
>Originator:     Idar Tollefsen
>Release:        glib2-2.12.12
>Organization:
Performance Design
>Environment:
Darwin fulcrum.performancedesign.no 8.10.0 Darwin Kernel Version 8.10.0: Wed May 23 16:50:59 PDT 2007; root:xnu-792.21.3~1/RELEASE_PPC Power Macintosh powerpc
>Description:
If "-dead_strip" is used as a linker flag, devel/glib2 fails during linking on Darwin/OS X with messages like "ld: .libs/gatomic.o relocation overflow for relocation entry 0 in section (__TEXT,__text) (displacement too large)". Here's the output:

 gcc -DHAVE_CONFIG_H -I. -I.. -DG_LOG_DOMAIN=\"GLib\" -DG_DISABLE_CAST_CHECKS -DG_DISABLE_DEPRECATED -DGLIB_COMPILATION -DNDEBUG -DPREFIX=\"/usr/pkg\" -DPKGLOCALEDIR=\"share\" -DPKG_SYSCONFDIR=\"/usr/pkg/etc\" -no-cpp-precomp -I/usr/pkg/pkgsrc/devel/glib2/work/.buildlink/include -D_REENTRANT -O2 -Wall -MT gspawn.lo -MD -MP -MF .deps/gspawn.Tpo -c gspawn.c -o gspawn.o >/dev/null 2>&1
/bin/sh ../libtool --mode=link gcc  -DNDEBUG -O2 -I/usr/pkg/include -I/usr/include -Wall  -Wl,-x -Wl,-dead_strip -L/usr/pkg/lib -L/usr/lib -o libglib-2.0.la -rpath /usr/pkg/lib  -version-info 1200:12:1200 -export-dynamic  -export-symbols-regex "^[^_].*" garray.lo gasyncqueue.lo gatomic.lo gbacktrace.lo gbase64.lo gbookmarkfile.lo gcache.lo gcompletion.lo gconvert.lo gdataset.lo gdate.lo gdir.lo gerror.lo gfileutils.lo ghash.lo ghook.lo giochannel.lo gkeyfile.lo glist.lo gmain.lo gmappedfile.lo gmarkup.lo gmem.lo gmessages.lo gnode.lo goption.lo gpattern.lo gprimes.lo gqsort.lo gqueue.lo grel.lo grand.lo gscanner.lo gshell.lo gslice.lo gslist.lo gstdio.lo gstrfuncs.lo gstring.lo gthread.lo gthreadpool.lo gtimer.lo gtree.lo guniprop.lo gutf8.lo gunibreak.lo gunicollate.lo gunidecomp.lo gutils.lo gprintf.lo libcharset/libcharset.la  giounix.lo gspawn.lo  -liconv   -lintl  
generating symbol list for `libglib-2.0.la'
nm  .libs/garray.o .libs/gasyncqueue.o .libs/gatomic.o .libs/gbacktrace.o .libs/gbase64.o .libs/gbookmarkfile.o .libs/gcache.o .libs/gcompletion.o .libs/gconvert.o .libs/gdataset.o .libs/gdate.o .libs/gdir.o .libs/gerror.o .libs/gfileutils.o .libs/ghash.o .libs/ghook.o .libs/giochannel.o .libs/gkeyfile.o .libs/glist.o .libs/gmain.o .libs/gmappedfile.o .libs/gmarkup.o .libs/gmem.o .libs/gmessages.o .libs/gnode.o .libs/goption.o .libs/gpattern.o .libs/gprimes.o .libs/gqsort.o .libs/gqueue.o .libs/grel.o .libs/grand.o .libs/gscanner.o .libs/gshell.o .libs/gslice.o .libs/gslist.o .libs/gstdio.o .libs/gstrfuncs.o .libs/gstring.o .libs/gthread.o .libs/gthreadpool.o .libs/gtimer.o .libs/gtree.o .libs/guniprop.o .libs/gutf8.o .libs/gunibreak.o .libs/gunicollate.o .libs/gunidecomp.o .libs/gutils.o .libs/gprintf.o .libs/giounix.o .libs/gspawn.o  libcharset/.libs/libcharset.a | sed -n -e 's/^.*[        ]\([BCDEGRST][BCDEGRST]*\)[     ][      ]*_\([_A-Za-z][_A-Za-z0-9]*\)$/\1 _\2 \2/p' |
  /usr/bin/sed 's/.* //' | sort | uniq > .libs/libglib-2.0.exp
/usr/bin/egrep -e "^[^_].*" ".libs/libglib-2.0.exp" > ".libs/libglib-2.0.expT"
mv -f ".libs/libglib-2.0.expT" ".libs/libglib-2.0.exp"
rm -fr .libs/libglib-2.0.lax
mkdir .libs/libglib-2.0.lax
rm -fr .libs/libglib-2.0.lax/libcharset.a
mkdir .libs/libglib-2.0.lax/libcharset.a
Extracting /usr/pkg/pkgsrc/devel/glib2/work/glib-2.12.12/glib/libcharset/.libs/libcharset.a
(cd .libs/libglib-2.0.lax/libcharset.a && ar x /usr/pkg/pkgsrc/devel/glib2/work/glib-2.12.12/glib/libcharset/.libs/libcharset.a)
sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < .libs/libglib-2.0.exp > .libs/libglib-2.0-symbols.expsym
gcc -dynamiclib ${wl}-undefined ${wl}dynamic_lookup -o .libs/libglib-2.0.0.1200.12.dylib  .libs/garray.o .libs/gasyncqueue.o .libs/gatomic.o .libs/gbacktrace.o .libs/gbase64.o .libs/gbookmarkfile.o .libs/gcache.o .libs/gcompletion.o .libs/gconvert.o .libs/gdataset.o .libs/gdate.o .libs/gdir.o .libs/gerror.o .libs/gfileutils.o .libs/ghash.o .libs/ghook.o .libs/giochannel.o .libs/gkeyfile.o .libs/glist.o .libs/gmain.o .libs/gmappedfile.o .libs/gmarkup.o .libs/gmem.o .libs/gmessages.o .libs/gnode.o .libs/goption.o .libs/gpattern.o .libs/gprimes.o .libs/gqsort.o .libs/gqueue.o .libs/grel.o .libs/grand.o .libs/gscanner.o .libs/gshell.o .libs/gslice.o .libs/gslist.o .libs/gstdio.o .libs/gstrfuncs.o .libs/gstring.o .libs/gthread.o .libs/gthreadpool.o .libs/gtimer.o .libs/gtree.o .libs/guniprop.o .libs/gutf8.o .libs/gunibreak.o .libs/gunicollate.o .libs/gunidecomp.o .libs/gutils.o .libs/gprintf.o .libs/giounix.o .libs/gspawn.o  .libs/libglib-2.0.lax/libcharset.a/localcharset.o   -L/u
 sr/pkg/pkgsrc/devel/glib2/work/.buildlink/lib -lc /usr/lib/libiconv.dylib /usr/pkg/pkgsrc/devel/glib2/work/.buildlink/lib/libintl.dylib /usr/lib/libc.dylib  -Wl,-x -Wl,-dead_strip -install_name  /usr/pkg/lib/libglib-2.0.0.dylib -Wl,-compatibility_version -Wl,1201 -Wl,-current_version -Wl,1201.12
ld: warning multiple definitions of symbol _locale_charset
/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/../../../libiconv.dylib(localcharset.o) definition of _locale_charset
/usr/pkg/pkgsrc/devel/glib2/work/.buildlink/lib/libintl.dylib(localcharset.o) definition of _locale_charset
ld: .libs/gatomic.o relocation overflow for relocation entry 0 in section (__TEXT,__text) (displacement too large)
ld: .libs/gatomic.o relocation overflow for relocation entry 1 in section (__TEXT,__text) (displacement too large)
ld: .libs/gatomic.o relocation overflow for relocation entry 2 in section (__TEXT,__text) (displacement too large)
ld: .libs/gatomic.o relocation overflow for relocation entry 3 in section (__TEXT,__text) (displacement too large)
/usr/bin/libtool: internal link edit command failed
gnumake[4]: *** [libglib-2.0.la] Error 1
gnumake[3]: *** [all-recursive] Error 1
gnumake[2]: *** [all] Error 2
gnumake[1]: *** [all-recursive] Error 1
gnumake: *** [all] Error 2
*** Error code 2

Stop.
bmake: stopped in /usr/pkg/pkgsrc/devel/glib2
*** Error code 1

Stop.
bmake: stopped in /usr/pkg/pkgsrc/devel/glib2

>How-To-Repeat:
On Darwin/OS X, add "-Wl,-dead_strip" to LDFLAGS in mk.conf. Then try to build devel/glib2.
>Fix:
Remove -dead_strip from LDFLAGS. Here's a patch against devel/glib2/Makefile. It also adds xgettext to USE_TOOLS to pull this into the build tree as glib2 uses it as it uses msgfmt that's allready part of USE_TOOLS.

--- Makefile.orig	2007-06-24 14:06:44.000000000 +0200
+++ Makefile	2007-06-27 19:18:39.000000000 +0200
@@ -16,7 +16,7 @@
 PKG_DESTDIR_SUPPORT=	user-destdir
 
 USE_PKGLOCALEDIR=	yes
-USE_TOOLS+=		gmake msgfmt perl:run pkg-config
+USE_TOOLS+=		gmake msgfmt xgettext perl:run pkg-config
 USE_LANGUAGES=		c c++ c99
 USE_LIBTOOL=		yes
 TEST_TARGET=		check
@@ -71,6 +71,10 @@
 CONFIGURE_ENV+=		gt_cv_c_wchar_t=no
 .endif
 
+.if ${OPSYS} == "Darwin" && ${PKGSRC_COMPILER} == "gcc"
+LDFLAGS:=	${LDFLAGS:N-Wl,-dead_strip}
+.endif
+
 # Handle directories shared with devel/glib.
 PRINT_PLIST_AWK+=	/^@dirrm include\/glib$$/ \
 				{ print "@unexec $${RMDIR} %D/" $$2 \