From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 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 dcvr.yhbt.net (Postfix) with ESMTPS id 4E2601F885 for ; Sat, 11 Jan 2020 13:25:44 +0000 (UTC) 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:cc:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=N4Go 4HWOatfvxurcHOgtcao2BRpBwV0TxJZDSMFFV+oWR57hCcjOwzGvDQHx3H5aE0m/ UfxzMyLPACMj/z4w72OTKe4fq2d0qmkFgLyGpbhorz5l+NpiSJvD+BwisuNoeYVP ByMbr3fIdMKCmH+qvOvTe0+8MfsWaJwjQVxjKWA= 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:cc:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=A2n0Xf21MU hUU0uHxn+eEMaMBhk=; b=iyYRk34wBoeU2EVdnzl+faUDv4wFGF0cuUedueHVNs 7Bo+6gd3WivCNdd6kHXKvyqKVS1pbygqNK3qesim84haU0ap3CjO88Pyom9cqnOj J5j9XZZr35+4pUDwrCIg1SIVPWjm17WTLLBVgZ0BAAlO/9AKomS/zEl8DarFovDz s= Received: (qmail 8234 invoked by alias); 11 Jan 2020 13:25:19 -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 Received: (qmail 8149 invoked by uid 89); 11 Jan 2020 13:25:19 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: gate.crashing.org Date: Sat, 11 Jan 2020 07:25:09 -0600 From: Segher Boessenkool To: Siddhesh Poyarekar Cc: gcc@gcc.gnu.org, GLIBC Devel Subject: Re: [RFC] builtin functions and `-ffreestanding -nostartfies` with static binaries Message-ID: <20200111132509.GA3191@gate.crashing.org> References: <129c8494-bfd0-87f0-ddb5-e56f6d4a6e0c@gotplt.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <129c8494-bfd0-87f0-ddb5-e56f6d4a6e0c@gotplt.org> User-Agent: Mutt/1.4.2.3i Hi! On Fri, Jan 10, 2020 at 09:50:48PM +0530, Siddhesh Poyarekar wrote: > Statically built independent programs that implement their own program > entry points (i.e. -ffreestanding -nostartfiles) and call __builtin_* > functions break when the builtin function in question is implemented as > an IFUNC in glibc and the builtin results in a glibc call instead of > some inline code. > > This happens because the startup code where ifuncs are resolved never > gets executed (since glibc's startup code is never executed) and hence > the PLT jumps fail. The bug report talks about this as an aarch64 > problem but I've been able to reproduce the problem on x86_64 as well. > One just needs to make sure that the __builtin_foo call results in a > glibc call. -ffreestanding means you might not have any of the C standard library, and -nostartfiles means you do not do any of the standard initialisation. Why then would you expect any ifunc to work? > I spent some time thinking about this and while it's trivial to fix by > disabling ifuncs for static glibc, I wanted a solution that wasn't such > a big hammer. The other alternative I could think of is to have an > exported alias (called __builtin_strlen for example instead of strlen) > of a default implementation of the builtin function in glibc that gcc > generates a call to if freestanding && nostartfiles && static. > > Any thoughts or other ideas on how this could be implemented? Why do you not want the startfiles, but do want their effects? Segher