Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 764041

Summary: sys-apps/systemd-246.6 compilation error: static declaration of reallocarray in basic/alloc-util.h follows non-static declaration in stdlib.h
Product: Gentoo Linux Reporter: Jiahao_XU
Component: Current packagesAssignee: Gentoo systemd Team <systemd>
Status: RESOLVED UPSTREAM    
Severity: normal CC: ionen, Jiahao_XU
Priority: Normal    
Version: unspecified   
Hardware: AMD64   
OS: Linux   
See Also: https://bugs.gentoo.org/show_bug.cgi?id=766833
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: build log of systemd-246.6

Description Jiahao_XU 2021-01-06 07:00:36 UTC
After I added `policykit` to my USE flag in make.conf, systemd failed to compile due to static declaration of 'reallocarray' `src/basic/alloc-util.h` conflicted with the declaration from `stdlib.h`:

```
../systemd-stable-246.6/src/basic/alloc-util.h:100:35: error: static declaration of 'reallocarray' follows non-static declaration
_alloc_(2, 3) static inline void *reallocarray(void *p, size_t need, size_t size) {
                                  ^
/usr/include/stdlib.h:559:14: note: previous declaration is here
extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)

```

I believe this is a bug in systemd-246.6::gentoo, not in the configuration of my system.

I have included the output of `emerge --info =sys-apps/systemd-246.6::gentoo`, `emerge -pqv =sys-apps/systemd-246.6::gentoo` and the complete build log in the attachment
Comment 1 Jiahao_XU 2021-01-06 07:03:12 UTC
Sorry that the attachment didn't get uploaded.

I will put `emerge --info` here:

```
Portage 3.0.12 (python 3.8.6-final-0, default/linux/amd64/17.1/systemd, gcc-9.3.0, glibc-2.32-r3, 5.4.80-gentoo-r1 x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-5.4.80-gentoo-r1-x86_64-Intel_Core_Processor_-Skylake,_IBRS-with-glibc2.2.5
KiB Mem:    15882748 total,  14569576 free
KiB Swap:     524284 total,    524284 free
Timestamp of repository gentoo: Wed, 06 Jan 2021 00:45:01 +0000
Head commit of repository gentoo: 8c6dbafdc9c5fc5d1f6b3c972f1d3c39eb8d34e1
sh bash 5.0_p18
ld GNU ld (Gentoo 2.34 p6) 2.34.0
ccache version 4.1 [disabled]
app-shells/bash:          5.0_p18::gentoo
dev-lang/perl:            5.30.3::gentoo
dev-lang/python:          3.8.6-r1::gentoo, 3.9.0-r1::gentoo
dev-util/ccache:          4.1::gentoo
dev-util/cmake:           3.17.4-r1::gentoo
sys-apps/baselayout:      2.7::gentoo
sys-apps/sandbox:         2.20::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r5::gentoo
sys-devel/automake:       1.16.2-r1::gentoo
sys-devel/binutils:       2.34-r2::gentoo
sys-devel/gcc:            9.3.0-r2::gentoo
sys-devel/gcc-config:     2.3.2-r1::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.3::gentoo
sys-kernel/linux-headers: 5.4-r1::gentoo (virtual/os-headers)
sys-libs/glibc:           2.32-r3::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-extra-opts: 
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-metamanifest: yes
    sync-rsync-verify-jobs: 1

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CC="clang"
CFLAGS="-march=native -O3 -flto -fmerge-all-constants -fomit-frame-pointer"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/sandbox.d /etc/terminfo"
CXX="clang++"
CXXFLAGS="-march=native -O3 -flto -fmerge-all-constants -fomit-frame-pointer"
DISTDIR="/var/cache/distfiles"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-march=native -O3 -flto -fmerge-all-constants -fomit-frame-pointer"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-march=native -O3 -flto -fmerge-all-constants -fomit-frame-pointer"
GENTOO_MIRRORS="http://ftp.swin.edu.au/gentoo"
LANG="C.UTF8"
LDFLAGS="-flto -fuse-ld=lld -Wl,-icf=all,--gc-sections,--plugin-opt=O3,-O3,--as-needed"
MAKEOPTS="-j12"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="acl adns alsa amd64 bash-completion berkdb bzip2 clang cli crypt dbus dri fortran gdbm iconv ipv6 libglvnd libtirpc lto multilib ncurses networkmanager nls nptl openmp pam pcre policykit pulseaudio readline seccomp split-usr sqlite ssl systemd tcpd udev unicode wayland xattr zlib" ABI_X86="64" ADA_TARGET="gnat_2018" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext sse sse2" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-2 php7-3 php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_8" PYTHON_TARGETS="python2_7 python3_8" RUBY_TARGETS="ruby25 ruby26" USERLAND="GNU" VIDEO_CARDS="amdgpu fbdev intel nouveau radeon radeonsi vesa dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS

=================================================================
                        Package Settings
=================================================================

sys-apps/systemd-246.6::gentoo was built with the following:
USE="acl gcrypt hwdb kmod lz4 pam pcre resolvconf seccomp (split-usr) sysv-utils zstd -apparmor -audit -build -cgroup-hybrid -cryptsetup -curl -dns-over-tls -elfutils -gnuefi -homed -http -idn -importd -lzma -nat -pkcs11 -policykit -pwquality -qrcode -repart (-selinux) -static-libs -test -vanilla -xkb" ABI_X86="(64) -32 (-x32)"
CFLAGS="-O2 -pipe"
CXXFLAGS="-O2 -pipe"
FEATURES="fail-clean buildpkg ebuild-locks parallel-fetch preserve-libs protect-owned qa-unresolved-soname-deps userfetch unmerge-orphans binpkg-dostrip binpkg-logs binpkg-multi-instance pid-sandbox assume-digests fixlafiles sandbox multilib-strict strict usersync merge-sync unmerge-logs userpriv sfperms distlocks network-sandbox usersandbox clean-logs ipc-sandbox config-protect-if-modified unknown-features-warn binpkg-docompress"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"

```
Comment 2 Jiahao_XU 2021-01-06 07:05:35 UTC
Created attachment 681394 [details]
build log of systemd-246.6

Here is the build log of systemd-246.6, just in case it is needed.
Comment 3 Ionen Wolkens gentoo-dev 2021-01-06 10:09:01 UTC
Looks specific to the combination of clang + ld.lld + -flto (clang+ld.lld works without lto, and gcc+ld.bfd works either way).

I'd advise against using those C(XX)FLAGS and LDFLAGS, especially on a global scope (e.g. use something more normal like "-march=native -O2").

clang/lld support is already not very tested, exotic flags isn't going to help.
Comment 4 Jiahao_XU 2021-01-06 12:51:49 UTC
You are right.

After I switch off lto, everything works perfectly fine.

This makes me wonder whether this is a compiler bug in clang.
Comment 5 Mike Gilbert gentoo-dev 2021-09-08 18:45:53 UTC
Please work with upstream if you want this toolchain config to be supported.