From patchwork Thu Jun 4 20:35:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. Murphy" X-Patchwork-Id: 39478 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E648B3851C39; Thu, 4 Jun 2020 20:35:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E648B3851C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1591302910; bh=LdwUyGaOJsxiFrunU5R481YpRmvUA01+ZITwL027I2c=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jNBDtfslOfNg6py/fWi4h+JK1/YdZDY007rh143EsDJ3Z4HsVwHd2U3V8OLXlZynB yljkUZAhAtI7cuNjZ/3rS//vC1ENymY1yqapOy1dU8R6R1X0XrN+l0U8sJ9pxnkZ1b fNPYfFn+ofFnKBq81jzTF2WU83Ig2bcMD44ZXzkk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 0C95C385DC14 for ; Thu, 4 Jun 2020 20:35:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0C95C385DC14 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 054KWWI4058455 for ; Thu, 4 Jun 2020 16:35:05 -0400 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 31efd6537r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 04 Jun 2020 16:35:05 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 054KYXh9002240 for ; Thu, 4 Jun 2020 20:35:04 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma01wdc.us.ibm.com with ESMTP id 31bf49f3af-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 04 Jun 2020 20:35:03 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 054KZ3eI16711946 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 4 Jun 2020 20:35:03 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0B4A2BE051 for ; Thu, 4 Jun 2020 20:35:03 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D5DC8BE04F for ; Thu, 4 Jun 2020 20:35:02 +0000 (GMT) Received: from brokenarrow.ibmuc.com (unknown [9.163.73.2]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP for ; Thu, 4 Jun 2020 20:35:02 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [RFC PATCH 1/2] dlfcn: add long double redirect wrappers for dl*sym Date: Thu, 4 Jun 2020 15:35:01 -0500 Message-Id: <241f0fb69316e533e3fc5025bab74b40bb7ab5c9.1591302826.git.murphyp@linux.vnet.ibm.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-04_13:2020-06-04, 2020-06-04 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 cotscore=-2147483648 malwarescore=0 adultscore=0 spamscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006040142 X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Paul E. Murphy via Libc-alpha" From: "Paul E. Murphy" Reply-To: "Paul E. Murphy" Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Using a non-default long double creates some odd issues when attempting to dynamically load symbols. I am not sure how big an issue this really is, but it is worth putting forth patches to have this discussion. Users of the IEEE128 ldbl will run into ABI problems if they attempt to load symbols which are renamed (mangled via asm redirects). A first attempt here is to mangle lib{c,m,dl} symbol names which are redirected via headers by wrapping dl*sym functions. Given that the renames are not always trivial and may grow with future releases, this is something the end user should not have to do. Prepare to support mangling certain symbol names which can be redirected depending on the choice of long double format the caller object was built against. --- dlfcn/dlerror.c | 4 +-- dlfcn/dlfcn.h | 9 +++++ dlfcn/dlsym.c | 21 ++++++++---- dlfcn/dlvsym.c | 22 ++++++++----- include/dlfcn.h | 10 ++++-- sysdeps/ieee754/ldbl-128ibm-compat/Makefile | 6 ++++ sysdeps/ieee754/ldbl-128ibm-compat/Versions | 7 ++++ .../ldbl-128ibm-compat/ieee128-dlfcn.c | 33 +++++++++++++++++++ .../linux/powerpc/powerpc64/le/libdl.abilist | 2 ++ 9 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-dlfcn.c diff --git a/dlfcn/dlerror.c b/dlfcn/dlerror.c index 0d38a37bf7..b94516af5b 100644 --- a/dlfcn/dlerror.c +++ b/dlfcn/dlerror.c @@ -261,8 +261,8 @@ static struct dlfcn_hook _dlfcn_hooks = { .dlopen = __dlopen, .dlclose = __dlclose, - .dlsym = __dlsym, - .dlvsym = __dlvsym, + .dlsym = __dlsym_internal, + .dlvsym = __dlvsym_internal, .dlerror = __dlerror, .dladdr = __dladdr, .dladdr1 = __dladdr1, diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h index c629fc7f42..baf709375a 100644 --- a/dlfcn/dlfcn.h +++ b/dlfcn/dlfcn.h @@ -64,6 +64,10 @@ extern int dlclose (void *__handle) __THROWNL __nonnull ((1)); extern void *dlsym (void *__restrict __handle, const char *__restrict __name) __THROW __nonnull ((2)); +#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 && defined (__REDIRECT) +__LDBL_REDIR_DECL (dlsym); +#endif + #ifdef __USE_GNU /* Like `dlopen', but request object to be allocated in a new namespace. */ extern void *dlmopen (Lmid_t __nsid, const char *__file, int __mode) __THROWNL; @@ -74,6 +78,11 @@ extern void *dlvsym (void *__restrict __handle, const char *__restrict __name, const char *__restrict __version) __THROW __nonnull ((2, 3)); + +#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 && defined (__REDIRECT) +__LDBL_REDIR_DECL (dlvsym); +#endif + #endif /* When any of the above functions fails, call this function diff --git a/dlfcn/dlsym.c b/dlfcn/dlsym.c index e9ee596021..5cf9730955 100644 --- a/dlfcn/dlsym.c +++ b/dlfcn/dlsym.c @@ -26,11 +26,20 @@ void * dlsym (void *handle, const char *name) { - return __dlsym (handle, name, RETURN_ADDRESS (0)); + return __dlsym_internal (handle, name, RETURN_ADDRESS (0)); } #else +# ifdef SHARED +void * +__dlsym (void *handle, const char *name) +{ + return __dlsym_internal (handle, name, RETURN_ADDRESS (0)); +} +strong_alias (__dlsym, dlsym) +# endif + struct dlsym_args { /* The arguments to dlsym_doit. */ @@ -52,15 +61,15 @@ dlsym_doit (void *a) void * -__dlsym (void *handle, const char *name DL_CALLER_DECL) +__dlsym_internal (void *handle, const char *name, void *dl_caller) { # ifdef SHARED if (!rtld_active ()) - return _dlfcn_hook->dlsym (handle, name, DL_CALLER); + return _dlfcn_hook->dlsym (handle, name, dl_caller); # endif struct dlsym_args args; - args.who = DL_CALLER; + args.who = dl_caller; args.handle = handle; args.name = name; @@ -73,7 +82,5 @@ __dlsym (void *handle, const char *name DL_CALLER_DECL) return result; } -# ifdef SHARED -strong_alias (__dlsym, dlsym) -# endif + #endif diff --git a/dlfcn/dlvsym.c b/dlfcn/dlvsym.c index 021697fb75..5aa9974104 100644 --- a/dlfcn/dlvsym.c +++ b/dlfcn/dlvsym.c @@ -27,11 +27,20 @@ void * weak_function dlvsym (void *handle, const char *name, const char *version_str) { - return __dlvsym (handle, name, version_str, RETURN_ADDRESS (0)); + return __dlvsym_internal (handle, name, version_str, RETURN_ADDRESS (0)); } #else +# ifdef SHARED +void * +__dlvsym (void *handle, const char *name, const char *version_str) +{ + return __dlvsym_internal (handle, name, version_str, RETURN_ADDRESS (0)); +} +weak_alias (__dlvsym, dlvsym) +# endif + struct dlvsym_args { /* The arguments to dlvsym_doit. */ @@ -54,18 +63,18 @@ dlvsym_doit (void *a) } void * -__dlvsym (void *handle, const char *name, const char *version_str - DL_CALLER_DECL) +__dlvsym_internal (void *handle, const char *name, const char *version_str, + void *dl_caller) { # ifdef SHARED if (!rtld_active ()) - return _dlfcn_hook->dlvsym (handle, name, version_str, DL_CALLER); + return _dlfcn_hook->dlvsym (handle, name, version_str, dl_caller); # endif struct dlvsym_args args; args.handle = handle; args.name = name; - args.who = DL_CALLER; + args.who = dl_caller; args.version = version_str; /* Protect against concurrent loads and unloads. */ @@ -77,7 +86,4 @@ __dlvsym (void *handle, const char *name, const char *version_str return result; } -# ifdef SHARED -weak_alias (__dlvsym, dlvsym) -# endif #endif diff --git a/include/dlfcn.h b/include/dlfcn.h index 93dd369ab1..3eeb6b556b 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -131,10 +131,14 @@ extern void *__dlmopen (Lmid_t nsid, const char *file, int mode DL_CALLER_DECL) attribute_hidden; extern int __dlclose (void *handle) attribute_hidden; -extern void *__dlsym (void *handle, const char *name DL_CALLER_DECL) +extern void *__dlsym (void *handle, const char *name) attribute_hidden; -extern void *__dlvsym (void *handle, const char *name, const char *version - DL_CALLER_DECL) +extern void *__dlsym_internal (void *handle, const char *name, void *dl_caller) + attribute_hidden; +extern void *__dlvsym (void *handle, const char *name, const char *version) + attribute_hidden; +extern void *__dlvsym_internal (void *handle, const char *name, + const char *version, void *dl_caller) attribute_hidden; extern char *__dlerror (void) attribute_hidden; diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile index 7b42746c34..9abe1d7e2a 100644 --- a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile +++ b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile @@ -344,3 +344,9 @@ obj-suf-foreach = $(foreach suf,$(all-object-suffixes),$(subst ^,$(suf),$(1))) # Explicitly add -mabi=ibm-long-double to required files. $(call obj-suf-foreach,$(ldbl-ibm128-files)): \ sysdep-CFLAGS += -mabi=ibmlongdouble + +ifeq ($(subdir),dlfcn) + libdl-routines += ieee128-dlfcn + CFLAGS-dlsym.c += -mabi=ibmlongdouble + CFLAGS-dlvsym.c += -mabi=ibmlongdouble +endif diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Versions b/sysdeps/ieee754/ldbl-128ibm-compat/Versions index 07e6a5b08a..fe644f79f4 100644 --- a/sysdeps/ieee754/ldbl-128ibm-compat/Versions +++ b/sysdeps/ieee754/ldbl-128ibm-compat/Versions @@ -245,3 +245,10 @@ libc { __qfcvtieee128_r; } } + +libdl { + LDBL_IBM128_VERSION { + __dlsymieee128; + __dlvsymieee128; + } +} diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-dlfcn.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-dlfcn.c new file mode 100644 index 0000000000..8b06c42cf7 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-dlfcn.c @@ -0,0 +1,33 @@ +/* Look up a versioned symbol in a shared object loaded by `dlopen' + with name mangling for ieee128 redirects. + + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +void * +__dlsymieee128 (void *handle, const char *name) +{ + return __dlsym_internal (handle, name, RETURN_ADDRESS (0)); +} + +void * +__dlvsymieee128 (void *handle, const char *name, const char *version_str) +{ + return __dlvsym_internal (handle, name, version_str, RETURN_ADDRESS (0)); +} diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libdl.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libdl.abilist index 36340d5dd8..a95c377a24 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libdl.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libdl.abilist @@ -7,3 +7,5 @@ GLIBC_2.17 dlmopen F GLIBC_2.17 dlopen F GLIBC_2.17 dlsym F GLIBC_2.17 dlvsym F +GLIBC_2.32 __dlsymieee128 F +GLIBC_2.32 __dlvsymieee128 F