pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkg/48842: Wrong flag for linker to extract all symbols from static archives



On Wed, May 28, 2014 at 1:54 AM, Xiyue Deng <manphiz%gmail.com@localhost> wrote:
> On Wed, May 28, 2014 at 1:50 AM,  <manphiz%gmail.com@localhost> wrote:
>>>Number:         48842
>>>Category:       pkg
>>>Synopsis:       Wrong flag for linker to extract all symbols from static 
>>>archives
>>>Confidential:   no
>>>Severity:       serious
>>>Priority:       high
>>>Responsible:    pkg-manager
>>>State:          open
>>>Class:          change-request
>>>Submitter-Id:   net
>>>Arrival-Date:   Wed May 28 08:50:01 +0000 2014
>>>Originator:     Xiyue Deng
>>>Release:        pkgsrc-current
>>>Organization:
>>>Environment:
>> Darwin Xiyues-MBP.local 13.2.0 Darwin Kernel Version 13.2.0: Thu Apr 17 
>> 23:03:13 PDT 2014; root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64
>>>Description:
>> The flag for linker to extract all symbols from static archives in Darwin is 
>> wrong. It assumes ld is GNU ld which is wrong. The correct flag should be 
>> "-Wl,-force_load". A patch is supplied.
>>>How-To-Repeat:
>>
>>>Fix:
>> $NetBSD$
>>
>> --- mk/platform/Darwin.mk.orig  2013-12-31 11:13:43.000000000 +0000
>> +++ mk/platform/Darwin.mk
>> @@ -120,9 +120,8 @@ _OPSYS_PREFER.linux-pam?=   native
>>  _OPSYS_PREFER.mit-krb5?=       native
>>
>>  # flags passed to the linker to extract all symbols from static archives.
>> -# this is GNU ld.
>> -_OPSYS_WHOLE_ARCHIVE_FLAG=     -Wl,--whole-archive
>> -_OPSYS_NO_WHOLE_ARCHIVE_FLAG=  -Wl,--no-whole-archive
>> +_OPSYS_WHOLE_ARCHIVE_FLAG=     -Wl,-force_load
>> +_OPSYS_NO_WHOLE_ARCHIVE_FLAG=
>>
>>  _OPSYS_CAN_CHECK_SHLIBS=       no # can't use readelf in 
>> check/bsd.check-vars.mk
>>
>>
>
> Forgot to mention, package affected by this issue includes
> libexecinfo. Details see
> http://mail-index.netbsd.org/pkgsrc-users/2014/05/26/msg019743.html.

Besides the previous patch, pkgtools/bootstrap-mk-files also handles
Darwin wrong. I have made several changes, including:

* Add another OBJECT_FMT "MACH-O" in files/mods/bsd.own.mk.in, using
"OS!= uname -s" to detect Darwin and set properly.
* Modify files/Darwin.bsd.lib.mk to align with Darwin customs.
  - Use .dylib instead of .so
  - Versioned shared libraries is named
lib${LIB}.${SHLIB_VERSION}.dylib (This including FULLVERSION and
MAJOR_VERSION)
  - The flag to extract all symbols from static library is "-force_load".
  - A minor fix for lorder as not all objects contain "o" anymore (dylib).

The patches are attached.

Attachment: patch-files-mods-bsd.own.mk.in
Description: Binary data

$NetBSD$

--- pkgtools/bootstrap-mk-files/files/mods/Darwin.bsd.lib.mk.orig       
2013-10-25 13:53:03.000000000 +0000
+++ pkgtools/bootstrap-mk-files/files/mods/Darwin.bsd.lib.mk
@@ -70,9 +70,9 @@ SHLIB_FULLVERSION=${SHLIB_MAJOR}
 
 # add additional suffixes not exported.
 # .po is used for profiling object files.
-# .so is used for PIC object files.
-.SUFFIXES: .out .a .ln .so .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
-.SUFFIXES: .sh .m4 .m
+# .dylib is used for PIC object files.
+.SUFFIXES: .out .a .ln .dylib .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p 
.h
+.SUFFIXES: .sh .m4 .m .so
 
 
 # Set PICFLAGS to cc flags for producing position-independent code,
@@ -80,21 +80,23 @@ SHLIB_FULLVERSION=${SHLIB_MAJOR}
 
 # Data-driven table using make variables to control how shared libraries
 # are built for different platforms and object formats.
-# OBJECT_FMT:          currently either "ELF" or "a.out", from <bsd.own.mk>
+# OBJECT_FMT:          currently either "MACH-O" or "a.out", from <bsd.own.mk>
 # SHLIB_SOVERSION:     version number to be compiled into a shared library
-#                      via -soname. Usualy ${SHLIB_MAJOR} on ELF.
+#                      via -dynamiclib. Usualy ${SHLIB_MAJOR} on MAC-O.
 #                      NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
 #                      [.${SHLIB_TEENY}]]
 # SHLIB_SHFLAGS:       Flags to tell ${LD} to emit shared library.
-#                      with ELF, also set shared-lib version for ld.so.
+#                      with MACH-O, also set shared-lib version.
 # SHLIB_LDSTARTFILE:   support .o file, call C++ file-level constructors
 # SHLIB_LDENDFILE:     support .o file, call C++ file-level destructors
-# FPICFLAGS:           flags for ${FC} to compile .[fF] files to .so objects.
+# FPICFLAGS:           flags for ${FC} to compile .[fF] files to .dylib
+#                      objects.
 # CPPICFLAGS:          flags for ${CPP} to preprocess .[sS] files for ${AS}
-# CPICFLAGS:           flags for ${CC} to compile .[cC] files to .so objects.
+# CPICFLAGS:           flags for ${CC} to compile .[cC] files to .dylib
+#                      objects.
 # CAPICFLAGS           flags for {$CC} to compiling .[Ss] files
-#                      (usually just ${CPPPICFLAGS} ${CPICFLAGS})
-# APICFLAGS:           flags for ${AS} to assemble .[sS] to .so objects.
+#                      (usually just ${CPPPICFLAGS} ${CPICFLAGS})
+# APICFLAGS:           flags for ${AS} to assemble .[sS] to .dylib objects.
 
 .if ${MACHINE_ARCH} == "alpha"
                # Alpha-specific shared library flags
@@ -114,12 +116,12 @@ AINC+=-DABICALLS
 AFLAGS+= -fPIC
 AS+=   -KPIC
 
-.elif ${MACHINE_ARCH} == "vax" && ${OBJECT_FMT} == "ELF"
+.elif ${MACHINE_ARCH} == "vax" && ${OBJECT_FMT} == "MACH-O"
 # On the VAX, all object are PIC by default, not just sharedlibs.
 MKPICLIB= no
 
 .elif (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64") && \
-       ${OBJECT_FMT} == "ELF"
+       ${OBJECT_FMT} == "MACH-O"
 
 FPICFLAGS ?= -fPIC
 CPICFLAGS ?= -fPIC -DPIC
@@ -144,10 +146,10 @@ APICFLAGS?= -k
 
 MKPICLIB?= yes
 
-# Platform-independent linker flags for ELF shared libraries
-.if ${OBJECT_FMT} == "ELF"
+# Platform-independent linker flags for MACH-O shared libraries
+.if ${OBJECT_FMT} == "MACH-O"
 SHLIB_SOVERSION=       ${SHLIB_MAJOR}
-SHLIB_SHFLAGS=         -soname lib${LIB}.so.${SHLIB_SOVERSION}
+SHLIB_SHFLAGS=         -install_name lib${LIB}.${SHLIB_SOVERSION}.dylib
 SHLIB_LDSTARTFILE?=    ${DESTDIR}/usr/lib/crtbeginS.o
 SHLIB_LDENDFILE?=      ${DESTDIR}/usr/lib/crtendS.o
 .endif
@@ -175,7 +177,7 @@ FFLAGS+=    ${FOPTS}
        @rm -f ${.TARGET}.o
 .endif
 
-.c.so:
+.c.dylib:
 .if defined(COPTS) && !empty(COPTS:M*-g*)
        ${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
 .else
@@ -208,7 +210,7 @@ FFLAGS+=    ${FOPTS}
        @rm -f ${.TARGET}.o
 .endif
 
-.cc.so .C.so:
+.cc.dylib .C.dylib:
 .if defined(COPTS) && !empty(COPTS:M*-g*)
        ${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
 .else
@@ -238,7 +240,7 @@ FFLAGS+=    ${FOPTS}
        @rm -f ${.TARGET}.o
 .endif
 
-.f.so:
+.f.dylib:
 .if defined(FOPTS) && !empty(FOPTS:M*-g*)
        ${COMPILE.f} ${FPICFLAGS} ${.IMPSRC} -o ${.TARGET}
 .else
@@ -271,7 +273,7 @@ FFLAGS+=    ${FOPTS}
        @rm -f ${.TARGET}.o
 .endif
 
-.m.so:
+.m.dylib:
 .if defined(OBJCFLAGS) && !empty(OBJCFLAGS:M*-g*)
        ${COMPILE.m} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
 .else
@@ -293,7 +295,7 @@ FFLAGS+=    ${FOPTS}
        @${LD} -r ${.TARGET}.o -o ${.TARGET}
        @rm -f ${.TARGET}.o
 
-.S.so .s.so:
+.S.dylib .s.dylib:
        @echo ${COMPILE.S:Q} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} 
-o ${.TARGET}
        @${COMPILE.S} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o 
${.TARGET}.o
        @${LD} -r ${.TARGET}.o -o ${.TARGET}
@@ -319,10 +321,10 @@ SOLIB=lib${LIB}.a
 .else
 SOLIB=lib${LIB}_pic.a
 _LIBS+=${SOLIB}
-SOBJS+=${OBJS:.o=.so}
+SOBJS+=${OBJS:.o=.dylib}
 .endif
 .if defined(SHLIB_FULLVERSION)
-_LIBS+=lib${LIB}.so.${SHLIB_FULLVERSION}
+_LIBS+=lib${LIB}.${SHLIB_FULLVERSION}.dylib
 .endif
 .endif
 
@@ -346,7 +348,7 @@ realall: ${SRCS} ${ALLOBJS:O} ${_LIBS}
 
 __archivebuild: .USE
        @rm -f ${.TARGET}
-       ${AR} -c -q ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
+       ${AR} -c -q ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} 
${.ALLSRC:M*dylib} | ${TSORT}`
        ${RANLIB} ${.TARGET}
 
 __archiveinstall: .USE
@@ -370,28 +372,28 @@ lib${LIB}_p.a:: ${POBJS} __archivebuild
 lib${LIB}_pic.a:: ${SOBJS} __archivebuild
        @echo building shared object ${LIB} library
 
-lib${LIB}.so.${SHLIB_FULLVERSION}: ${SOLIB} ${DPADD} \
+lib${LIB}.${SHLIB_FULLVERSION}.dylib: ${SOLIB} ${DPADD} \
     ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
        @echo building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\)
-       @rm -f lib${LIB}.so.${SHLIB_FULLVERSION}
+       @rm -f lib${LIB}.${SHLIB_FULLVERSION}.dylib
 .if defined(DESTDIR)
-       $(CC) -nostdlib -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
+       $(CC) -nostdlib -dynamiclib ${SHLIB_SHFLAGS} -o ${.TARGET} \
            ${SHLIB_LDSTARTFILE} \
-           --whole-archive ${SOLIB} \
-           --no-whole-archive ${LDADD} \
+           -force_load ${SOLIB} \
+           ${LDADD} \
            -L${DESTDIR}${LIBDIR} -R${LIBDIR} \
            ${SHLIB_LDENDFILE}
 .else
        $(CC) -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
            ${SHLIB_LDSTARTFILE} \
-           --whole-archive ${SOLIB} --no-whole-archive ${LDADD} \
+           -force_load ${SOLIB} ${LDADD} \
            ${SHLIB_LDENDFILE}
 .endif
-.if ${OBJECT_FMT} == "ELF"
-       ln -sf lib${LIB}.so.${SHLIB_FULLVERSION} lib${LIB}.so.${SHLIB_MAJOR}.tmp
-       mv -f lib${LIB}.so.${SHLIB_MAJOR}.tmp lib${LIB}.so.${SHLIB_MAJOR}
-       ln -sf lib${LIB}.so.${SHLIB_FULLVERSION} lib${LIB}.so.tmp
-       mv -f lib${LIB}.so.tmp lib${LIB}.so
+.if ${OBJECT_FMT} == "MACH-O"
+       ln -sf lib${LIB}.${SHLIB_FULLVERSION}.dylib 
lib${LIB}.${SHLIB_MAJOR}.dylib.tmp
+       mv -f lib${LIB}.${SHLIB_MAJOR}.dylib.tmp lib${LIB}.${SHLIB_MAJOR}.dylib
+       ln -sf lib${LIB}.${SHLIB_FULLVERSION}.dylib lib${LIB}.dylib.tmp
+       mv -f lib${LIB}.dylib.tmp lib${LIB}.dylib
 .endif
 
 .if !empty(LOBJS)
@@ -406,13 +408,13 @@ cleanlib:
        rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
        rm -f lib${LIB}.a ${OBJS}
        rm -f lib${LIB}_p.a ${POBJS}
-       rm -f lib${LIB}_pic.a lib${LIB}.so.* lib${LIB}.so ${SOBJS}
+       rm -f lib${LIB}_pic.a lib${LIB}.dylib.* lib${LIB}.dylib ${SOBJS}
        rm -f llib-l${LIB}.ln ${LOBJS}
 
 .if defined(SRCS)
 afterdepend: .depend
        @(TMP=/tmp/_depend$$$$; \
-           sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
+           sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.dylib \1.ln:/' \
              < .depend > $$TMP; \
            mv $$TMP .depend)
 .endif
@@ -467,31 +469,31 @@ ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib
 .endif
 
 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
-libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_FULLVERSION}
-.PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_FULLVERSION}
+libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.${SHLIB_FULLVERSION}.dylib
+.PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.${SHLIB_FULLVERSION}.dylib
 .if !defined(UPDATE)
-.PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_FULLVERSION}
+.PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.${SHLIB_FULLVERSION}.dylib
 .endif
 
-.if !defined(BUILD) && !make(all) && !make(lib${LIB}.so.${SHLIB_FULLVERSION})
-${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_FULLVERSION}: .MADE
+.if !defined(BUILD) && !make(all) && 
!make(lib${LIB}.${SHLIB_FULLVERSION}.dylib)
+${DESTDIR}${LIBDIR}/lib${LIB}.${SHLIB_FULLVERSION}.dylib: .MADE
 .endif
-${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_FULLVERSION}: 
lib${LIB}.so.${SHLIB_FULLVERSION}
+${DESTDIR}${LIBDIR}/lib${LIB}.${SHLIB_FULLVERSION}.dylib: 
lib${LIB}.${SHLIB_FULLVERSION}.dylib
        ${INSTALL} ${RENAME} ${PRESERVE} ${COPY} ${INSTPRIV} -o ${LIBOWN} \
            -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} ${.TARGET}
 .if ${OBJECT_FMT} == "a.out" && !defined(DESTDIR)
        /sbin/ldconfig -m ${LIBDIR}
 .endif
-.if ${OBJECT_FMT} == "ELF"
-       ln -sf lib${LIB}.so.${SHLIB_FULLVERSION}\
-           ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.tmp
-       mv -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.tmp\
-           ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
+.if ${OBJECT_FMT} == "MACH-O"
+       ln -sf lib${LIB}.${SHLIB_FULLVERSION}.dylib\
+           ${DESTDIR}${LIBDIR}/lib${LIB}.${SHLIB_MAJOR}.dylib.tmp
+       mv -f ${DESTDIR}${LIBDIR}/lib${LIB}.${SHLIB_MAJOR}.dylib.tmp\
+           ${DESTDIR}${LIBDIR}/lib${LIB}.${SHLIB_MAJOR}.dylib
 .if ${MKLINKLIB} != "no"
-       ln -sf lib${LIB}.so.${SHLIB_FULLVERSION}\
-           ${DESTDIR}${LIBDIR}/lib${LIB}.so.tmp
-       mv -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.tmp\
-           ${DESTDIR}${LIBDIR}/lib${LIB}.so
+       ln -sf lib${LIB}.${SHLIB_FULLVERSION}.dylib\
+           ${DESTDIR}${LIBDIR}/lib${LIB}.dylib.tmp
+       mv -f ${DESTDIR}${LIBDIR}/lib${LIB}.dylib.tmp\
+           ${DESTDIR}${LIBDIR}/lib${LIB}.dylib
 .endif
 .endif
 .endif


Home | Main Index | Thread Index | Old Index