Commit 4e8b9a35 authored by Daiki Ueno's avatar Daiki Ueno
Browse files

global: define entry point of libgnutls when called as executable



This defines the entry point of the library, which prints the library
information when called as executable:

  $ lib/.libs/libgnutls.so.30.30.0
  GnuTLS 3.7.2
  Copyright (C) 2000-2021 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.
  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
  PARTICULAR PURPOSE.

  Library configuration:
    fips-module-name: ...
    libnettle-soname: libnettle.so.8
    libhogweed-soname: libhogweed.so.6
    libgmp-soname: libgmp.so.10

  Please send bug reports to: bugs@gnutls.org
Signed-off-by: Daiki Ueno's avatarDaiki Ueno <ueno@gnu.org>
parent cb854bcb
......@@ -27,7 +27,7 @@ required_submodules="tests/suite/tls-fuzzer/python-ecdsa tests/suite/tls-fuzzer/
# Those modules are common to lib/ and src/.
common_modules="
alloca attribute byteswap c-ctype c-strcase explicit_bzero fopen-gnu func getline gettext-h gettimeofday hash hash-pjw-bare arpa_inet inet_ntop inet_pton intprops lock memmem-simple minmax netdb netinet_in read-file secure_getenv setsockopt snprintf stdint stpcpy strcase strdup-posix strndup strtok_r strverscmp sys_socket sys_stat sys_types threadlib time_r unistd valgrind-tests vasprintf verify vsnprintf xalloc-oversized
alloca attribute byteswap c-ctype c-strcase explicit_bzero fopen-gnu func getline gettext-h gettimeofday hash hash-pjw-bare arpa_inet inet_ntop inet_pton intprops lock memmem-simple minmax netdb netinet_in noreturn read-file secure_getenv setsockopt snprintf stdint stpcpy strcase strdup-posix strndup strtok_r strverscmp sys_socket sys_stat sys_types threadlib time_r unistd valgrind-tests vasprintf verify vsnprintf xalloc-oversized
"
gnulib_modules="
$common_modules extensions gendocs havelib ldd lib-msvc-compat lib-symbol-versions maintainer-makefile manywarnings pmccabe2html warnings
......
......@@ -767,6 +767,28 @@ gnutls_so=libgnutls.so.`expr "$LT_CURRENT" - "$LT_AGE"`
AC_DEFINE_UNQUOTED([GNUTLS_LIBRARY_SONAME], ["$gnutls_so"], [The soname of gnutls library])
AC_SUBST([gnutls_so])
AC_CHECK_TOOL([READELF], [readelf])
AC_MSG_CHECKING([ELF dynamic linker])
changequote(,)
extract_interp='s/.*program interpreter: \(.*\)\]/\1/p'
changequote([,])
save_LIBS=$LIBS
LIBS="$LIBS $GMP_LIBS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <gmp.h>],[
mpz_t n;
mpz_init(n);])],
[interp=`$READELF -lW conftest$EXEEXT | sed -n "$extract_interp"`])
LIBS=$save_LIBS
if test -n "$interp"; then
AC_DEFINE_UNQUOTED([RUNTIME_LINKER], ["$interp"], [The path to ELF dynamic linker])
else
interp=none
fi
AM_CONDITIONAL(ENABLE_LIB_ENTRY_POINT, test "$interp" != none)
AC_MSG_RESULT($interp)
AC_MSG_CHECKING([whether to build libdane])
AC_ARG_ENABLE(libdane,
AS_HELP_STRING([--disable-libdane],
......
......@@ -213,6 +213,10 @@ else
libgnutls_la_LDFLAGS += -export-symbols-regex '^(gnutls|_gnutls).*'
endif
if ENABLE_LIB_ENTRY_POINT
libgnutls_la_LDFLAGS += -Wl,-e,__libgnutls_main
endif
if ENABLE_MINITASN1
libgnutls_la_LIBADD += minitasn1/libminitasn1.la
else
......
......@@ -38,6 +38,7 @@
#include <fips.h>
#include <atfork.h>
#include <system-keys.h>
#include <noreturn.h>
#include "str.h"
#include "global.h"
......@@ -568,3 +569,49 @@ gnutls_get_library_config(void)
{
return _gnutls_library_config;
}
#ifdef RUNTIME_LINKER
static const char banner_header[] =
PACKAGE_NAME " " PACKAGE_VERSION "\n"
"Copyright (C) 2000-2021 Free Software Foundation, Inc.\n"
"This is free software; see the source for copying conditions.\n"
"There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n"
"PARTICULAR PURPOSE.\n\n";
static const char banner_footer[] =
"\nPlease send bug reports to: " PACKAGE_BUGREPORT "\n";
const char interpreter[] __attribute__ ((section (".interp"))) =
RUNTIME_LINKER;
_GL_NORETURN_FUNC extern void __libgnutls_main (void);
void
__libgnutls_main (void)
{
const gnutls_library_config_st *p;
write(STDOUT_FILENO, banner_header, sizeof(banner_header)-1);
#define MSG "Library configuration:\n"
write(STDOUT_FILENO, MSG, sizeof(MSG)-1);
Please register or sign in to reply
#undef MSG
for (p = _gnutls_library_config; p->name; p++) {
#define MSG " "
write(STDOUT_FILENO, MSG, sizeof(MSG)-1);
#undef MSG
write(STDOUT_FILENO, p->name, strlen(p->name));
#define MSG ": "
write(STDOUT_FILENO, MSG, sizeof(MSG)-1);
#undef MSG
write(STDOUT_FILENO, p->value, strlen(p->value));
#define MSG "\n"
write(STDOUT_FILENO, MSG, sizeof(MSG)-1);
#undef MSG
}
write(STDOUT_FILENO, banner_footer, sizeof(banner_footer)-1);
_exit(0);
}
#endif /* RUNTIME_LINKER */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment