1*e0c4386eSCy Schubert#! /usr/bin/env perl 2*e0c4386eSCy Schubert# -*- mode: perl; -*- 3*e0c4386eSCy Schubert# Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved. 4*e0c4386eSCy Schubert# 5*e0c4386eSCy Schubert# Licensed under the Apache License 2.0 (the "License"). You may not use 6*e0c4386eSCy Schubert# this file except in compliance with the License. You can obtain a copy 7*e0c4386eSCy Schubert# in the file LICENSE in the source distribution or at 8*e0c4386eSCy Schubert# https://www.openssl.org/source/license.html 9*e0c4386eSCy Schubert 10*e0c4386eSCy Schubert# This is a collection of extra attributes to be used as input for creating 11*e0c4386eSCy Schubert# shared libraries, currently on any Unix variant, including Unix like 12*e0c4386eSCy Schubert# environments on Windows. 13*e0c4386eSCy Schubert 14*e0c4386eSCy Schubertsub detect_gnu_ld { 15*e0c4386eSCy Schubert my @lines = 16*e0c4386eSCy Schubert `$config{CROSS_COMPILE}$config{CC} -Wl,-V /dev/null 2>&1`; 17*e0c4386eSCy Schubert return grep /^GNU ld/, @lines; 18*e0c4386eSCy Schubert} 19*e0c4386eSCy Schubertsub detect_gnu_cc { 20*e0c4386eSCy Schubert my @lines = 21*e0c4386eSCy Schubert `$config{CROSS_COMPILE}$config{CC} -v 2>&1`; 22*e0c4386eSCy Schubert return grep /gcc/, @lines; 23*e0c4386eSCy Schubert} 24*e0c4386eSCy Schubert 25*e0c4386eSCy Schubertmy %shared_info; 26*e0c4386eSCy Schubert%shared_info = ( 27*e0c4386eSCy Schubert 'gnu-shared' => { 28*e0c4386eSCy Schubert shared_ldflag => '-shared -Wl,-Bsymbolic', 29*e0c4386eSCy Schubert shared_sonameflag => '-Wl,-soname=', 30*e0c4386eSCy Schubert }, 31*e0c4386eSCy Schubert 'linux-shared' => sub { 32*e0c4386eSCy Schubert return { 33*e0c4386eSCy Schubert %{$shared_info{'gnu-shared'}}, 34*e0c4386eSCy Schubert shared_defflag => '-Wl,--version-script=', 35*e0c4386eSCy Schubert dso_ldflags => 36*e0c4386eSCy Schubert (grep /(?:^|\s)-fsanitize/, 37*e0c4386eSCy Schubert @{$config{CFLAGS}}, @{$config{cflags}}) 38*e0c4386eSCy Schubert ? '' 39*e0c4386eSCy Schubert : '-Wl,-z,defs', 40*e0c4386eSCy Schubert }; 41*e0c4386eSCy Schubert }, 42*e0c4386eSCy Schubert 'bsd-gcc-shared' => sub { return $shared_info{'linux-shared'}; }, 43*e0c4386eSCy Schubert 'darwin-shared' => { 44*e0c4386eSCy Schubert module_ldflags => '-bundle', 45*e0c4386eSCy Schubert shared_ldflag => '-dynamiclib -current_version $(SHLIB_VERSION_NUMBER) -compatibility_version $(SHLIB_VERSION_NUMBER)', 46*e0c4386eSCy Schubert shared_sonameflag => '-install_name $(libdir)/', 47*e0c4386eSCy Schubert }, 48*e0c4386eSCy Schubert 'cygwin-shared' => { 49*e0c4386eSCy Schubert shared_ldflag => '-shared -Wl,--enable-auto-image-base', 50*e0c4386eSCy Schubert shared_impflag => '-Wl,--out-implib=', 51*e0c4386eSCy Schubert }, 52*e0c4386eSCy Schubert 'mingw-shared' => sub { 53*e0c4386eSCy Schubert return { 54*e0c4386eSCy Schubert %{$shared_info{'cygwin-shared'}}, 55*e0c4386eSCy Schubert # def_flag made to empty string so it still generates 56*e0c4386eSCy Schubert # something 57*e0c4386eSCy Schubert shared_defflag => '', 58*e0c4386eSCy Schubert shared_argfileflag => '@', 59*e0c4386eSCy Schubert }; 60*e0c4386eSCy Schubert }, 61*e0c4386eSCy Schubert 'alpha-osf1-shared' => sub { 62*e0c4386eSCy Schubert return $shared_info{'gnu-shared'} if detect_gnu_ld(); 63*e0c4386eSCy Schubert return { 64*e0c4386eSCy Schubert module_ldflags => '-shared -Wl,-Bsymbolic', 65*e0c4386eSCy Schubert shared_ldflag => '-shared -Wl,-Bsymbolic -set_version $(SHLIB_VERSION_NUMBER)', 66*e0c4386eSCy Schubert }; 67*e0c4386eSCy Schubert }, 68*e0c4386eSCy Schubert 'svr3-shared' => sub { 69*e0c4386eSCy Schubert return $shared_info{'gnu-shared'} if detect_gnu_ld(); 70*e0c4386eSCy Schubert return { 71*e0c4386eSCy Schubert shared_ldflag => '-G', 72*e0c4386eSCy Schubert shared_sonameflag => '-h ', 73*e0c4386eSCy Schubert }; 74*e0c4386eSCy Schubert }, 75*e0c4386eSCy Schubert 'svr5-shared' => sub { 76*e0c4386eSCy Schubert return $shared_info{'gnu-shared'} if detect_gnu_ld(); 77*e0c4386eSCy Schubert return { 78*e0c4386eSCy Schubert shared_ldflag => detect_gnu_cc() ? '-shared' : '-G', 79*e0c4386eSCy Schubert shared_sonameflag => '-h ', 80*e0c4386eSCy Schubert }; 81*e0c4386eSCy Schubert }, 82*e0c4386eSCy Schubert 'solaris-gcc-shared' => sub { 83*e0c4386eSCy Schubert return $shared_info{'linux-shared'} if detect_gnu_ld(); 84*e0c4386eSCy Schubert return { 85*e0c4386eSCy Schubert # Note: we should also have -shared here, but because some 86*e0c4386eSCy Schubert # config targets define it with an added -static-libgcc 87*e0c4386eSCy Schubert # following it, we don't want to change the order. This 88*e0c4386eSCy Schubert # forces all solaris gcc config targets to define shared_ldflag 89*e0c4386eSCy Schubert shared_ldflag => '-Wl,-Bsymbolic', 90*e0c4386eSCy Schubert shared_defflag => "-Wl,-M,", 91*e0c4386eSCy Schubert shared_sonameflag => "-Wl,-h,", 92*e0c4386eSCy Schubert }; 93*e0c4386eSCy Schubert }, 94*e0c4386eSCy Schubert); 95