I tried building both without LTO and they both output the same error. Regarding Clang, adding `append-ldflags "-march=bpf"` to src_configure results in it outputting the same error as GCC
Portage 3.0.54 (python 3.11.6-final-0, default/linux/amd64/23.0/llvm, gcc-13, glibc-2.38-r6, 6.5.8-gentoo-dist x86_64) ================================================================= System uname: Linux-6.5.8-gentoo-dist-x86_64-AMD_Ryzen_9_5900HX_with_Radeon_Graphics-with-glibc2.38 KiB Mem: 32173352 total, 1019924 free KiB Swap: 8011772 total, 5795600 free Head commit of repository gentoo: a06562eb106165b7800c5d9877f97cc409e3ec53 Timestamp of repository guru: Sun, 29 Oct 2023 04:03:33 +0000 Head commit of repository guru: b7313da4415b51b25069f64b8bb0a37b91348c2f Head commit of repository librewolf: cf0e96e73f451363acdfcdcfffe10e91296896f2 Timestamp of repository pentoo: Sun, 29 Oct 2023 04:02:57 +0000 Head commit of repository pentoo: 74942f833b8477119e9e74fbd242dceeaf950ce0 Timestamp of repository pf4public: Sun, 29 Oct 2023 04:03:25 +0000 Head commit of repository pf4public: c7e4229424a0dd57326552b60d9394cb402ca9b7 Timestamp of repository riscv: Sun, 29 Oct 2023 04:03:29 +0000 Head commit of repository riscv: 9e343d1db3b8b00f7f2b3d0aa1a3f008b4a7774c Timestamp of repository steam-overlay: Sun, 29 Oct 2023 04:02:59 +0000 Head commit of repository steam-overlay: 408e682e9b0ee72a313ba6b182f9d909c83080eb sh bash 5.2_p15-r7 ld GNU ld (Gentoo 2.41 p2) 2.41.0 app-misc/pax-utils: 1.3.7::gentoo app-shells/bash: 5.2_p15-r7::gentoo dev-java/java-config: 2.3.1-r1::gentoo dev-lang/perl: 5.38.0-r1::gentoo dev-lang/python: 3.11.6::gentoo, 3.12.0_p1::gentoo dev-lang/rust: 1.73.0::gentoo dev-lang/rust-bin: 1.73.0::gentoo dev-util/cmake: 3.27.7::gentoo dev-util/meson: 1.2.3::gentoo sys-apps/baselayout: 2.14::gentoo sys-apps/openrc: 0.51::gentoo sys-apps/sandbox: 2.38::gentoo sys-devel/autoconf: 2.13-r8::gentoo, 2.71-r7::gentoo sys-devel/automake: 1.16.5-r1::gentoo sys-devel/binutils: 2.41-r2::gentoo sys-devel/binutils-config: 5.5::gentoo sys-devel/clang: 16.0.6::gentoo, 17.0.3::gentoo sys-devel/gcc: 13.2.1_p20231014::gentoo sys-devel/gcc-config: 2.11::gentoo sys-devel/libtool: 2.4.7-r1::gentoo sys-devel/lld: 16.0.6::gentoo, 17.0.3::gentoo sys-devel/llvm: 16.0.6::gentoo, 17.0.3::gentoo sys-devel/make: 4.4.1-r1::gentoo sys-kernel/linux-headers: 6.5-r1::gentoo (virtual/os-headers) sys-libs/glibc: 2.38-r6::gentoo Repositories: gentoo location: /var/db/repos/gentoo sync-type: git sync-uri: https://github.com/gentoo/gentoo priority: -1000 volatile: False guru location: /var/db/repos/guru sync-type: git sync-uri: https://github.com/gentoo-mirror/guru.git masters: gentoo volatile: False librewolf location: /var/db/repos/librewolf sync-type: git sync-uri: https://codeberg.org/librewolf/gentoo.git masters: gentoo volatile: False local location: /var/db/repos/local masters: gentoo volatile: False pentoo location: /var/db/repos/pentoo sync-type: git sync-uri: https://github.com/gentoo-mirror/pentoo.git masters: gentoo volatile: False pf4public location: /var/db/repos/pf4public sync-type: git sync-uri: https://github.com/gentoo-mirror/pf4public.git masters: gentoo volatile: False riscv location: /var/db/repos/riscv sync-type: git sync-uri: https://github.com/gentoo-mirror/riscv.git masters: gentoo volatile: False steam-overlay location: /var/db/repos/steam-overlay sync-type: git sync-uri: https://github.com/gentoo-mirror/steam-overlay.git masters: gentoo volatile: False Binary Repositories: gentoobinhost priority: 1 sync-uri: https://gentoo.osuosl.org/releases/amd64/binpackages/17.1/x86-64_llvm ACCEPT_KEYWORDS="amd64 ~amd64" ACCEPT_LICENSE="@FREE @BINARY-REDISTRIBUTABLE" ADDR2LINE="llvm-addr2line" AR="llvm-ar" AS="clang -c" CBUILD="x86_64-pc-linux-gnu" CC="clang" CFLAGS="-march=native -O3 -flto=thin -pipe" CHOST="x86_64-pc-linux-gnu" CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /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/revdep-rebuild /etc/sandbox.d /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c" CPP="clang-cpp" CXX="clang++" CXXFLAGS="-march=native -O3 -flto=thin -pipe" DISTDIR="/var/cache/distfiles" 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="-march=native -O3 -flto=thin -pipe" FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs binpkg-multi-instance buildpkg buildpkg-live candy config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch 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="-march=native -O3 -flto=thin -pipe" GENTOO_MIRRORS="https://mirrors.rit.edu/gentoo/" LANG="en_US.utf8" LD="ld.lld" LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,--as-needed -Wl,-O2 -Wl,--as-needed" LEX="flex" MAKEOPTS="-j10" NM="llvm-nm" OBJCOPY="llvm-objcopy" OBJDUMP="llvm-objdump" 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" RANLIB="llvm-ranlib" READELF="llvm-readelf" SHELL="/bin/zsh" STRINGS="llvm-strings" STRIP="llvm-strip" USE="X a52 aac acl acpi alsa amd64 bluetooth branding bzip2 cairo cdda cdr clang crypt cups dbus dri dts dvd dvdr elogind encode exif flac gdbm gif gpm gtk gui iconv icu ipv6 jpeg lcms libnotify libtirpc llvm-libunwind lto lzma mad mng mp3 mp4 mpeg multilib ncurses nls nptl ogg opengl pam pango pcre pdf pipewire png policykit ppds pulseaudio qt5 readline screencast sdl seccomp sound spell ssl startup-notification svg test-rust tiff truetype udev udisks unicode upower usb vorbis vulkan wayland wifi wxwidgets x264 xattr xcb xft xml xv xvid zlib zstd" ABI_X86="64" ADA_TARGET="gnat_2021" 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 aes avx avx2 f16c fma3 pclmul popcnt rdrand sha sse3 sse4_1 sse4_2 sse4a ssse3" 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="php8-1" POSTGRES_TARGETS="postgres15" PYTHON_SINGLE_TARGET="python3_11" PYTHON_TARGETS="python3_11" RUBY_TARGETS="ruby31" VIDEO_CARDS="amdgpu radeonsi" 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: ARFLAGS, ASFLAGS, CCLD, CONFIG_SHELL, CPPFLAGS, CTARGET, CXXFILT, ELFEDIT, EMERGE_DEFAULT_OPTS, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RUSTFLAGS, SIZE, YACC, YFLAGS
Created attachment 873793 [details] build.log using gcc
Created attachment 873794 [details] build.log using clang w/o the march flag
Created attachment 873795 [details] build.log using clang w/ the march flag
Steps to reproduce: 1. emerge -va net-libs/xdp-tools using clang or gcc GCC Error: Warning: Num of global symbols in ./sharedobjs/libxdp.o ./sharedobjs/xsk.o (69) does NOT match with num of versioned symbols in libxdp.so (73). Please make sure all symbols are versioned in libxdp.map. --- libxdp_global_syms.tmp 2023-10-31 17:38:28.074637866 -0400 +++ libxdp_versioned_syms.tmp 2023-10-31 17:38:28.084637847 -0400 @@ -1,3 +1,7 @@ +LIBXDP_1.0.0 +LIBXDP_1.2.0 +LIBXDP_1.3.0 +LIBXDP_1.4.0 libxdp_clean_references libxdp_get_error libxdp_set_print make[2]: *** [Makefile:108: check_abi] Error 1 make[2]: Leaving directory '/var/tmp/portage/net-libs/xdp-tools-1.4.1/work/xdp-tools-1.4.1/lib/libxdp' make[1]: *** [Makefile:20: libxdp] Error 2 make[1]: Leaving directory '/var/tmp/portage/net-libs/xdp-tools-1.4.1/work/xdp-tools-1.4.1/lib' make: *** [Makefile:31: lib] Error 2 Clang Error (without fix): ld.lld: error: target emulation unknown: -m or at least one .o file required ld.lld: error: target emulation unknown: -m or at least one .o file required make[2]: *** [Makefile:134: xsk_def_xdp_prog.embed.o] Error 1
Disregard the march flag, it seems to not work anymore after I tried this morning?
1.4.1 builds and works fine without LTO, with both gcc and clang using bfd as linker. Building with LTO is known to be problematic, see: https://github.com/xdp-project/xdp-tools/issues/137 which is why we already filter-lto. However in this case the actual problem seems to be with lld. I can reproduce the "target emulation unknown" problem by building with clang+lld-17. This has been reported previously as well: https://github.com/xdp-project/xdp-tools/issues/335 and the recommendation is to use bfd. I don't know what the mentioned "embedding trick" is, so if you want to see lld supported it seems the best way is to open an issue upstream. Offhand I don't know how to force use of bfd or check for lld upfront; suggestions welcome.
Just found various instances of "if tc-ld-is-lld" in the tree - I'll see if I can do something with that.
(In reply to Holger Hoffstätte from comment #8) > Just found various instances of "if tc-ld-is-lld" in the tree - I'll see if > I can do something with that. just use tc-force-bfd
(In reply to Sam James from comment #9) > (In reply to Holger Hoffstätte from comment #8) > > Just found various instances of "if tc-ld-is-lld" in the tree - I'll see if > > I can do something with that. > > just use tc-force-bfd tc-ld-force-bfd doesn't seem to work: LDFLAGS is appended to but LD is still ld.lld. LDFLAGS might then still contain lld-specific flags that bfd doesn't like. Maybe I'm missing something but this seems doomed. The actual problem seems to be lld getting confused with embedding binary data. According to https://super-unix.com/unixlinux/freebsd-embedding-binary-data-into-an-executable-using-llvm-tools/ one can pass '-m <value>' for the "target emulation". Your quest: find the super secret value for the targets! Turns out those are at: https://github.com/llvm/llvm-project/blob/main/lld/ELF/Driver.cpp#L177 So I casually slapped "-m elf_amd64" into the line in question (https://github.com/xdp-project/xdp-tools/blob/master/lib/libxdp/Makefile#L134) and the build succeeds. \o/ Unfortunately there is no useful documentation anywhere for the -m flag, let alone a way to find a good way to map from the host to the required target emulation value.
(In reply to Holger Hoffstätte from comment #10) > (In reply to Sam James from comment #9) > > (In reply to Holger Hoffstätte from comment #8) > > > Just found various instances of "if tc-ld-is-lld" in the tree - I'll see if > > > I can do something with that. > > > > just use tc-force-bfd > > tc-ld-force-bfd doesn't seem to work: LDFLAGS is appended to but LD is still > ld.lld. LDFLAGS might then still contain lld-specific flags that bfd doesn't > like. Maybe I'm missing something but this seems doomed. > Nothing should really invoke LD directly...
(In reply to Sam James from comment #11) > Nothing should really invoke LD directly... We need to export LD because the custom Makefiles use whatever is exported. I now have a combination of filter-ldflags and hard-exporting LD="ld.bfd" which works, but that's obviously terrible. :( Instead of trying to undo all possible weird toolchain configurations it makes more sense to straight up abort the build in a sanity check.
So it turned out that tc-ld-force-bfd had a bug, which floppym helped fix. With that fix LD is now properly exported and everything works as expected. I had another improvement/simplification in mind and will make a PR soon.
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=36b6b67f771d5ec4373578e1599c013b7e679b24 commit 36b6b67f771d5ec4373578e1599c013b7e679b24 Author: Holger Hoffstätte <holger@applied-asynchrony.com> AuthorDate: 2023-11-02 11:17:12 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2023-11-22 12:02:14 +0000 net-libs/xdp-tools: force use of ld.bfd lld needs special care for embeddings in object files and this is not (yet) supported by upstream, so just force ld.bfd instead of creating more complications. Bug: https://bugs.gentoo.org/916591 Signed-off-by: Holger Hoffstätte <holger@applied-asynchrony.com> Signed-off-by: Sam James <sam@gentoo.org> net-libs/xdp-tools/xdp-tools-1.4.1.ebuild | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
Fixed hopefully.