Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
No option to build gentoo-sources with LTO
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
causality
Apprentice
Apprentice


Joined: 03 Jun 2006
Posts: 243

PostPosted: Sat Feb 22, 2025 11:43 pm    Post subject: No option to build gentoo-sources with LTO Reply with quote

This is concerning gentoo-sources-6.13.4 version. I have enabled the "experimental" USE flag.

I notice that when I run "make menuconfig", there is an entry under "General architecture-dependent options" that is called "Link Time Optimization (LTO)". I can select this to bring up a sub-menu, but the only available option is "None" or "CONFIG_LTO_NONE". I have GCC version 14.2.1_p20241221 and Clang 19.1.7, both of which support LTO and often build packages with it enabled.

Please correct me if I have this wrong, but my understanding is that building the kernel with Clang+LTO has been supported for some time now and GCC+LTO is more recently supported. So, why can't I select these options through standard configuration? Usually, the menuconfig "<HELP>" option will tell you what selects or de-selects a given option, but that information is notably absent.

I keep a few previous kernels around and configured in my bootloader, so there is very little risk for me if an LTO kernel doesn't boot or wants to crash.

Further, I perused https://wiki.gentoo.org/wiki/Kernel/Optimization#Link_Time_Optimization but it appears to be dated. Specifically, that site mentions kernel version 6.6 and I could find nothing more recent on that site. I also tried https://github.com/CachyOS/kernel-patches/ but none of the patches there under 6.13 indicate LTO.

I would rather not use a patch if that's not needed. I would much prefer to figure out why a nice, standard configuration option is unavailable than force the issue by manually trying to add KCFLAGS and such. From what I hear, apparently some other users get to select LTO and then select whether that'll be Clang or GCC. I'm unclear on how they are doing that and recent information on this topic is quite difficult to find (most of it is about 5.12 series kernels), but I would like to try that.

Standard output of "emerge --info":

Code:
# emerge --info
Portage 3.0.66.1 (python 3.12.9-final-0, default/linux/amd64/23.0/desktop/plasma, gcc-14, glibc-2.40-r8, 6.13.2-gentoo x86_64)
=================================================================
System uname: Linux-6.13.2-gentoo-x86_64-Intel-R-_Core-TM-_i5-6500_CPU_@_3.20GHz-with-glibc2.40
KiB Mem:    16354720 total,   9466340 free
KiB Swap:    5392376 total,   4936528 free
Timestamp of repository gentoo: Sat, 22 Feb 2025 13:45:00 +0000
Head commit of repository gentoo: 75d82143fa29cb7a37550333c548292bda6b4687
Timestamp of repository myrvolay: Sun, 16 Feb 2025 18:52:21 +0000
Head commit of repository myrvolay: 527d600806d23f9ac64966559376fa828c3e4b0d

sh bash 5.2_p37
ld GNU ld (Gentoo 2.43 p3) 2.43.1
app-misc/pax-utils:        1.3.8::gentoo
app-shells/bash:           5.2_p37::gentoo
dev-build/autoconf:        2.13-r8::gentoo, 2.72-r1::gentoo
dev-build/automake:        1.16.5-r2::gentoo
dev-build/cmake:           3.31.5::gentoo
dev-build/libtool:         2.5.4::gentoo
dev-build/make:            4.4.1-r100::gentoo
dev-build/meson:           1.6.1::gentoo
dev-lang/perl:             5.40.0-r1::gentoo
dev-lang/python:           3.12.9::gentoo, 3.13.1_p1::gentoo
dev-lang/rust-bin:         1.81.0-r100::gentoo, 1.82.0-r101::gentoo, 1.83.0-r1::gentoo, 1.84.1-r2::gentoo
llvm-core/clang:           18.1.8-r6::gentoo, 19.1.7::gentoo
llvm-core/lld:             18.1.8::gentoo, 19.1.7::gentoo
llvm-core/llvm:            18.1.8-r6::gentoo, 19.1.7::gentoo
sys-apps/baselayout:       2.17::gentoo
sys-apps/openrc:           0.55.1::gentoo
sys-apps/sandbox:          2.39::gentoo
sys-devel/binutils:        2.42-r2::gentoo, 2.43-r2::gentoo
sys-devel/binutils-config: 5.5.2::gentoo
sys-devel/gcc:             14.2.1_p20241221::gentoo
sys-devel/gcc-config:      2.12.1::gentoo
sys-kernel/linux-headers:  6.6-r1::gentoo (virtual/os-headers)
sys-libs/glibc:            2.40-r8::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.us.gentoo.org/gentoo-portage
    priority: -1000
    volatile: True
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-jobs: 1
    sync-rsync-extra-opts:
    sync-rsync-verify-metamanifest: yes

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

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="*"
AR="gcc-ar"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=native -fomit-frame-pointer -fsched-pressure -ftree-loop-distribution -fweb -frename-registers -floop-interchange -ftree-vectorize -fivopts -pipe -flto=auto -fuse-linker-plugin -floop-nest-optimize -fgraphite-identity"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt /var/bind"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d"
CXXFLAGS="-O2 -march=native -fomit-frame-pointer -fsched-pressure -ftree-loop-distribution -fweb -frename-registers -floop-interchange -ftree-vectorize -fivopts -pipe -flto=auto -fuse-linker-plugin -floop-nest-optimize -fgraphite-identity"
DISTDIR="/var/cache/distfiles"
EMERGE_DEFAULT_OPTS="--with-bdeps=y"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GDK_PIXBUF_MODULE_FILE 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="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs binpkg-multi-instance buildpkg buildpkg-live candy config-protect-if-modified distlocks ebuild-locks fail-clean fixlafiles ipc-sandbox merge-sync merge-wait multilib-strict network-sandbox news pid-sandbox pkgdir-index-trusted preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://gentoo.mirror.root.lu/"
LANG="C.UTF8"
LDFLAGS="-Wl,-O2 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,--sort-common -Wl,-z,combreloc -Wl,-z,relro -Wl,-z,now -Wl,--strip-debug -O2 -march=native -fomit-frame-pointer -fsched-pressure -ftree-loop-distribution -fweb -frename-registers -floop-interchange -ftree-vectorize -fivopts -pipe -flto=auto -fuse-linker-plugin -floop-nest-optimize -fgraphite-identity -fuse-ld=mold"
LEX="flex"
MAKEOPTS="-j3"
NM="gcc-nm"
PKGDIR="/usr/portage/packages"
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"
RANLIB="gcc-ranlib"
SHELL="/bin/bash"
USE="3dnow 3dnowext X \ a52 aac aalib acl acpi activities alsa amd64 bash-completion branding bzip2 cairo cdda cdr cet crypt cups dbus declarative dri dts dvd dvdr elogind encode exif ffmpeg flac gdbm gif gpm gtk gui iconv icu ipv6 jpeg jpeg2k kde kf6compat kwallet lcms libnotify libtirpc lzma mad mng mp3 mp4 mpeg mplayer multilib mysql ncurses networkmanager nvenc offensive ogg opengl openmp openssl pam pango pcre pdf plasma png policykit ppds python qml qt5 qt6 readline sdl seccomp socks5 sound spell ssl startup-notification svg symlink test-rust tiff truetype udev udisks unicode upower usb verify-sig videos vorbis vulkan wayland widgets wmf wxwidgets x264 xattr xcb xcomposite xft xine xml xscreensaver xv xvid zlib" ABI_X86="64 32" ADA_TARGET="gcc_14" ALSA_CARDS="hda-intel" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_anon authn_dbm authn_file authz_dbm authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir env expires ext_filter file_cache filter headers include info log_config logio 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="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax navcom oceanserver oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 tsip tripmate tnt ublox" GRUB_PLATFORMS="pc" GUILE_SINGLE_TARGET="3-0" GUILE_TARGETS="3-0" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" L10N="en en-US" LCD_DEVICES="bayrad cfontz glk hd44780 lb216 lcdm001 mtxorb text" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php8-2" POSTGRES_TARGETS="postgres16" PYTHON_SINGLE_TARGET="python3_12" PYTHON_TARGETS="python3_12" RUBY_TARGETS="ruby32" VIDEO_CARDS="nvidia nv vesa" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipp2p iface geoip fuzzy condition tarpit sysrq proto logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PYTHONPATH, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23131

PostPosted: Sun Feb 23, 2025 12:27 am    Post subject: Reply with quote

As I read arch/Kconfig, this prompt has 3 options: None (always available), LTO_CLANG_FULL (depends on HAS_LTO_CLANG), and LTO_CLANG_THIN (depends on HAS_LTO_CLANG and ARCH_SUPPORTS_LTO_CLANG_THIN). I then looked above and found the implementation of HAS_LTO_CLANG:
Code:
config HAS_LTO_CLANG
   def_bool y
   depends on CC_IS_CLANG && LD_IS_LLD && AS_IS_LLVM
   depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm)
   depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm)
   depends on ARCH_SUPPORTS_LTO_CLANG
   depends on !FTRACE_MCOUNT_USE_RECORDMCOUNT
   depends on !KASAN || KASAN_HW_TAGS
   depends on !GCOV_KERNEL
Does your build environment satisfy all these dependency checks?
Back to top
View user's profile Send private message
sam_
Developer
Developer


Joined: 14 Aug 2020
Posts: 2174

PostPosted: Sun Feb 23, 2025 2:26 am    Post subject: Reply with quote

kernel.org upstream still doesn't support GCC LTO because they don't want to adapt their asm (or add workarounds, depending on your perspective) to mark them up with attributes.

As for using LTO with Clang, you need to make sure you pass LLVM=1 on all make command lines (including for e.g. menuconfig).
Back to top
View user's profile Send private message
causality
Apprentice
Apprentice


Joined: 03 Jun 2006
Posts: 243

PostPosted: Sun Feb 23, 2025 5:55 pm    Post subject: Reply with quote

Yes, adding "LLVM=1" with each invocation of "make" opened up the appropriate Clang options including Full LTO and ThinLTO. Thank you, that's nice and simple.

The kernel built just fine. Then x11-drivers/nvidia-drivers automatically detected that the kernel was built with Clang and built itself with Clang as well (usually both would be GCC). nvidia-drivers built and installed fine, but I had a suspicion that LTO might be a little too aggressive at removing symbols that an out-of-tree module would need. Sure enough, that's what happened, with both full LTO and thin LTO. The kernel boots fine and functions, except that the nvidia driver fails to load. From kern.log:

Code:
Feb 23 11:24:17 causality kernel: nvidia: loading out-of-tree module taints kernel.
Feb 23 11:24:17 causality kernel: nvidia: module license 'NVIDIA' taints kernel.
Feb 23 11:24:17 causality kernel: Disabling lock debugging due to kernel taint
Feb 23 11:24:17 causality kernel: nvidia: module license taints kernel.
Feb 23 11:24:17 causality kernel: nvidia-nvlink: Nvlink Core is being initialized, major device number 244
Feb 23 11:24:17 causality kernel:
Feb 23 11:24:17 causality kernel: nvidia 0000:01:00.0: vgaarb: VGA decodes changed: olddecodes=io+mem,decodes=none:owns=io+m
em
Feb 23 11:24:17 causality kernel: NVRM: loading NVIDIA UNIX x86_64 Kernel Module  550.144.03  Mon Dec 30 17:44:08 UTC 2024
Feb 23 11:24:17 causality kernel: nvidia_modeset: Unknown symbol backlight_device_register (err -2)
Feb 23 11:24:17 causality kernel: nvidia_modeset: Unknown symbol backlight_device_unregister (err -2)
Feb 23 11:24:17 causality kernel: nvidia_modeset: Unknown symbol __acpi_video_get_backlight_type (err -2)


So, no SDDM and no Xorg or Wayland. Good thing i'm comfortable on the console heh. I'm convinced it's that LTO was too aggressive with the kernel because booting a prior kernel that wasn't built with LTO, while changing nothing else (so, a GCC built kernel with no LTO + the Clang-built nvidia-drivers) works fine. In fact, building the kernel with ThinLTO gave these warnings at or around the final link:

Code:
depmod: WARNING: /lib/modules/6.13.4-gentoo/video/nvidia-modeset.ko needs unknown symbol backlight_device_register
depmod: WARNING: /lib/modules/6.13.4-gentoo/video/nvidia-modeset.ko needs unknown symbol backlight_device_unregister
depmod: WARNING: /lib/modules/6.13.4-gentoo/video/nvidia-modeset.ko needs unknown symbol __acpi_video_get_backlight_type
depmod: WARNING: /lib/modules/6.13.4-gentoo/video/nvidia-drm.ko needs unknown symbol drm_fbdev_ttm_driver_fbdev_probe


Is there a way to get this to work, or should I just abandon LTO kernels? Maybe I could enable a kernel setting or module someplace that would cause those symbols to remain in the final link? I'm very comfortable with the command line and system admin type tasks but I'm really not much of a programmer; so, while I have heard of these things, I'm out of my element, here.

Thank all of you for your time, really. The forums are part of what makes Gentoo great.

** EDIT **

It seems the missing symbols were unrelated to LTO. I inadvertently disabled Device Drivers -> Graphics support -> Backlight & LCD device support -> "Lowlevel LCD controls" (CONFIG_LCD_CLASS_DEVICE) and "Lowlevel Backlight controls" (CONFIG_BACKLIGHT_CLASS_DEVICE) as I associated these with laptops, netbooks, and other mobile devices, not a desktop system. Re-enabling those as well as CONFIG_ACPI_VIDEO got rid of all the missing symbol warnings (from depmod), even with ThinLTO re-enabled.

The "drm_fbdev_ttm_driver_fbdev_probe" symbol was because I forgot why I had enabled graphics DRM driver CONFIG_DRM_AMDGPU even though I have no AMD graphics hardware on this system. This was to pull in DRM-related helpers that nvidia-drivers needs to have in the kernel. The nvidia-drivers themselves will abort the build if they detect that this isn't present in the kernel config and explicitly suggest enabling something you won't use to enable this. Gah.

Anyway, the nvidia-drivers package built successfully and I'm hoping a reboot will bring me a fully functional system.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum