Bug 31928 - glibc doesn't compile if the compiler already define _FORTIFY_SOURCE
Summary: glibc doesn't compile if the compiler already define _FORTIFY_SOURCE
Status: UNCONFIRMED
Alias: None
Product: glibc
Classification: Unclassified
Component: build (show other bugs)
Version: 2.39
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-25 15:06 UTC by Simon Chopin
Modified: 2024-06-26 19:17 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Chopin 2024-06-25 15:06:57 UTC
In Ubuntu, GCC has been modified to define _FORTIFY_SOURCE in the preprocessor driver, resulting in failures to build glibc, with the following error (with --disable-werror):

syslog.c: In function ‘__vsyslog_internal’:
syslog.c:95:30: error: inlining failed in call to ‘always_inline’ ‘syslog’: function not inlinable
   95 | ldbl_strong_alias (__syslog, syslog)

We're shipping a patch to adress this in 2.39, I still need to rebase it and clean it up:

https://git.launchpad.net/~ubuntu-core-dev/ubuntu/+source/glibc/tree/debian/patches/ubuntu/fix-fortify-source.patch
Comment 1 Florian Weimer 2024-06-26 07:14:20 UTC
You could add a flag _DISTRO_EVADE_FORTIFY_SOURCE, similar to bug 31624. Then no glibc patching will be required.
Comment 2 Simon Chopin 2024-06-26 08:30:05 UTC
Or we could *not* use -Wp,-U_FORTIFY_SOURCE ? I couldn't find any rationale for it in the first place.
Comment 3 Florian Weimer 2024-06-26 08:36:00 UTC
(In reply to Simon Chopin from comment #2)
> Or we could *not* use -Wp,-U_FORTIFY_SOURCE ? I couldn't find any rationale
> for it in the first place.

It's needed to avoid duplicate function bodies. See:

[PATCH 00/11] Build getdomainname, gethostname, syslog with fortification
<https://inbox.sourceware.org/libc-alpha/cover.1707491940.git.fweimer@redhat.com/>
Comment 4 Adhemerval Zanella 2024-06-26 11:48:57 UTC
(In reply to Florian Weimer from comment #3)
> (In reply to Simon Chopin from comment #2)
> > Or we could *not* use -Wp,-U_FORTIFY_SOURCE ? I couldn't find any rationale
> > for it in the first place.
> 
> It's needed to avoid duplicate function bodies. See:
> 
> [PATCH 00/11] Build getdomainname, gethostname, syslog with fortification
> <https://inbox.sourceware.org/libc-alpha/cover.1707491940.git.fweimer@redhat.
> com/>

Why do we need to use -Wp instead of just -U? It seems that -Wp does not play nice if compiler defaults to define _FORTIFY_SOURCE.
Comment 5 Florian Weimer 2024-06-26 19:17:36 UTC
If -U works, we can switch to that. The use of -Wp goes back to CFLAGS settings which needed to be compatible with GCJ, where -D had a different meaning. Hence, -Wp,-D_FORTIFY_SOURCE=2 came into being, and it has been carried forward ever since.