From patchwork Tue Feb 13 18:49:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 873117 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-90287-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="PyH/H/mD"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zgs5q6QJJz9t2l for ; Wed, 14 Feb 2018 05:49:35 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=MZuXFdc3zcKveydzbScyRvwb480xx TDkOeYWlYhyHAN5XEGZVzXXYL8efpI7xYv7G5QDjiUlnb2b45TX4wJUi7uHYam6T zc0XYEWFdJuD2iFrqp0cixUEh7IiSTOQnwFiOgPQYTjUGndOg7N9ryRlzwTMFeRN TtBsJFpej575gw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=6+zYjLBfC7/xN760BvUN6aeZVKY=; b=PyH /H/mDQ9OEPQUPbE/4mQb1I5FL4qLh9JpTmV61pSZ0c9fZWSUOqUcKsiKOEQHqwtn NRgeDK1EVmniJzTS9XEC24XxsG2ouGZjZNsGQfmnZE4FRETgha9Ji/RNNanantT4 hETf3TB5/KWS300TVF52vgbszG5W50s8J3WTG3s8= Received: (qmail 32920 invoked by alias); 13 Feb 2018 18:49:30 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 32564 invoked by uid 89); 13 Feb 2018 18:49:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Date: Tue, 13 Feb 2018 18:49:22 +0000 From: Joseph Myers To: Subject: Use libc_hidden_* for fputs (bug 15105) Message-ID: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) Among other localplt test failures when building with -Os, there are libc.so PLT references for fputs. fputs calls normally get redirected to _IO_fputs by a macro in include/stdio.h (and _IO_fputs in turn uses libc_hidden_proto), but GCC can convert an fprintf call with a constant string argument into an fputs call, which of course is then unaffected by the macro redirection. (I don't know why this issue only appears with -Os.) This patch duly adds a use of libc_hidden_proto for fputs. I see no obvious reason why the fputs macro redirection is needed at all, but this patch does not change it. Tested for x86_64 (both that it removes this particular localplt failure for -Os - but other such failures remain so the bug can't yet be closed - and that the testsuite continues to pass without -Os). 2018-02-13 Joseph Myers [BZ #15105] * include/stdio.h [!_ISOMAC && IS_IN (libc)] (fputs): Use libc_hidden_proto. * libio/iofputs.c (fputs): Use libc_hidden_weak. Reviewed-by: Adhemerval Zanella diff --git a/include/stdio.h b/include/stdio.h index 94bc2fd..266c1d2 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -140,6 +140,10 @@ extern int _IO_new_fclose (_IO_FILE*); # define fclose(fp) _IO_new_fclose (fp) extern int _IO_fputs (const char*, _IO_FILE*); libc_hidden_proto (_IO_fputs) +/* The compiler may optimize calls to fprintf into calls to fputs. + Use libc_hidden_proto to ensure that those calls, not redirected by + the fputs macro, also do not go through the PLT. */ +libc_hidden_proto (fputs) # define fputs(str, fp) _IO_fputs (str, fp) extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *); # define fsetpos(fp, posp) _IO_new_fsetpos (fp, posp) diff --git a/libio/iofputs.c b/libio/iofputs.c index b4fbeb5..176e9ed 100644 --- a/libio/iofputs.c +++ b/libio/iofputs.c @@ -43,6 +43,7 @@ _IO_fputs (const char *str, _IO_FILE *fp) libc_hidden_def (_IO_fputs) weak_alias (_IO_fputs, fputs) +libc_hidden_weak (fputs) # ifndef _IO_MTSAFE_IO strong_alias (_IO_fputs, __fputs_unlocked)