From c86ddbe61323e371f6ac88728581481a1aa6f0e6 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Fri, 5 Feb 2016 11:47:14 +0100 Subject: [PATCH] Enhance and clear the support of linker flags Some time ago, we had a ex_libs configuration setting that could be divided into lflags and ex_libs. These got divided in two settings, lflags and ex_libs, and the former was interpreted to be general linking flags. Unfortunately, that conclusion wasn't entirely accurate. Most of those linking were meant to end up in a very precise position on the linking command line, just before the spec of libraries the linking depends on. Back to the drawing board, we're diving things further, now having lflags, which are linking flags that aren't depending on command line position, plib_lflags, which are linking flags that should show up just before the spec of libraries to depend on, and finally ex_libs, which is the spec of extra libraries to depend on. Also, documentation is changed in Configurations/README. This was previously forgotten. Reviewed-by: Kurt Roeckx --- Configurations/10-main.conf | 6 ++-- Configurations/99-personal-ben.conf | 2 +- Configurations/README | 46 +++++++++++++++++++++-------- Configure | 12 ++++++-- Makefile.in | 10 ++++--- Makefile.shared | 20 ++++++------- apps/Makefile.in | 5 ++-- crypto/Makefile.in | 2 +- crypto/pkcs7/Makefile.in | 2 +- crypto/ts/Makefile.in | 2 +- engines/Makefile.in | 4 +-- test/Makefile.in | 25 +++++++--------- 12 files changed, 82 insertions(+), 54 deletions(-) diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf index e1c25c0209..c5c1424bdc 100644 --- a/Configurations/10-main.conf +++ b/Configurations/10-main.conf @@ -1345,7 +1345,7 @@ release_cflags => "-O3", thread_cflag => "-D_REENTRANT", sys_id => "MACOSX", - lflags => "-Wl,-search_paths_first", + plib_lflags => "-Wl,-search_paths_first", bn_ops => "BN_LLONG RC4_CHAR", perlasm_scheme => "osx32", dso_scheme => "dlfcn", @@ -1498,7 +1498,7 @@ cc => "$ENV{'CC'}", cflags => "\$(CFLAGS)", thread_cflag => "-D_REENTRANT", - lflags => "\$(LDFLAGS)", + plib_lflags => "\$(LDFLAGS)", ex_libs => "\$(LDLIBS)", bn_ops => "BN_LLONG", dso_scheme => "$ENV{'LIBSSL_dlfcn'}", @@ -1512,7 +1512,7 @@ cc => "$ENV{'CC'}", cflags => "\$(CFLAGS)", thread_cflag => "-D_REENTRANT", - lflags => "\$(LDFLAGS)", + plib_lflags => "\$(LDFLAGS)", ex_libs => "\$(LDLIBS)", bn_ops => "SIXTY_FOUR_BIT_LONG", dso_scheme => "$ENV{'LIBSSL_dlfcn'}", diff --git a/Configurations/99-personal-ben.conf b/Configurations/99-personal-ben.conf index c445199bc5..01d8a2dffa 100644 --- a/Configurations/99-personal-ben.conf +++ b/Configurations/99-personal-ben.conf @@ -83,7 +83,7 @@ cflags => "$gcc_devteam_warn -Wno-language-extension-token -Wno-extended-offsetof -arch x86_64 -O3 -DL_ENDIAN -DMD32_REG_T=int -Wall", thread_cflag => "-D_REENTRANT", sys_id => "MACOSX", - lflags => "-Wl,-search_paths_first", + plib_lflags => "-Wl,-search_paths_first", bn_ops => "SIXTY_FOUR_BIT_LONG", perlasm_scheme => "macosx", dso_scheme => "dlfcn", diff --git a/Configurations/README b/Configurations/README index ecf2b7908b..fb94aa723e 100644 --- a/Configurations/README +++ b/Configurations/README @@ -39,25 +39,22 @@ In each table entry, the following keys are significant: compiling for shared libraries, typically something like "-fPIC". - ld => the linker command, usually not defined + (linking is a complex thing, see [3] below) + ld => Linker command, usually not defined (meaning the compiler command is used instead). (NOTE: this is here for future use, it's not implemented yet) - lflags => the flags that are used at all times when - linking. These can have a % sign in them - showing where the OpenSSL libraries should - appear, otherwise these flags will come - last. So in a typical links situation, - this is a quick table of results: - - "-foo%-bar" > -foo -lssl -lcrypto -bar - "-foo%" > -foo -lssl -lcrypto - "-foo" > -lssl -lcrypto -foo + lflags => Flags that are used when linking apps. + shared_ldflag => Flags that are used when linking shared + or dynamic libraries. + plib_lflags => Extra linking flags to appear just before + the libraries on the command line. + ex_libs => Extra libraries that are needed when + linking. debug_lflags => Like debug_cflags, but used when linking. release_lflags => Like release_cflags, but used when linking. - shared_lflags => Like shared_cflags, but used when linking. ar => The library archive command, the default is "ar". @@ -253,6 +250,31 @@ In each table entry, the following keys are significant: be "(unknown)", in which case the user MUST give some compilation flags to Configure. +[3] OpenSSL has three types of things to link from object files or + static libraries: + + - shared libraries; that would be libcrypto and libssl. + - shared objects (sometimes called dynamic libraries); that would + be the engines. + - applications; those are apps/openssl and all the test apps. + + Very roughly speaking, linking is done like this (words in braces + represent the configuration settings documented at the beginning + of this file): + + shared libraries: + {ld} $(CFLAGS) {shared_ldflag} -shared -o libfoo.so \ + -Wl,--whole-archive libfoo.a -Wl,--no-whole-archive \ + {plib_lflags} -lcrypto {ex_libs} + + shared objects: + {ld} $(CFLAGS) {shared_ldflag} -shared -o libeng.so \ + blah1.o blah2.o {plib_lflags} -lcrypto {ex_libs} + + applications: + {ld} $(CFLAGS) {lflags} -o app \ + app1.o utils.o {plib_lflags} -lssl -lcrypto {ex_libs} + Historically, the target configurations came in form of a string with values separated by colons. This use is deprecated. The string form diff --git a/Configure b/Configure index 56fa31a079..0595e71745 100755 --- a/Configure +++ b/Configure @@ -820,7 +820,8 @@ $config{openssldir} = catdir($config{prefix}, $config{openssldir}) # Allow environment CC to override compiler... $target{cc} = $ENV{CC} || $target{cc}; -# For cflags, lflags and ex_libs, add the debug_ or release_ attributes +# For cflags, lflags, plib_lflags and ex_libs, add the debug_ or release_ +# attributes. # Do it in such a way that no spurious space is appended (hence the grep). $config{cflags} = join(" ", grep { $_ ne "" } ($target{cflags}, @@ -828,6 +829,9 @@ $config{cflags} = join(" ", $config{lflags} = join(" ", grep { $_ ne "" } ($target{lflags}, $target{$build_prefix."lflags"})); +$config{plib_lflags} = join(" ", + grep { $_ ne "" } ($target{plib_lflags}, + $target{$build_prefix."plib_lflags"})); $config{ex_libs} = join(" ", grep { $_ ne "" } ($target{ex_libs}, $target{$build_prefix."ex_libs"})); @@ -1653,7 +1657,8 @@ EOF print "IsMK1MF =", ($target{build_scheme}->[0] eq "mk1mf" ? "yes" : "no"), "\n"; print "CC =$target{cc}\n"; print "CFLAG =$config{cflags}\n"; -print "LFLAGS =$config{lflags}\n"; +print "LFLAG =$config{lflags}\n"; +print "PLIB_LFLAG =$config{plib_lflags}\n"; print "EX_LIBS =$config{ex_libs}\n"; print "CPUID_OBJ =$target{cpuid_obj}\n"; print "BN_ASM =$target{bn_obj}\n"; @@ -2116,10 +2121,13 @@ sub print_table_entry "unistd", "ld", "lflags", + "plib_lflags", "ex_libs", "debug_lflags", + "debug_plib_lflags", "debug_ex_libs", "release_lflags", + "release_plib_lflags", "release_ex_libs", "bn_ops", "cpuid_obj", diff --git a/Makefile.in b/Makefile.in index 85685c52e9..b4b5f0dac5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -62,7 +62,8 @@ CROSS_COMPILE= {- $config{cross_compile_prefix} -} CC= $(CROSS_COMPILE){- $target{cc} -} CFLAG= {- $config{cflags} -} DEPFLAG= {- $config{depflags} -} -LDFLAGS= {- $config{lflags} -} +LDFLAG= {- $config{lflags} -} +PLIB_LDFLAG= {- $config{plib_lflags} -} EX_LIBS= {- $config{ex_libs} -} EXE_EXT= {- $target{exe_extension} -} ARFLAGS= {- $target{arflags} -} @@ -159,7 +160,7 @@ LIBS= libcrypto.a libssl.a SHARED_CRYPTO=libcrypto$(SHLIB_EXT) SHARED_SSL=libssl$(SHLIB_EXT) SHARED_LIBS={- '$(SHARED_CRYPTO) $(SHARED_SSL)' if (!$config{no_shared}) -} -SHARED_LDFLAGS={- $target{shared_ldflag} -} +SHARED_LDFLAG={- $target{shared_ldflag} -} GENERAL= Makefile BASENAME= openssl @@ -209,11 +210,12 @@ BUILDENV= LC_ALL=C PLATFORM='$(PLATFORM)' PROCESSOR='$(PROCESSOR)'\ INSTALLTOP='$(INSTALLTOP)' OPENSSLDIR='$(OPENSSLDIR)' \ LIBDIR='$(LIBDIR)' \ DEPFLAG='$(DEPFLAG)' \ - SHARED_LDFLAGS='$(SHARED_LDFLAGS)' \ + SHARED_LDFLAG='$(SHARED_LDFLAG)' \ ZLIB_INCLUDE='$(ZLIB_INCLUDE)' LIBZLIB='$(LIBZLIB)' \ EXE_EXT='$(EXE_EXT)' SHARED_LIBS='$(SHARED_LIBS)' \ SHLIB_EXT='$(SHLIB_EXT)' SHLIB_TARGET='$(SHLIB_TARGET)' \ - LDFLAGS='$(LDFLAGS)' EX_LIBS='$(EX_LIBS)' \ + LDFLAG='$(LDFLAG)' \ + PLIB_LDFLAG='$(PLIB_LDFLAG)' EX_LIBS='$(EX_LIBS)' \ CPUID_OBJ='$(CPUID_OBJ)' BN_ASM='$(BN_ASM)' \ EC_ASM='$(EC_ASM)' DES_ENC='$(DES_ENC)' \ AES_ENC='$(AES_ENC)' CMLL_ENC='$(CMLL_ENC)' \ diff --git a/Makefile.shared b/Makefile.shared index 70980ade08..d8bd9ed782 100644 --- a/Makefile.shared +++ b/Makefile.shared @@ -11,8 +11,8 @@ CFLAGS=$(CFLAG) # LDFLAGS contains flags to be used when temporary object files (when building # shared libraries) are created, or when an application is linked. # SHARED_LDFLAGS contains flags to be used when the shared library is created. -LDFLAGS= -SHARED_LDFLAGS= +LDFLAGS=$(LDFLAG) +SHARED_LDFLAGS=$(SHARED_LDFLAG) NM=nm @@ -92,7 +92,7 @@ CALC_VERSIONS= \ LINK_APP= \ ( $(SET_X); \ LIBDEPS="$${LIBDEPS:-$(LIBDEPS)}"; \ - LDCMD="$${LDCMD:-$(CC)}"; LDFLAGS="$${LDFLAGS:-$(CFLAGS)}"; \ + LDCMD="$${LDCMD:-$(CC)}"; LDFLAGS="$${LDFLAGS:-$(CFLAGS) $(LDFLAGS)}"; \ LIBPATH=`for x in $$LIBDEPS; do echo $$x; done | sed -e 's/^ *-L//;t' -e d | uniq`; \ LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \ LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \ @@ -153,7 +153,7 @@ DO_GNU_SO=$(CALC_VERSIONS); \ NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX" -DO_GNU_APP=LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBRPATH)" +DO_GNU_APP=LDFLAGS="$(CFLAGS) $(LDFLAGS) -Wl,-rpath,$(LIBRPATH)" #This is rather special. It's a special target with which one can link #applications without bothering with any features that have anything to @@ -203,7 +203,7 @@ link_a.bsd: fi; $(LINK_SO_A) link_app.bsd: @if $(DETECT_GNU_LD); then $(DO_GNU_APP); else \ - LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBPATH)"; \ + LDFLAGS="$(CFLAGS) $(LDFLAGS) -Wl,-rpath,$(LIBPATH)"; \ fi; $(LINK_APP) # For Darwin AKA Mac OS/X (dyld) @@ -357,7 +357,7 @@ link_app.alpha-osf1: @if $(DETECT_GNU_LD); then \ $(DO_GNU_APP); \ else \ - LDFLAGS="$(CFLAGS) -rpath $(LIBRPATH)"; \ + LDFLAGS="$(CFLAGS) $(LDFLAGS) -rpath $(LIBRPATH)"; \ fi; \ $(LINK_APP) @@ -398,7 +398,7 @@ link_app.solaris: @ if $(DETECT_GNU_LD); then \ $(DO_GNU_APP); \ else \ - LDFLAGS="$(CFLAGS) -R $(LIBRPATH)"; \ + LDFLAGS="$(CFLAGS) $(LDFLAGS) -R $(LIBRPATH)"; \ fi; \ $(LINK_APP) @@ -493,7 +493,7 @@ link_a.irix: fi; \ $(LINK_SO_A) link_app.irix: - @LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBRPATH)"; \ + @LDFLAGS="$(CFLAGS) $(LDFLAGS) -Wl,-rpath,$(LIBRPATH)"; \ $(LINK_APP) # 32-bit PA-RISC HP-UX embeds the -L pathname of libs we link with, so @@ -532,7 +532,7 @@ link_a.hpux: $(LINK_SO_A) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX link_app.hpux: @if $(DETECT_GNU_LD); then $(DO_GNU_APP); else \ - LDFLAGS="$(CFLAGS) -Wl,+s,+cdp,../:,+cdp,./:,+b,$(LIBRPATH)"; \ + LDFLAGS="$(CFLAGS) $(LDFLAGS) -Wl,+s,+cdp,../:,+cdp,./:,+b,$(LIBRPATH)"; \ fi; \ $(LINK_APP) @@ -557,7 +557,7 @@ link_a.aix: SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-bexpall,-bnolibpath,-bM:SRE'; \ $(LINK_SO_A_VIA_O) link_app.aix: - LDFLAGS="$(CFLAGS) -Wl,-brtl,-blibpath:$(LIBRPATH):$${LIBPATH:-/usr/lib:/lib}"; \ + LDFLAGS="$(CFLAGS) $(LDFLAGS) -Wl,-brtl,-blibpath:$(LIBRPATH):$${LIBPATH:-/usr/lib:/lib}"; \ $(LINK_APP) diff --git a/apps/Makefile.in b/apps/Makefile.in index 02585a7d2b..966868489d 100644 --- a/apps/Makefile.in +++ b/apps/Makefile.in @@ -11,7 +11,7 @@ MAKEFILE= Makefile PERL= perl RM= rm -f -LDFLAGS= +PLIB_LDFLAG= EX_LIBS= EXE_EXT= @@ -131,7 +131,8 @@ $(EXE): progs.h $(EXE_OBJ) $(DLIBCRYPTO) $(DLIBSSL) LIBRARIES="$(LIBSSL) $(LIBCRYPTO)" ; \ $(MAKE) -f $(TOP)/Makefile.shared -e \ APPNAME=$(EXE) OBJECTS="$(EXE_OBJ)" \ - LIBDEPS="$(LDFLAGS) $$LIBRARIES $(EX_LIBS)" \ + LDFLAG="$(LDFLAG)" \ + LIBDEPS="$(PLIB_LDFLAG) $$LIBRARIES $(EX_LIBS)" \ link_app.$${shlib_target} progs.h: progs.pl Makefile diff --git a/crypto/Makefile.in b/crypto/Makefile.in index 331bbd8954..8d69c28830 100644 --- a/crypto/Makefile.in +++ b/crypto/Makefile.in @@ -18,7 +18,7 @@ RECURSIVE_MAKE= [ -n "$(SDIRS)" ] && for i in $(SDIRS) ; do \ $(MAKE) -e TOP=../.. DIR=$$i INCLUDES='$(INCLUDES)' $$target ) || exit 1; \ done; -LDFLAGS= +PLIB_LDFLAG= EX_LIBS= CFLAGS= $(INCLUDE) $(CFLAG) diff --git a/crypto/pkcs7/Makefile.in b/crypto/pkcs7/Makefile.in index c2ee429efb..973b982303 100644 --- a/crypto/pkcs7/Makefile.in +++ b/crypto/pkcs7/Makefile.in @@ -10,7 +10,7 @@ CFLAG=-g MAKEFILE= Makefile AR= ar r -LDFLAGS= +PLIB_LDFLAG= EX_LIBS= CFLAGS= $(INCLUDES) $(CFLAG) diff --git a/crypto/ts/Makefile.in b/crypto/ts/Makefile.in index 4001e8f3dd..68a3206158 100644 --- a/crypto/ts/Makefile.in +++ b/crypto/ts/Makefile.in @@ -11,7 +11,7 @@ OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl AR= ar r -LDFLAGS= +PLIB_LDFLAG= EX_LIBS= CFLAGS= $(INCLUDES) $(CFLAG) diff --git a/engines/Makefile.in b/engines/Makefile.in index a515dc1664..2207c5cfd5 100644 --- a/engines/Makefile.in +++ b/engines/Makefile.in @@ -15,7 +15,7 @@ AR= ar r PADLOCK_ASM_OBJ= -LDFLAGS= +PLIB_LDFLAG= EX_LIBS= CFLAGS= $(INCLUDES) $(CFLAG) @@ -62,7 +62,7 @@ lib: $(LIBOBJ) $(TESTLIBOBJ) for l in $(LIBNAMES) $(TESTLIBNAMES); do \ $(MAKE) -f ../Makefile.shared -e \ LIBNAME=$$l LIBEXTRAS="e_$$l*.o" \ - LIBDEPS='-L.. -lcrypto $(EX_LIBS)' \ + LIBDEPS='$(PLIB_LDFLAG) -L.. -lcrypto $(EX_LIBS)' \ link_o.$(SHLIB_TARGET); \ done; \ else \ diff --git a/test/Makefile.in b/test/Makefile.in index 96ee8f46fb..5a1839fad2 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -10,10 +10,11 @@ CFLAG= -g MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) PERL= perl -LDFLAGS= +PLIB_LDFLAG= EX_LIBS= #-lnsl -lsocket CFLAGS= $(INCLUDES) $(CFLAG) +LDFLAGS= $(CFLAGS) $(LDFLAG) GENERAL=Makefile maketests.com \ tests.com testenc.com tx509.com trsa.com tcrl.com tsid.com treq.com \ @@ -182,14 +183,16 @@ BUILD_CMD=shlib_target=; if [ -n "$(SHARED_LIBS)" ]; then \ LIBRARIES="$(LIBSSL) $(LIBCRYPTO)"; \ $(MAKE) -f $(TOP)/Makefile.shared -e \ APPNAME=$$target$(EXE_EXT) OBJECTS="$$target.o $$testutil" \ - LIBDEPS="$(LDFLAGS) $$LIBRARIES $(EX_LIBS)" \ + LDFLAG="$(LDFLAG)" \ + LIBDEPS="$(PLIB_LDFLAG) $$LIBRARIES $(EX_LIBS)" \ link_app.$${shlib_target} BUILD_CMD_STATIC=shlib_target=; \ LIBRARIES="$(DLIBSSL) $(DLIBCRYPTO)"; \ $(MAKE) -f $(TOP)/Makefile.shared -e \ APPNAME=$$target$(EXE_EXT) OBJECTS="$$target.o $$testutil" \ - LIBDEPS="$(LDFLAGS) $$LIBRARIES $(EX_LIBS)" \ + LDFLAG="$(LDFLAG)" \ + LIBDEPS="$(PLIB_LDFLAG) $$LIBRARIES $(EX_LIBS)" \ link_app.$${shlib_target} $(RSATEST)$(EXE_EXT): $(RSATEST).o $(DLIBCRYPTO) @@ -244,7 +247,8 @@ FIPS_BUILD_CMD=shlib_target=; if [ -n "$(SHARED_LIBS)" ]; then \ fi; \ $(MAKE) -f $(TOP)/Makefile.shared -e \ CC="$${CC}" APPNAME=$$target$(EXE_EXT) OBJECTS="$$target.o" \ - LIBDEPS="$(LDFLAGS) $$LIBRARIES $(EX_LIBS)" \ + LDFLAG="$(LDFLAG)" \ + LIBDEPS="$(PLIB_LDFLAG) $$LIBRARIES $(EX_LIBS)" \ link_app.$${shlib_target} FIPS_CRYPTO_BUILD_CMD=shlib_target=; if [ -n "$(SHARED_LIBS)" ]; then \ @@ -257,7 +261,8 @@ FIPS_CRYPTO_BUILD_CMD=shlib_target=; if [ -n "$(SHARED_LIBS)" ]; then \ [ "$(FIPSCANLIB)" = "libfips" ] && LIBRARIES="$$LIBRARIES -lfips"; \ $(MAKE) -f $(TOP)/Makefile.shared -e \ CC="$${CC}" APPNAME=$$target$(EXE_EXT) OBJECTS="$$target.o" \ - LIBDEPS="$(LDFLAGS) $$LIBRARIES $(EX_LIBS)" \ + LDFLAG="$(LDFLAG)" \ + LIBDEPS="$(PLIB_LDFLAG) $$LIBRARIES $(EX_LIBS)" \ link_app.$${shlib_target} $(RMDTEST)$(EXE_EXT): $(RMDTEST).o $(DLIBCRYPTO) @@ -368,16 +373,6 @@ $(ASYNCTEST)$(EXE_EXT): $(ASYNCTEST).o $(DTLSV1LISTENTEST)$(EXE_EXT): $(DTLSV1LISTENTEST).o @target=$(DTLSV1LISTENTEST) $(BUILD_CMD) -#$(AESTEST).o: $(AESTEST).c -# $(CC) -c $(CFLAGS) -DINTERMEDIATE_VALUE_KAT -DTRACE_KAT_MCT $(AESTEST).c - -#$(AESTEST)$(EXE_EXT): $(AESTEST).o $(DLIBCRYPTO) -# if [ "$(SHLIB_TARGET)" = "hpux-shared" -o "$(SHLIB_TARGET)" = "darwin-shared" ] ; then \ -# $(CC) -o $(AESTEST)$(EXE_EXT) $(CFLAGS) $(AESTEST).o $(LDFLAGS) $(DLIBCRYPTO) $(EX_LIBS) ; \ -# else \ -# $(CC) -o $(AESTEST)$(EXE_EXT) $(CFLAGS) $(AESTEST).o $(LDFLAGS) $(LIBCRYPTO) $(EX_LIBS) ; \ -# fi - dummytest$(EXE_EXT): dummytest.o $(DLIBCRYPTO) @target=dummytest; $(BUILD_CMD) -- 2.40.0