From b6d5ba1a9f004d637acac18ae3519fe063b6b5e1 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Tue, 18 Oct 2016 15:11:57 +0100 Subject: [PATCH] Link using -znodelete Instead of deliberately leaking a reference to ourselves, use nodelete which does this more neatly. Only for Linux at the moment. Reviewed-by: Tim Hudson --- Configurations/10-main.conf | 25 +++++++++++++------------ crypto/init.c | 6 +++++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf index 9b4c78fd07..b77efbff51 100644 --- a/Configurations/10-main.conf +++ b/Configurations/10-main.conf @@ -632,7 +632,8 @@ sub vms_info { thread_scheme => "pthreads", dso_scheme => "dlfcn", shared_target => "linux-shared", - shared_cflag => "-fPIC", + shared_cflag => "-fPIC -DOPENSSL_USE_NODELETE", + shared_ldflag => "-znodelete", shared_extension => ".so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", }, "linux-generic64" => { @@ -648,14 +649,14 @@ sub vms_info { inherit_from => [ "linux-generic64", asm("ppc64_asm") ], cflags => add("-m64 -DB_ENDIAN"), perlasm_scheme => "linux64", - shared_ldflag => "-m64", + shared_ldflag => add("-m64"), multilib => "64", }, "linux-ppc64le" => { inherit_from => [ "linux-generic64", asm("ppc64_asm") ], cflags => add("-m64 -DL_ENDIAN"), perlasm_scheme => "linux64le", - shared_ldflag => "-m64", + shared_ldflag => add("-m64"), }, "linux-armv4" => { @@ -711,7 +712,7 @@ sub vms_info { inherit_from => [ "linux-generic32", asm("mips32_asm") ], cflags => add("-mabi=32 -DBN_DIV3W"), perlasm_scheme => "o32", - shared_ldflag => "-mabi=32", + shared_ldflag => add("-mabi=32"), }, # mips32 and mips64 below refer to contemporary MIPS Architecture # specifications, MIPS32 and MIPS64, rather than to kernel bitness. @@ -720,14 +721,14 @@ sub vms_info { cflags => add("-mabi=n32 -DBN_DIV3W"), bn_ops => "SIXTY_FOUR_BIT RC4_CHAR", perlasm_scheme => "n32", - shared_ldflag => "-mabi=n32", + shared_ldflag => add("-mabi=n32"), multilib => "32", }, "linux64-mips64" => { inherit_from => [ "linux-generic64", asm("mips64_asm") ], cflags => add("-mabi=64 -DBN_DIV3W"), perlasm_scheme => "64", - shared_ldflag => "-mabi=64", + shared_ldflag => add("-mabi=64"), multilib => "64", }, @@ -754,7 +755,7 @@ sub vms_info { cflags => add("-m64 -DL_ENDIAN"), bn_ops => "SIXTY_FOUR_BIT_LONG", perlasm_scheme => "elf", - shared_ldflag => "-m64", + shared_ldflag => add("-m64"), multilib => "64", }, "linux-x86_64-clang" => { @@ -781,7 +782,7 @@ sub vms_info { inherit_from => [ "linux-generic64", asm("s390x_asm") ], cflags => add("-m64 -DB_ENDIAN"), perlasm_scheme => "64", - shared_ldflag => "-m64", + shared_ldflag => add("-m64"), multilib => "64", }, "linux32-s390x" => { @@ -805,7 +806,7 @@ sub vms_info { cflags => add("-m31 -Wa,-mzarch -DB_ENDIAN"), bn_asm_src => sub { my $r=join(" ",@_); $r=~s|asm/s390x\.S|bn_asm.c|; $r; }, perlasm_scheme => "31", - shared_ldflag => "-m31", + shared_ldflag => add("-m31"), multilib => "/highgprs", }, @@ -821,14 +822,14 @@ sub vms_info { # but -Wa,-Av8plus should do the trick no matter what. inherit_from => [ "linux-generic32", asm("sparcv9_asm") ], cflags => add("-m32 -mcpu=ultrasparc -Wa,-Av8plus -DB_ENDIAN -DBN_DIV2W"), - shared_ldflag => "-m32", + shared_ldflag => add("-m32"), }, "linux64-sparcv9" => { # GCC 3.1 is a requirement inherit_from => [ "linux-generic64", asm("sparcv9_asm") ], cflags => add("-m64 -mcpu=ultrasparc -DB_ENDIAN"), bn_ops => "BN_LLONG RC4_CHAR", - shared_ldflag => "-m64", + shared_ldflag => add("-m64"), multilib => "64", }, @@ -857,7 +858,7 @@ sub vms_info { dso_scheme => "dlfcn", shared_target => "linux-shared", shared_cflag => "--pic", - shared_ldflag => "-z --sysv --shared", + shared_ldflag => add("-z --sysv --shared"), shared_extension => ".so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", ranlib => "true", }, diff --git a/crypto/init.c b/crypto/init.c index ebc41465d5..cfa0ce0c86 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -81,6 +81,7 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_base) OPENSSL_cpuid_setup(); base_inited = 1; +#ifndef OPENSSL_USE_NODELETE /* * Deliberately leak a reference to ourselves. This will force the library * to remain loaded until the atexit() handler is run a process exit. @@ -91,6 +92,7 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_base) dso = DSO_dsobyaddr(&base_inited, DSO_FLAG_NO_UNLOAD_ON_FREE); DSO_free(dso); } +#endif return 1; } @@ -588,10 +590,11 @@ int OPENSSL_atexit(void (*handler)(void)) { OPENSSL_INIT_STOP *newhand; +#ifndef OPENSSL_USE_NODELETE /* * Deliberately leak a reference to the handler. This will force the * library/code containing the handler to remain loaded until we run the - * atexit handler. + * atexit handler. If -znodelete has been used then this is unneccessary. */ { DSO *dso = NULL; @@ -605,6 +608,7 @@ int OPENSSL_atexit(void (*handler)(void)) dso = DSO_dsobyaddr(handlersym.sym, DSO_FLAG_NO_UNLOAD_ON_FREE); DSO_free(dso); } +#endif newhand = OPENSSL_malloc(sizeof(*newhand)); if (newhand == NULL) -- 2.25.1