Bug 270421 - graphics/librsvg2-rust: LTO fails under WITH_LLVM_BINUTILS (mismatched LLVM toolchain)
Summary: graphics/librsvg2-rust: LTO fails under WITH_LLVM_BINUTILS (mismatched LLVM t...
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-desktop (Team)
URL:
Keywords:
Depends on:
Blocks: 258872
  Show dependency treegraph
 
Reported: 2023-03-23 18:50 UTC by Luna
Modified: 2024-03-26 00:35 UTC (History)
3 users (show)

See Also:
vishwin: maintainer-feedback+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luna 2023-03-23 18:50:02 UTC
When trying to compile librsvg2-rust it fails with this error:

```
CPPFLAGS="" CFLAGS="-march=native -O3 -pipe -funroll-loops -march=znver2  -fstack-protector-strong -fno-strict-aliasing " LDFLAGS="-fstack-protector-strong " CC="cc" PKG_CONFIG="pkgconf" GI_HOST_OS="" DLLTOOL="false"  /usr/local/bin/g-ir-scanner  --add-include-path=. --symbol-prefix=rsvg --symbol-prefix=librsvg --warn-all --namespace=Rsvg --nsversion=2.0 --libtool="/bin/sh ./libtool" --pkg=pango --pkg=libxml-2.0 --include=GLib-2.0 --include=GObject-2.0 --include=Gio-2.0 --include=cairo-1.0 --include=GdkPixbuf-2.0 --pkg-export=librsvg-2.0   --library=librsvg-2.la --c-include="librsvg/rsvg.h" --cflags-begin -I./include -I. -I./include -DRSVG_COMPILATION --cflags-end  include/librsvg/rsvg.h include/librsvg/rsvg-cairo.h include/librsvg/rsvg-features.h include/librsvg/rsvg-version.h librsvg-2.la --output Rsvg-2.0.gir
g-ir-scanner: link: /bin/sh ./libtool --mode=link --tag=CC cc -o /wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0/tmp-introspectn2ree5hw/Rsvg-2.0 -export-dynamic -march=native -O3 -pipe -funroll-loops -march=znver2 -fstack-protector-strong -fno-strict-aliasing /wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0/tmp-introspectn2ree5hw/Rsvg-2.0.o -L. librsvg-2.la -L/usr/local/lib -lgio-2.0 -Wl,--export-dynamic -lgmodule-2.0 -pthread -lglib-2.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lintl -lharfbuzz -lxml2 -fstack-protector-strong
libtool: link: cc -o /wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0/tmp-introspectn2ree5hw/.libs/Rsvg-2.0 -march=native -O3 -pipe -funroll-loops -march=znver2 -fstack-protector-strong -fno-strict-aliasing /wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0/tmp-introspectn2ree5hw/Rsvg-2.0.o -Wl,--export-dynamic -fstack-protector-strong -Wl,--export-dynamic  -L. ./.libs/librsvg-2.so -L/usr/local/lib -lgmodule-2.0 -lpng16 -lcairo-gobject -lgdk_pixbuf-2.0 -lgio-2.0 -lxml2 -lpangocairo-1.0 -lcairo -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lintl -lharfbuzz -lfontconfig -lfreetype -lm -pthread -Wl,-rpath -Wl,/usr/local/lib
ld: error: undefined symbol: rsvg_error_get_type
>>> referenced by Rsvg-2.0.c
>>>               /wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0/tmp-introspectn2ree5hw/Rsvg-2.0.o:(GI_GET_TYPE_FUNCS_)

ld: error: undefined symbol: rsvg_handle_get_type
>>> referenced by Rsvg-2.0.c
>>>               /wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0/tmp-introspectn2ree5hw/Rsvg-2.0.o:(GI_GET_TYPE_FUNCS_)

ld: error: undefined symbol: rsvg_handle_flags_get_type
>>> referenced by Rsvg-2.0.c
>>>               /wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0/tmp-introspectn2ree5hw/Rsvg-2.0.o:(GI_GET_TYPE_FUNCS_)

ld: error: undefined symbol: rsvg_error_quark
>>> referenced by Rsvg-2.0.c
>>>               /wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0/tmp-introspectn2ree5hw/Rsvg-2.0.o:(GI_ERROR_QUARK_FUNCS_)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
linking of temporary binary failed: Command '['/bin/sh', './libtool', '--mode=link', '--tag=CC', 'cc', '-o', '/wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0/tmp-introspectn2ree5hw/Rsvg-2.0', '-export-dynamic', '-march=native', '-O3', '-pipe', '-funroll-loops', '-march=znver2', '-fstack-protector-strong', '-fno-strict-aliasing', '/wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0/tmp-introspectn2ree5hw/Rsvg-2.0.o', '-L.', 'librsvg-2.la', '-L/usr/local/lib', '-lgio-2.0', '-Wl,--export-dynamic', '-lgmodule-2.0', '-pthread', '-lglib-2.0', '-lpango-1.0', '-lgobject-2.0', '-lglib-2.0', '-lintl', '-lharfbuzz', '-lxml2', '-fstack-protector-strong']' returned non-zero exit status 1.
gmake[3]: *** [/usr/local/share/gobject-introspection-1.0/Makefile.introspection:156: Rsvg-2.0.gir] Error 1
gmake[3]: Leaving directory '/wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0'
gmake[2]: *** [Makefile:1075: all-recursive] Error 1
gmake[2]: Leaving directory '/wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0'
gmake[1]: *** [Makefile:710: all] Error 2
gmake[1]: Leaving directory '/wrkdirs/usr/ports/graphics/librsvg2-rust/work/librsvg-2.56.0'
*** Error code 1
```

Further up another error occurs:

```
libtool: link: ranlib .libs/librsvg_c_api.a
libtool: link: ( cd ".libs" && rm -f "librsvg_c_api.la" && ln -s "../librsvg_c_api.la" "librsvg_c_api.la" )
/bin/sh ./libtool  --tag=CC   --mode=link cc  -march=native -O3 -pipe -funroll-loops -march=znver2  -fstack-protector-strong -fno-strict-aliasing   -version-info 50:0:48 -export-dynamic -no-undefined -export-symbols-regex "^rsvg_.*"   -fstack-protector-strong  -o librsvg-2.la -rpath /usr/local/lib   librsvg_c_api.la -L/usr/local/lib -lpng16 -lcairo-gobject -lgdk_pixbuf-2.0 -lgio-2.0 -lxml2 -lpangocairo-1.0 -lcairo -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lintl -lharfbuzz -lfontconfig -lfreetype  -lm  
libtool: link: /usr/bin/nm -B   ./.libs/librsvg_c_api.a | /usr/bin/sed -n -e 's/^.*[     ]\([ABCDGIRSTW][ABCDGIRSTW]*\)[         ][      ]*\([_A-Za-z][_A-Za-z0-9]*\)$/\1 \2 \2/p' | /usr/bin/sed '/ __gnu_lto/d' | /usr/bin/sed 's/.* //' | sort | uniq > .libs/librsvg-2.exp
/usr/bin/nm: error: ./.libs/librsvg_c_api.a(rsvg-44ebdb0941189021.rsvg.623880d2-cgu.0.rcgu.o): Unknown attribute kind (82) (Producer: 'LLVM15.0.6-rust-1.68.0-stable' Reader: 'LLVM 13.0.0')

/usr/bin/nm: error: ./.libs/librsvg_c_api.a(pangocairo-8fa3a9f2ef17cb23.pangocairo.00c80890-cgu.0.rcgu.o): Unknown attribute kind (82) (Producer: 'LLVM15.0.6-rust-1.68.0-stable' Reader: 'LLVM 13.0.0')

LLVM ERROR: Type mismatch in constant table!
PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /usr/bin/nm -B ./.libs/librsvg_c_api.a
 #0 0x00000000007e3879 (/usr/bin/nm+0x7e3879)
 #1 0x00000000007e4443 (/usr/bin/nm+0x7e4443)
 #2 0x0000000824ea07a0 (/lib/libthr.so.3+0x1a7a0)
 #3 0x0000000824e9fdac (/lib/libthr.so.3+0x19dac)
 #4 0x00007fffffffe2d3 ([vdso]+0x2d3)
 #5 0x000000082871914a thr_kill (/lib/libc.so.7+0x14414a)
 #6 0x000000082868a424 _raise (/lib/libc.so.7+0xb5424)
 #7 0x0000000828743ae9 abort (/lib/libc.so.7+0x16eae9)
 #8 0x00000000007d3a73 (/usr/bin/nm+0x7d3a73)
 #9 0x00000000007d3937 (/usr/bin/nm+0x7d3937)
#10 0x00000000006f85c6 (/usr/bin/nm+0x6f85c6)
#11 0x00000000006759f1 (/usr/bin/nm+0x6759f1)
#12 0x0000000000680a76 (/usr/bin/nm+0x680a76)
#13 0x0000000000669d2a (/usr/bin/nm+0x669d2a)
#14 0x0000000000665cac (/usr/bin/nm+0x665cac)
#15 0x000000000078eeaf (/usr/bin/nm+0x78eeaf)
#16 0x000000000063f0b1 (/usr/bin/nm+0x63f0b1)
#17 0x000000000063d172 (/usr/bin/nm+0x63d172)
#18 0x000000000054c17c (/usr/bin/nm+0x54c17c)
Abort trap (core dumped)
libtool: link: /usr/bin/egrep -e "^rsvg_.*" ".libs/librsvg-2.exp" > ".libs/librsvg-2.expT"
libtool: link: mv -f ".libs/librsvg-2.expT" ".libs/librsvg-2.exp"
libtool: link: echo "{ global:" > .libs/librsvg-2.so.2.48.0-ver
```

Disabling lto with LTO_UNSAFE= is a temporary workaround.
Comment 1 Jan Beich freebsd_committer freebsd_triage 2023-03-23 19:31:33 UTC
I can't reproduce 12.3/12.4/13.1/-CURRENT amd64/i386. Need more details or a poudriere log.
Comment 2 Luna 2023-03-23 19:38:13 UTC
I've compiled the world with 'WITH_LLVM_BINUTILS=YES'.
It seems like librsvg2-rust compiles without problems when using elftoolchain nm, but fails when using llvm-nm because of the version mismatch.
Comment 3 Jan Beich freebsd_committer freebsd_triage 2023-03-24 00:54:44 UTC
Likely a regresion from ports 967022fd812c + ports c9c14b819fe4. However, WITH_LLVM_BINUTILS is generally not yet supported until bug 258872 is fixed.
Comment 4 (intentionally left blank) 2023-05-23 05:56:50 UTC
I have similar here with -CURRENT (base LLVM 15) and Rust using LLVM 16:

[...]
cargo --locked build --verbose  --release --bin rsvg-convert
libtool: link: /usr/bin/nm -B   ./.libs/librsvg_c_api.a | /usr/bin/sed -n -e
 's/^.*[         ]\([ABCDGIRSTW][ABCDGIRSTW]*\)[         ][      ]*\([_A-Za-
z][_A-Za-z0-9]*\)$/\1 \2 \2/p' | /usr/bin/sed '/ __gnu_lto/d' | /usr/bin/sed
 's/.* //' | sort | uniq > .libs/librsvg-2.exp
/usr/bin/nm: error: ./.libs/librsvg_c_api.a(rsvg-6aae7815bd5a5a95.rsvg.f7c38f4e-cgu.0.rcgu.o): Unknown attribute kind (86) (Producer: 'LLVM16.0.3' Reader: 'LLVM 15.0.7')
[...]

/usr/bin/nm is detected in configure script:

[...]
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
[...]

To avoid Rust LLVM and nm version match, try (adjust 16 for Rust LLVM version in use):

diff --git a/graphics/librsvg2-rust/Makefile b/graphics/librsvg2-rust/Makefile
--- a/graphics/librsvg2-rust/Makefile
+++ b/graphics/librsvg2-rust/Makefile
@@ -13,7 +13,8 @@ WWW=		https://live.gnome.org/LibRsvg
 
 LICENSE=	LGPL20
 
-BUILD_DEPENDS=	rst2man:textproc/py-docutils
+BUILD_DEPENDS=	rst2man:textproc/py-docutils \
+		llvm-nm16:devel/llvm16
 LIB_DEPENDS=	libfontconfig.so:x11-fonts/fontconfig \
 		libfreetype.so:print/freetype2 \
 		libharfbuzz.so:print/harfbuzz \
@@ -30,7 +31,7 @@ CONFIGURE_ARGS=	--disable-Bsymbolic \
 		--disable-dependency-tracking \
 		--disable-static \
 		--enable-vala
-CONFIGURE_ENV=	${CARGO_ENV}
+CONFIGURE_ENV=	${CARGO_ENV} NM=/usr/local/bin/llvm-nm16
 MAKE_ENV=	${CARGO_ENV}
 CARGO_ENV=	RUST_TARGET=${CARGO_BUILD_TARGET}
 CARGO_BUILD=	no

Alternatively, investigate if parts of librsvg2-rust invoking cargo directly (rg 'CARGO_RELEASE_ARGS' in WRKDIR) could opt-out either from LTO (maybe ThinLTO is partly used, and switching to fat LTO would help) or build.
Comment 5 (intentionally left blank) 2023-05-23 06:02:01 UTC
This needs to be added to "Depends on" of 
Bug 258872 - [exp-run] WITH_LLVM_BINUTILS

as that would hit a FreeBSD version built with WITH_LLVM_BINUTILS,
and Rust LLVM of a mismatched version. I can't add this bug to the
depends of bug 258872
Comment 6 Ed Maste freebsd_committer freebsd_triage 2023-05-23 14:55:29 UTC
LTO requires that the compiler and nm are matched, so we will have to find a way to make this happen for all ports that may be built with LTO and use an LLVM other than from the base system.
Comment 7 Charlie Li freebsd_committer freebsd_triage 2023-05-23 19:47:06 UTC
USES=llvm makes matching LLVM versions easy, but there's more to the story. Since the Rust toolchain will never (unless something drastically changes) use base system LLVM, we may have to unconditionally use ports LLVM, like the gecko@ ports, if/when WITH_LLVM_BINUTILS becomes ready enough.
Comment 8 Ed Maste freebsd_committer freebsd_triage 2024-03-26 00:35:38 UTC
> if/when WITH_LLVM_BINUTILS becomes ready enough

It is ready to go now, so I'm hopeful these few bugs (this one, and 270962 and 270963) can be addressed before we switch it on.