Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 877343 - sys-libs/musl-1.2.3-r4: fails to build with LTO (<artificial>:(.text+0x12): undefined reference to `_dlstart_c')
Summary: sys-libs/musl-1.2.3-r4: fails to build with LTO (<artificial>:(.text+0x12): u...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Anthony Basile
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks: lto
  Show dependency tree
 
Reported: 2022-10-16 17:45 UTC by immolo
Modified: 2023-05-09 11:50 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
build.log (build.log.xz,20.74 KB, application/x-xz)
2022-10-16 17:48 UTC, immolo
Details
Clang error (clang-build.log.xz,20.09 KB, application/x-xz)
2022-10-16 18:51 UTC, immolo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description immolo 2022-10-16 17:45:54 UTC
My Musl AMD64 seems to fail to build with -flto enabled yet works fine if filtered out.

I can see the GentooLTO community run into this in 2019 and applied the filter however I can't see that looked into solving it first so don't want to jump to conclusions.

Reproducible: Always

Steps to Reproduce:
1. Add -flto to cflags
2. emerge musl
3. Fail
Actual Results:  
See build.log


The only information on LTO musl working comes from a 9 year old openwrt post but I was unable to find anything else on the subject.
Comment 1 immolo 2022-10-16 17:46:36 UTC
Portage 3.0.38.1 (python 3.10.8-final-0, default/linux/amd64/17.0/musl, gcc-12.2.0, musl-1.2.3-r4, 5.19.11-gentoo-x86_64 x86_64)
=================================================================
System uname: Linux-5.19.11-gentoo-x86_64-x86_64-Intel-R-_Core-TM-_i5-5300U_CPU_@_2.30GHz-with-libc
KiB Mem:     8018436 total,   2921740 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Sun, 16 Oct 2022 17:00:01 +0000
Head commit of repository gentoo: c41b4efc1125ff985ca7b44aebe2b309e783a918
Timestamp of repository musl: Sat, 15 Oct 2022 17:49:05 +0000
Head commit of repository musl: b7cb287ba8a02c7610135e7fbb3fe05ad9b3081f

sh bash 5.1_p16-r2
ld GNU ld (Gentoo 2.38 p4) 2.38
app-misc/pax-utils:        1.3.5::gentoo
app-shells/bash:           5.1_p16-r2::gentoo
dev-lang/perl:             5.36.0::gentoo
dev-lang/python:           3.10.8::gentoo, 3.11.0_rc2::gentoo
dev-lang/rust:             1.64.0-r1::gentoo
dev-util/cmake:            3.24.2::gentoo
dev-util/meson:            0.63.2-r1::gentoo
sys-apps/baselayout:       2.9::gentoo
sys-apps/openrc:           0.45.2::gentoo
sys-apps/sandbox:          2.29::gentoo
sys-devel/autoconf:        2.13-r3::gentoo, 2.71-r4::gentoo
sys-devel/automake:        1.16.5::gentoo
sys-devel/binutils:        2.38-r2::gentoo, 2.39-r2::gentoo
sys-devel/binutils-config: 5.4.1::gentoo
sys-devel/clang:           14.0.6-r1::gentoo, 15.0.1::gentoo
sys-devel/gcc:             11.3.0::gentoo, 12.2.0::gentoo
sys-devel/gcc-config:      2.8::gentoo
sys-devel/libtool:         2.4.7::gentoo
sys-devel/llvm:            14.0.6-r2::gentoo, 15.0.1::gentoo
sys-devel/make:            4.3::gentoo
sys-kernel/linux-headers:  6.0::gentoo (virtual/os-headers)
sys-libs/musl:             1.2.3-r4::gentoo
Repositories:

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

musl
    location: /var/db/repos/musl
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/musl.git
    masters: gentoo

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-gentoo-linux-musl"
CFLAGS="-march=broadwell -O2 -pipe -fgraphite-identity -floop-nest-optimize -flto=4 -fuse-linker-plugin -falign-functions=32"
CHOST="x86_64-gentoo-linux-musl"
CONFIG_PROTECT="/etc /usr/share/config /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"
CXXFLAGS="-march=broadwell -O2 -pipe -fgraphite-identity -floop-nest-optimize -flto=4 -fuse-linker-plugin -falign-functions=32"
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 XDG_STATE_HOME"
FCFLAGS="-march=broadwell -O2 -pipe -fgraphite-identity -floop-nest-optimize -flto=4 -fuse-linker-plugin -falign-functions=32"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs binpkg-multi-instance buildpkg-live config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync 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=broadwell -O2 -pipe -fgraphite-identity -floop-nest-optimize -flto=4 -fuse-linker-plugin -falign-functions=32"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
INSTALL_MASK="charset.alias /usr/share/locale/locale.alias"
LANG="C.UTF8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j4"
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"
RUSTFLAGS="-C target-cpu=native"
SHELL="/bin/bash"
USE="X acl amd64 bluetooth bzip2 cairo cli crypt d3d9 dbus dri elogind fortran gif gnome-keyring graphite gtk iconv ipv6 libglvnd libtirpc logrotate lto ncurses networkmanager nls nptl openmp pam pcre pgo pulseaudio readline seccomp spell split-usr ssl startup-notification test-rust udisks unicode vulkan xattr zlib" ABI_X86="64" ADA_TARGET="gnat_2020" 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="musl" 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" L10N="en en-GB" 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-4 php8-0" POSTGRES_TARGETS="postgres12 postgres13" PYTHON_SINGLE_TARGET="python3_10" PYTHON_TARGETS="python3_10" RUBY_TARGETS="ruby27" USERLAND="GNU" VIDEO_CARDS="intel" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EMERGE_DEFAULT_OPTS, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, LC_ALL, LD, LEX, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, SIZE, STRINGS, STRIP, YACC, YFLAGS
Comment 2 immolo 2022-10-16 17:48:33 UTC
Created attachment 824473 [details]
build.log
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-10-16 18:08:31 UTC
This doesn't look like type mismatch as the main issue necessarily, but:

/usr/lib/gcc/x86_64-gentoo-linux-musl/12.2.0/../../../../x86_64-gentoo-linux-musl/bin/ld: /var/tmp/portage/sys-libs/musl-1.2.3-r4/temp/ccnLgfge.ltrans0.ltrans.o: in function `_dlstart':
<artificial>:(.text+0x12): undefined reference to `_dlstart_c'
collect2: error: ld returned 1 exit status
make: *** [Makefile:162: lib/libc.so] Error 1
Comment 4 immolo 2022-10-16 18:22:02 UTC
I was looking at that however I've not seen anything that points to why that variable is defined with lto disabled but not when it is.

I'll test in a clang build later on just to see if it gives me anymore infoamtion.
Comment 5 immolo 2022-10-16 18:51:10 UTC
Created attachment 824475 [details]
Clang error

Well the issue is still there but I feel like this could be giving more clues.
Comment 6 immolo 2022-10-17 19:01:16 UTC
On advice from #musl I have submitted a PR to filter lto as this is the correct solution.
Comment 7 Larry the Git Cow gentoo-dev 2022-10-17 20:31:27 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f44d1becbe468a4e1c36a4819a6276b9ee0c9da2

commit f44d1becbe468a4e1c36a4819a6276b9ee0c9da2
Author:     Ian Jordan <immoloism@gmail.com>
AuthorDate: 2022-10-17 18:44:08 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-10-17 20:31:10 +0000

    sys-libs/musl: Filter LTO
    
    After discussing my bug with dalias on #musl I was informed that LTO has a negative
    impact on Musl so fixing the issue I highlight rather than filtering wouldn't be the
    desired outcome for the user.
    
    This will also help crossdev users as a bonus as -flto applies to the
    crosstoolchain and can be hard to spot at first.
    
    Chat log to comfirm:
    
    immolo: I ran into the -flto issue while testing musl built with lto and the only thing I can find on it was a workaround in 2015.
    immolo: My question though is it even worth having lto enabled on musl in the first place as every distro just seems to filter it so
    there must be a reason
    dalias: not only is it not worth it. it's negative value
    dalias: makes musl larger and slower
    dalias: if you wanted libc.a to get LTO'd into static programs, that might have some value
    dalias: but LTO on libc.so is worse than worthless
    
    Closes: https://bugs.gentoo.org/877343
    Thanks-to: dalias
    Signed-off-by: Ian Jordan <immoloism@gmail.com>
    Closes: https://github.com/gentoo/gentoo/pull/27824
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-libs/musl/musl-1.2.2-r8.ebuild | 1 +
 sys-libs/musl/musl-1.2.3-r4.ebuild | 1 +
 sys-libs/musl/musl-1.2.3.ebuild    | 1 +
 sys-libs/musl/musl-9999.ebuild     | 1 +
 4 files changed, 4 insertions(+)
Comment 8 Larry the Git Cow gentoo-dev 2023-05-09 11:38:18 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=286463897801758ffa517870a5cf2b38cadd711b

commit 286463897801758ffa517870a5cf2b38cadd711b
Author:     Ian Jordan <immoloism@gmail.com>
AuthorDate: 2023-05-08 21:51:19 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-05-09 11:37:54 +0000

    sys-libs/musl: Reapply filter-lto
    
    As strip-flags no longer removes -flto then a filter-lto is now
    required to prevent bug 877343 from reopening, like has already
    been applied to sys-libs/glibc.
    
    Closes: https://bugs.gentoo.org/877343
    Closes: https://github.com/gentoo/gentoo/pull/30942
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-libs/musl/musl-1.2.3-r7.ebuild | 2 +-
 sys-libs/musl/musl-1.2.3-r8.ebuild | 2 +-
 sys-libs/musl/musl-1.2.3.ebuild    | 4 ++--
 sys-libs/musl/musl-1.2.4.ebuild    | 2 +-
 sys-libs/musl/musl-9999.ebuild     | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)