Commit 47eeaf45 authored by Richard Levitte's avatar Richard Levitte
Browse files

Separate general linking flags from extra libraries

So far, we've placed all extra library related flags together, ending
up in the make variable EX_LIBS.  This turns out to be problematic, as
for example, some compilers don't quite agree with something like
this:

    cc -o foo foo.o -L/whatever -lsomething

They prefer this:

    cc -L/whatever -o foo foo.o -lsomething

IBM's compiler on OS/390 is such a compiler that we know of, and we
have previously handled that as a previous case.

The answer here is to make a more general solution, where linking
options are divided in two parts, where one ends up in LDFLAGS and
the other in EX_LIBS (they corresponds to what is called LDFLAGS and
LDLIBS in the GNU world)

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5033)
parent f720194c
Loading
Loading
Loading
Loading
+5 −11
Changes for Configurations/00-base-templates.conf: 5 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -59,18 +59,12 @@ my %targets=(
        inherit_from    => [ "BASE_common" ],
        template        => 1,

        lflags          =>
            sub { $withargs{zlib_lib} ? "-L".$withargs{zlib_lib} : () },
        ex_libs         =>
            sub {
                unless ($disabled{zlib}) {
                    if (defined($disabled{"zlib-dynamic"})) {
                        if (defined($withargs{zlib_lib})) {
                            return "-L".$withargs{zlib_lib}." -lz";
                        } else {
                            return "-lz";
                        }
                    }
                }
                return (); },
            sub { !defined($disabled{zlib})
                  && defined($disabled{"zlib-dynamic"})
                  ? "-lz" : () },

        build_scheme    => [ "unified", "unix" ],
        build_file      => "Makefile",
+16 −12
Changes for Configurations/10-main.conf: 16 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ my %targets = (
                                   release => "-O3"),
        thread_scheme    => "(unknown)",
        sys_id           => "VOS",
        lflags           => "-Wl,-map",
        lflags           => add("-Wl,-map"),
        bn_ops           => "BN_LLONG",
        shared_extension => ".so",
    },
@@ -564,7 +564,8 @@ my %targets = (
        cc               => "gcc",
        cflags           => "-D_ENDIAN -DBN_DIV2W -O3 -D_POSIX_SOURCE -D_SOCKET_SOURCE -I/SYSLOG/PUB",
        sys_id           => "MPE",
        ex_libs          => add("-L/SYSLOG/PUB -lsyslog -lsocket -lcurses"),
        lflags           => add("-L/SYSLOG/PUB"),
        ex_libs          => add("-lsyslog -lsocket -lcurses"),
        thread_scheme    => "(unknown)",
        bn_ops           => "BN_LLONG",
    },
@@ -1384,10 +1385,10 @@ my %targets = (
                                     : " /MC"; }),
                   debug   => "/Od -DDEBUG -D_DEBUG",
                   release => "/O1i"),
        lflags           => combine("/nologo /opt:ref",
        lflags           => add(combine("/nologo /opt:ref",
                                        sub { vc_wince_info()->{lflags}; },
                                        sub { defined(env('PORTSDK_LIBPATH'))
                                              ? "/entry:mainCRTstartup" : (); }),
                                                  ? "/entry:mainCRTstartup" : (); })),
        sys_id           => "WINCE",
        bn_ops           => "BN_LLONG EXPORT_VAR_AS_FN",
        ex_libs          => add(sub {
@@ -1639,49 +1640,51 @@ my %targets = (
        cc               => "ccppc",
        cflags           => "-D_REENTRANT -mrtp -mhard-float -mstrict-align -fno-implicit-fp -DPPC32_fp60x -O2 -fstrength-reduce -fno-builtin -fno-strict-aliasing -Wall -DCPU=PPC32 -DTOOL_FAMILY=gnu -DTOOL=gnu -I\$(WIND_BASE)/target/usr/h -I\$(WIND_BASE)/target/usr/h/wrn/coreip",
        sys_id           => "VXWORKS",
        ex_libs          => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000 -L \$(WIND_BASE)/target/usr/lib/ppc/PPC32/common"),
        lflags           => add("-L \$(WIND_BASE)/target/usr/lib/ppc/PPC32/common"),
        ex_libs          => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000"),
    },
    "vxworks-ppcgen" => {
        inherit_from     => [ "BASE_unix" ],
        cc               => "ccppc",
        cflags           => "-D_REENTRANT -mrtp -msoft-float -mstrict-align -O1 -fno-builtin -fno-strict-aliasing -Wall -DCPU=PPC32 -DTOOL_FAMILY=gnu -DTOOL=gnu -I\$(WIND_BASE)/target/usr/h -I\$(WIND_BASE)/target/usr/h/wrn/coreip",
        sys_id           => "VXWORKS",
        ex_libs          => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000 -L \$(WIND_BASE)/target/usr/lib/ppc/PPC32/sfcommon"),
        lflags           => add("-L \$(WIND_BASE)/target/usr/lib/ppc/PPC32/sfcommon"),
        ex_libs          => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000"),
    },
    "vxworks-ppc405" => {
        inherit_from     => [ "BASE_unix" ],
        cc               => "ccppc",
        cflags           => "-g -msoft-float -mlongcall -DCPU=PPC405 -I\$(WIND_BASE)/target/h",
        sys_id           => "VXWORKS",
        lflags           => "-r",
        lflags           => add("-r"),
    },
    "vxworks-ppc750" => {
        inherit_from     => [ "BASE_unix" ],
        cc               => "ccppc",
        cflags           => "-ansi -nostdinc -DPPC750 -D_REENTRANT -fvolatile -fno-builtin -fno-for-scope -fsigned-char -Wall -msoft-float -mlongcall -DCPU=PPC604 -I\$(WIND_BASE)/target/h \$(DEBUG_FLAG)",
        sys_id           => "VXWORKS",
        lflags           => "-r",
        lflags           => add("-r"),
    },
    "vxworks-ppc750-debug" => {
        inherit_from     => [ "BASE_unix" ],
        cc               => "ccppc",
        cflags           => "-ansi -nostdinc -DPPC750 -D_REENTRANT -fvolatile -fno-builtin -fno-for-scope -fsigned-char -Wall -msoft-float -mlongcall -DCPU=PPC604 -I\$(WIND_BASE)/target/h -DPEDANTIC -DDEBUG -g",
        sys_id           => "VXWORKS",
        lflags           => "-r",
        lflags           => add("-r"),
    },
    "vxworks-ppc860" => {
        inherit_from     => [ "BASE_unix" ],
        cc               => "ccppc",
        cflags           => "-nostdinc -msoft-float -DCPU=PPC860 -DNO_STRINGS_H -I\$(WIND_BASE)/target/h",
        sys_id           => "VXWORKS",
        lflags           => "-r",
        lflags           => add("-r"),
    },
    "vxworks-simlinux" => {
        inherit_from     => [ "BASE_unix" ],
        cc               => "ccpentium",
        cflags           => "-B\$(WIND_BASE)/host/\$(WIND_HOST_TYPE)/lib/gcc-lib/ -D_VSB_CONFIG_FILE=\"\$(WIND_BASE)/target/lib/h/config/vsbConfig.h\" -DL_ENDIAN -DCPU=SIMLINUX -DTOOL_FAMILY=gnu -DTOOL=gnu -fno-builtin -fno-defer-pop -DNO_STRINGS_H -I\$(WIND_BASE)/target/h -I\$(WIND_BASE)/target/h/wrn/coreip -DOPENSSL_NO_HW_PADLOCK",
        sys_id           => "VXWORKS",
        lflags           => "-r",
        lflags           => add("-r"),
        ranlib           => "ranlibpentium",
    },
    "vxworks-mips" => {
@@ -1690,7 +1693,8 @@ my %targets = (
        cflags           => combine("-mrtp -mips2 -O -G 0 -B\$(WIND_BASE)/host/\$(WIND_HOST_TYPE)/lib/gcc-lib/ -D_VSB_CONFIG_FILE=\"\$(WIND_BASE)/target/lib/h/config/vsbConfig.h\" -DCPU=MIPS32 -msoft-float -mno-branch-likely -DTOOL_FAMILY=gnu -DTOOL=gnu -fno-builtin -fno-defer-pop -DNO_STRINGS_H -I\$(WIND_BASE)/target/usr/h -I\$(WIND_BASE)/target/h/wrn/coreip",
                                    threads("-D_REENTRANT")),
        sys_id           => "VXWORKS",
        ex_libs          => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000 -L \$(WIND_BASE)/target/usr/lib/mips/MIPSI32/sfcommon"),
        lflags           => add("-L \$(WIND_BASE)/target/usr/lib/mips/MIPSI32/sfcommon"),
        ex_libs          => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000"),
        thread_scheme    => "pthreads",
        perlasm_scheme   => "o32",
        ranlib           => "ranlibmips",
+2 −1
Changes for Configurations/50-djgpp.conf: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -8,7 +8,8 @@ my %targets = (
        cc               => "gcc",
        cflags           => "-I/dev/env/WATT_ROOT/inc -DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O2 -Wall",
        sys_id           => "MSDOS",
        ex_libs          => add("-L/dev/env/WATT_ROOT/lib -lwatt"),
        lflags           => add("-L/dev/env/WATT_ROOT/lib"),
        ex_libs          => add("-lwatt"),
        bn_ops           => "BN_LLONG",
        perlasm_scheme   => "a.out",
    },
+29 −13
Changes for Configurations/unix-Makefile.tmpl: 29 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ CFLAGS={- our $cflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config
CFLAGS_Q={- $cflags2 =~ s|([\\"])|\\$1|g; $cflags2 -} {- $config{cflags} -}
CXX= $(CROSS_COMPILE){- $target{cxx} -}
CXXFLAGS={- our $cxxflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $target{cxxflags} -} {- $config{cxxflags} -} -std=c++11
LDFLAGS= {- $target{lflags} -}
LDFLAGS= {- $config{lflags} -} {- $target{lflags} -}
PLIB_LDFLAGS= {- $target{plib_lflags} -}
EX_LIBS= {- $target{ex_libs} -} {- $config{ex_libs} -}
LIB_CFLAGS={- $target{shared_cflag} || "" -}
@@ -944,10 +944,15 @@ EOF
      my $libd = dirname($lib);
      my $libn = basename($lib);
      (my $libname = $libn) =~ s/^lib//;
      my $linklibs = join("", map { my $d = dirname($_);
                                    my $f = basename($_);
      my @linkdirs = ();
      foreach (@{args{deps}}) {
          my $d = dirname($_);
          push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
      }
      my $linkflags = join("", map { "-L$_ " } @linkdirs);
      my $linklibs = join("", map { my $f = basename($_);
                                    (my $l = $f) =~ s/^lib//;
                                    " -L$d -l$l" } @{$args{deps}});
                                    " -l$l" } @{$args{deps}});
      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x }
                 grep { $_ =~ m|\.o$| }
                 @{$args{objs}};
@@ -974,7 +979,7 @@ EOF
# simplest, {libname}\$(SHLIB_EXT_IMPORT) for Windows POSIX layers and
# {libname}\$(SHLIB_EXT_SIMPLE) for the Unix platforms.
$target: $deps
	\$(CC) \$(CFLAGS) \$(LIB_CFLAGS) \$(LIB_LDFLAGS)$shared_soname$shared_imp \\
	\$(CC) \$(CFLAGS) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\
		-o $target_full$shared_def $objs \\
                \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
EOF
@@ -999,10 +1004,15 @@ EOF
      my $dso = $args{lib};
      my $dsod = dirname($dso);
      my $dson = basename($dso);
      my $linklibs = join("", map { my $d = dirname($_);
                                    my $f = basename($_);
      my @linkdirs = ();
      foreach (@{args{deps}}) {
          my $d = dirname($_);
          push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
      }
      my $linkflags = join("", map { "-L$_ " } @linkdirs);
      my $linklibs = join("", map { my $f = basename($_);
                                    (my $l = $f) =~ s/^lib//;
                                    " -L$d -l$l" } @{$args{deps}});
                                    " -l$l" } @{$args{deps}});
      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
      my @deps = compute_lib_depends(@{$args{deps}});
      my $objs = join(" ", @objs);
@@ -1010,7 +1020,7 @@ EOF
      my $target = dso($dso);
      return <<"EOF";
$target: $objs $deps
	\$(CC) \$(CFLAGS) \$(DSO_CFLAGS) \$(DSO_LDFLAGS) \\
	\$(CC) \$(CFLAGS) \$(DSO_CFLAGS) $linkflags\$(DSO_LDFLAGS) \\
		-o $target $objs \\
                \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
EOF
@@ -1034,14 +1044,19 @@ EOF
      my $objs = join(" ", map { (my $x = $_) =~ s|\.o$|$objext|; $x }
                           @{$args{objs}});
      my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
      my @linkdirs = ();
      foreach (@{args{deps}}) {
          next if $_ =~ /\.a$/;
          my $d = dirname($_);
          push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
      }
      my $linkflags = join("", map { "-L$_ " } @linkdirs);
      my $linklibs = join("", map { if ($_ =~ /\.a$/) {
                                        " $_";
                                    } else {
                                        my $d = dirname($_);
                                        my $f = basename($_);
                                        $d = "." if $d eq $f;
                                        (my $l = $f) =~ s/^lib//;
                                        " -L$d -l$l"
                                        " -l$l"
                                    }
                                  } @{$args{deps}});
      my $cmd = '$(CC)';
@@ -1053,7 +1068,8 @@ EOF
      return <<"EOF";
$bin$exeext: $objs $deps
	rm -f $bin$exeext
	\$\${LDCMD:-$cmd} $cmdflags \$(LDFLAGS) \$(BIN_LDFLAGS) -o $bin$exeext $objs \\
	\$\${LDCMD:-$cmd} $cmdflags $linkflags\$(LDFLAGS) \$(BIN_LDFLAGS) \\
		-o $bin$exeext $objs \\
		\$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
EOF
  }
+9 −1
Changes for Configure: 9 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -526,6 +526,7 @@ $config{openssl_algorithm_defines}=[];
$config{openssl_thread_defines}=[];
$config{openssl_sys_defines}=[];
$config{openssl_other_defines}=[];
my $ldflags="";
my $libs="";
my $target="";
$config{options}="";
@@ -729,7 +730,11 @@ while (@argvcopy)
			{
			read_config $1;
			}
		elsif (/^-[lL](.*)$/ or /^-Wl,/)
		elsif (/^-L(.*)$/)
			{
			$ldflags.=$_." ";
			}
		elsif (/^-l(.*)$/ or /^-Wl,/)
			{
			$libs.=$_." ";
			}
@@ -1050,6 +1055,7 @@ $config{build_file} = $target{build_file};
$config{defines} = [];
$config{cflags} = "";
$config{cxxflags} = "";
$config{lflags} = "";
$config{ex_libs} = "";
$config{shared_ldflag} = "";

@@ -1121,6 +1127,7 @@ if (!$disabled{dso} && $target{dso_scheme} ne "")
	}

$config{ex_libs}="$libs$config{ex_libs}" if ($libs ne "");
$config{lflags}="$config{lflags}$ldflags" if ($ldflags ne "");

# If threads aren't disabled, check how possible they are
unless ($disabled{threads}) {
@@ -2176,6 +2183,7 @@ print "DEFINES =",join(" ", @{$target{defines}}, @{$config{defines}}),"\n"
#print "RANLIB        =", $target{ranlib} eq '$(CROSS_COMPILE)ranlib' ?
#                             "$config{cross_compile_prefix}ranlib" :
#                             "$target{ranlib}", "\n";
print "LDFLAGS       =$config{lflags} $target{lflags}\n";
print "EX_LIBS       =$target{ex_libs} $config{ex_libs}\n";

my %builders = (