From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90644 invoked by alias); 10 Jan 2020 16:21:13 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 90634 invoked by uid 89); 10 Jan 2020 16:21:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: crocodile.birch.relay.mailchannels.net Received: from crocodile.birch.relay.mailchannels.net (HELO crocodile.birch.relay.mailchannels.net) (23.83.209.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Jan 2020 16:21:11 +0000 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 316668C1443; Fri, 10 Jan 2020 16:21:09 +0000 (UTC) Received: from pdx1-sub0-mail-a10.g.dreamhost.com (100-96-11-8.trex.outbound.svc.cluster.local [100.96.11.8]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 3DBEC8C1CFD; Fri, 10 Jan 2020 16:21:07 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a10.g.dreamhost.com ([TEMPUNAVAIL]. [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.18.5); Fri, 10 Jan 2020 16:21:09 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Illustrious-Desert: 5351771c46fecbd3_1578673267842_1818246234 X-MC-Loop-Signature: 1578673267837:1365141418 X-MC-Ingress-Time: 1578673267836 Received: from pdx1-sub0-mail-a10.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTP id C536186192; Fri, 10 Jan 2020 08:21:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gotplt.org; h=to:from :subject:message-id:date:mime-version:content-type :content-transfer-encoding; s=gotplt.org; bh=KbRQYoN5vB6PGjZZYi7 ZUq6BBx8=; b=tD/m4vvFAU8sb2SzJp2Sum7UotfTD1mmJHW6IWaPVlWPavT5W9X oUFpBdCGPQ1aqihP+WFRAA8VEPFKBv39FeBmR/MsvayDLSq4YU0xh1DOUqFygcaJ sjyJJb9Se3BEyNs8wCZLjZED4jJec2Fi0FXt2KsneOfQwmixWEbE0/UM= Received: from [192.168.86.54] (unknown [103.199.173.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTPSA id 071BA846BD; Fri, 10 Jan 2020 08:20:57 -0800 (PST) To: gcc@gcc.gnu.org, GLIBC Devel X-DH-BACKEND: pdx1-sub0-mail-a10 From: Siddhesh Poyarekar Subject: [RFC] builtin functions and `-ffreestanding -nostartfies` with static binaries Message-ID: <129c8494-bfd0-87f0-ddb5-e56f6d4a6e0c@gotplt.org> Date: Fri, 10 Jan 2020 16:21:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: 0 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedufedrvdeifedgkeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucenucfjughrpefvhffukffffgggtgfgsehtjeertddtfeejnecuhfhrohhmpefuihguughhvghshhcurfhohigrrhgvkhgrrhcuoehsihguughhvghshhesghhothhplhhtrdhorhhgqeenucffohhmrghinheplhhinhgrrhhordhorhhgnecukfhppedutdefrdduleelrddujeefrdelnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopegludelvddrudeikedrkeeirdehgegnpdhinhgvthepuddtfedrudelledrudejfedrledprhgvthhurhhnqdhprghthhepufhiugguhhgvshhhucfrohihrghrvghkrghruceoshhiugguhhgvshhhsehgohhtphhlthdrohhrgheqpdhmrghilhhfrhhomhepshhiugguhhgvshhhsehgohhtphhlthdrohhrghdpnhhrtghpthhtohepghgttgesghgttgdrghhnuhdrohhrghenucevlhhushhtvghrufhiiigvpedt X-IsSubscribed: yes X-SW-Source: 2020-01/txt/msg00128.txt.bz2 Hello, Ref: https://bugs.linaro.org/show_bug.cgi?id=5479 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. 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? Thanks, Siddhesh