From patchwork Tue May 19 17:06:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 39322 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 CDF7F3894E68; Tue, 19 May 2020 17:06:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CDF7F3894E68 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1589907975; bh=EeOFFOd/MMPe4SZlGZrSRvzv7SBb3I5+TXHAH2pLTN0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BsXURqUQ/hcAVw4Q9EKI6JluCkqOm22kxNkw1xY/acInT17t4PbLRjqPPxFGgArt8 aj5KR56dfdj24J+fNAALaywzvaPYkvyn5J4LEO70MmixfCLyvNG6r03BWHOuuhyPLU nXwriPeAcdP6AScnTQt/DzpKTtsRpeSjPjFTWBkg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 1E56F3894E62 for ; Tue, 19 May 2020 17:06:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1E56F3894E62 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-cKdqlHZvPK6gxZ8GzoT-_A-1; Tue, 19 May 2020 13:06:05 -0400 X-MC-Unique: cKdqlHZvPK6gxZ8GzoT-_A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE4298014D7 for ; Tue, 19 May 2020 17:06:04 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-113-18.ams2.redhat.com [10.36.113.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F3325D9C5 for ; Tue, 19 May 2020 17:06:04 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] elf: Turn _dl_printf, _dl_error_printf, _dl_fatal_printf into functions Date: Tue, 19 May 2020 19:06:02 +0200 Message-ID: <871rnfg8hx.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This change makes it easier to set a breakpoint on these calls. This also addresses the issue that including without does not result usable _dl_*printf macros because of the use of the STD*_FILENO macros there. (The private symbol for _dl_fatal_printf will go away again once the exception handling implementation is unified between libc and ld.so.) Reviewed-by: Adhemerval Zanella --- elf/Versions | 2 +- elf/dl-misc.c | 31 +++++++++++++++++++++++++++++++ sysdeps/generic/ldsodefs.h | 19 +++++++------------ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/elf/Versions b/elf/Versions index 3be879c4ad..be88c48e6d 100644 --- a/elf/Versions +++ b/elf/Versions @@ -58,7 +58,7 @@ ld { _dl_allocate_tls; _dl_allocate_tls_init; _dl_argv; _dl_find_dso_for_object; _dl_get_tls_static_info; _dl_deallocate_tls; _dl_make_stack_executable; - _dl_rtld_di_serinfo; _dl_starting_up; + _dl_rtld_di_serinfo; _dl_starting_up; _dl_fatal_printf; _rtld_global; _rtld_global_ro; # Only here for gdb while a better method is developed. diff --git a/elf/dl-misc.c b/elf/dl-misc.c index e6cf247b46..ab70481fda 100644 --- a/elf/dl-misc.c +++ b/elf/dl-misc.c @@ -275,6 +275,37 @@ _dl_dprintf (int fd, const char *fmt, ...) va_end (arg); } +void +_dl_printf (const char *fmt, ...) +{ + va_list arg; + + va_start (arg, fmt); + _dl_debug_vdprintf (STDOUT_FILENO, 0, fmt, arg); + va_end (arg); +} + +void +_dl_error_printf (const char *fmt, ...) +{ + va_list arg; + + va_start (arg, fmt); + _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg); + va_end (arg); +} + +void +_dl_fatal_printf (const char *fmt, ...) +{ + va_list arg; + + va_start (arg, fmt); + _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg); + va_end (arg); + _exit (127); +} +rtld_hidden_def (_dl_fatal_printf) /* Test whether given NAME matches any of the names of the given object. */ int diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 5ff4a2831b..d08b97a5ef 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -751,24 +751,19 @@ _dl_dprintf (int fd, const char *fmt, ...) /* Write a message on the specified descriptor standard output. The parameters are interpreted as for a `printf' call. */ -#define _dl_printf(fmt, args...) \ - _dl_dprintf (STDOUT_FILENO, fmt, ##args) +void _dl_printf (const char *fmt, ...) + attribute_hidden __attribute__ ((__format__ (__printf__, 1, 2))); /* Write a message on the specified descriptor standard error. The parameters are interpreted as for a `printf' call. */ -#define _dl_error_printf(fmt, args...) \ - _dl_dprintf (STDERR_FILENO, fmt, ##args) +void _dl_error_printf (const char *fmt, ...) + attribute_hidden __attribute__ ((__format__ (__printf__, 1, 2))); /* Write a message on the specified descriptor standard error and exit the program. The parameters are interpreted as for a `printf' call. */ -#define _dl_fatal_printf(fmt, args...) \ - do \ - { \ - _dl_dprintf (STDERR_FILENO, fmt, ##args); \ - _exit (127); \ - } \ - while (1) - +void _dl_fatal_printf (const char *fmt, ...) + __attribute__ ((__format__ (__printf__, 1, 2), __noreturn__)); +rtld_hidden_proto (_dl_fatal_printf) /* An exception raised by the _dl_signal_error function family and caught by _dl_catch_error function family. Exceptions themselves