From: Segher Boessenkool <segher@kernel.crashing.org>
To: Siddhesh Poyarekar <siddhesh@gotplt.org>
Cc: gcc@gcc.gnu.org, GLIBC Devel <libc-alpha@sourceware.org>
Subject: Re: [RFC] builtin functions and `-ffreestanding -nostartfies` with static binaries
Date: Sat, 11 Jan 2020 13:25:00 -0000 [thread overview]
Message-ID: <20200111132509.GA3191@gate.crashing.org> (raw)
In-Reply-To: <129c8494-bfd0-87f0-ddb5-e56f6d4a6e0c@gotplt.org>
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
next prev parent reply other threads:[~2020-01-11 13:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-10 16:21 Siddhesh Poyarekar
2020-01-10 16:55 ` Alexander Monakov
2020-01-11 3:53 ` Siddhesh Poyarekar
2020-01-11 13:25 ` Segher Boessenkool [this message]
2020-01-11 13:32 ` Siddhesh Poyarekar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200111132509.GA3191@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=gcc@gcc.gnu.org \
--cc=libc-alpha@sourceware.org \
--cc=siddhesh@gotplt.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).