[OpenSSL-3.0LTS] bsd.lib.mk don't support build shared library from multipile lib*_pic.a archive

Issue #380 open
Takehiko NOZAKI repo owner created an issue

OpenSSL-3.0 build shared library libcrypto\.so from not only \*.o but multiple PIC archive library(libcommon\.a and libdefault\.a).

bsd\.lib\.mk builds shared library libfoo\.so from PIC archive library libfoo_pic\.a:

lib${LIB}.so.${SHLIB_FULLVERSION}: ${SOLIB} ${DPADD} ${DPLIBC} \
    ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
    ${_MKTARGET_BUILD}
    rm -f lib${LIB}.so.${SHLIB_FULLVERSION}
    ${LIBCC} ${LDLIBC} -Wl,-x -shared ${SHLIB_SHFLAGS} ${_LDFLAGS.lib${LIB}} \
        -o ${.TARGET} ${_LIBLDOPTS} \
        -Wl,--whole-archive ${SOLIB} -Wl,--no-whole-archive ${_LDADD.lib${LIB}}

if shared library depends on another PIC archive library libbar_pic\.a, define

LDADD=libbar_pic.a

but it may not work because of --no-whole-archive linker’s option.

it seems that TNF builds libcommon\.a separately.

# OpenSSL libraries.
SUBDIR+= ${OSSL}libapps ${OSSL}libcommon ${OSSL}libcrypto
SUBDIR+= ${OSSL}libcryptotest ${OSSL}libdes

SUBDIR+= .WAIT  ${OSSL}libssl ${OSSL}liblegacy  # depends on libcrypto, libcommon
SUBDIR+= ${OSSL}engines

and introduce LIBISPRIVATE=pic option to build PIC archive library if library is private and not to be installed(see this commit).

but libcommon_pic.a is not used for libcrypto.so because of bsd\.lib\.mk restriction mentioned above.

they include it’s src\.mk and build \*.{o,po,pico} again.

.include "srcs.inc"
.include "${.CURDIR}/../libdefault/srcs.inc"
CPPFLAGS+= -I${.CURDIR}/../libdefault
CPPFLAGS+= -I${OPENSSLSRC}/providers/common/include
CPPFLAGS+= -I${OPENSSLSRC}/providers/implementations/include
.PATH: ${.CURDIR}/../libdefault
.include "${.CURDIR}/../libcommon/srcs.inc"
.PATH: ${.CURDIR}/../libcommon

so separately building libcommon*.a is completely useless.

Comments (10)

  1. Takehiko NOZAKI reporter

    building *.a archive from another *.a is bit tricky.

    most portable way, extract *.a and create new archive:

    $ ar x libfoo.a
    $ ar x libbar.a
    $ ar crs libbuz.a foo.o bar.o buzz.o
    

    another way, using ar script with -M switch:

    $ ar -M
    AR >CREATE libbuz.a
    AR >ADDLIB libfoo.a
    AR >ADDLIB libbar.a
    AR >ADDMOD buzz.o
    AR >SAVE
    AR >END
    

    but ar script is only for developers who already have scripts written for the MRI “librarian” program, not recomended.

  2. Takehiko NOZAKI reporter

    as far as OpenSSL, libcommon and libdefault are built but only used by libcrypto. why are they separated?

  3. Takehiko NOZAKI reporter
    • changed status to open

    reopen, building apps/openssl there is namespace conflict between apps/engine.c and apps/lib/engine.c(libapps.a).

    so at least libapp.a should be separatedly built.

  4. Takehiko NOZAKI reporter
    $ ar -crsT libbuz.a libfoo.a libbar.a
    

    this concatinnate libfoo.a and libbar.a into libbuz.a(so called thin archive).

    but GNU ar’s -T option is not portable and conflict with TOG’s -T option(use with -x and truncate filename length according os/filesystem limitation).

  5. Takehiko NOZAKI reporter
    .if ${MKARZERO} == "yes"
    _ARFL=crsD
    _ARRANFL=sD
    _INSTRANLIB=
    .else
    _ARFL=crs
    _ARRANFL=s
    _INSTRANLIB=${empty(PRESERVE):?-a "${RANLIB} -t":}
    .endif
    
    # If you change this, please consider reflecting the change in
    # the override in sys/rump/Makefile.rump.
    .if !target(__archivebuild)
    __archivebuild: .USE
            ${_MKTARGET_BUILD}
            rm -f ${.TARGET}
            ${AR} ${_ARFL} ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
    .endif
    

  6. Takehiko NOZAKI reporter
    $ ar -crsT libbar.a *.o libfoo.a
    

    may works but

    ar -crsT libbar.a libfoo.a *.o
    

    may loose some libfoo.a’s object that has same name with *.o, why?

  7. Takehiko NOZAKI reporter

    OpenSSL’s generated Makefile creates libcrypto.a from libcrypto-lib-*.o, libdefault-lib-*.o and libcommon-lib-*.o not from libdefault.a and libcommon.a. *.a is only for building libcrypto.so.

  8. Log in to comment