This is the mail archive of the
mailing list for the GCC project.
[RFC] builtin functions and `-ffreestanding -nostartfies` with static binaries
- From: Siddhesh Poyarekar <siddhesh at gotplt dot org>
- To: gcc at gcc dot gnu dot org, GLIBC Devel <libc-alpha at sourceware dot org>
- Date: Fri, 10 Jan 2020 21:50:48 +0530
- Subject: [RFC] builtin functions and `-ffreestanding -nostartfies` with static binaries
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
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?