rust: add intrinsics to fix `-Os` builds
Miguel Ojeda
maintainerPATCH 1/1 rust: add intrinsics to fix `-Os` builds
Alice reported [1] that an arm64 build failed with:
ld.lld: error: undefined symbol: __extendsfdf2 >>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.a
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.a
ld.lld: error: undefined symbol: __truncdfsf2
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.a
Rust 1.80.0 or later together with CONFIG_CC_OPTIMIZE_FOR_SIZE=y is what triggers it.
In addition, x86_64 builds also fail the same way.
Similarly, compiling with Rust 1.82.0 (currently in nightly) makes another one appear, possibly due to the LLVM 19 upgrade there:
ld.lld: error: undefined symbol: __eqdf2
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_up) in archive vmlinux.a
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_down) in archive vmlinux.a
Gary adds [1]:
Quoted 4 lines
Usually the fix on rustc side is to mark those functions as
#[inline]All of {midpoint,next_up,next_down} are indeed unstable functions not marked as inline...
Fix all those by adding those intrinsics to our usual workaround.
--- rust/Makefile | 4 ++-- rust/compiler_builtins.rs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
rust/Makefile +2 -2
@@ -354,8 +354,8 @@ rust-analyzer: $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json redirect-intrinsics = \ - __addsf3 __eqsf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __unordsf2 \ - __adddf3 __ledf2 __ltdf2 __muldf3 __unorddf2 \ + __addsf3 __eqsf2 __extendsfdf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __truncdfsf2 __unordsf2 \ + __adddf3 __eqdf2 __ledf2 __ltdf2 __muldf3 __unorddf2 \ __muloti4 __multi3 \ __udivmodti4 __udivti3 __umodti3
rust/compiler_builtins.rs +3 -0
@@ -40,16 +40,19 @@ pub extern "C" fn $ident() {define_panicking_intrinsics! ("`f32` should not be used" , { __addsf3, __eqsf2, + __extendsfdf2, __gesf2, __lesf2, __ltsf2, __mulsf3, __nesf2, + __truncdfsf2, __unordsf2, });define_panicking_intrinsics! ("`f64` should not be used" , { __adddf3, + __eqdf2, __ledf2, __ltdf2, __muldf3,
base-commit: de9c2c66ad8e787abec7c9d7eff4f8c3cdd28aed
Signature · 1 line
2.46.0
Quoted 34 lines · Miguel Ojeda
Alice reported [1] that an arm64 build failed with:
ld.lld: error: undefined symbol:
__extendsfdf2>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.a
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.ald.lld: error: undefined symbol:
__truncdfsf2
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.aRust 1.80.0 or later together with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yis what triggers it.In addition,
x86_64builds also fail the same way.Similarly, compiling with Rust 1.82.0 (currently in nightly) makes another one appear, possibly due to the LLVM 19 upgrade there:
ld.lld: error: undefined symbol:
__eqdf2
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_up) in archive vmlinux.a
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_down) in archive vmlinux.aGary adds [1]:
Quoted 4 lines
Usually the fix on rustc side is to mark those functions as
#[inline]All of {midpoint,next_up,next_down} are indeed unstable functions not marked as inline...
Quoted 6 lines
Fix all those by adding those intrinsics to our usual workaround.
This fixes the issue I ran into.
Quoted 33 lines · Miguel Ojeda
Alice reported [1] that an arm64 build failed with:
ld.lld: error: undefined symbol:
__extendsfdf2>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.a
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.ald.lld: error: undefined symbol:
__truncdfsf2
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.aRust 1.80.0 or later together with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yis what triggers it.In addition,
x86_64builds also fail the same way.Similarly, compiling with Rust 1.82.0 (currently in nightly) makes another one appear, possibly due to the LLVM 19 upgrade there:
ld.lld: error: undefined symbol:
__eqdf2
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_up) in archive vmlinux.a
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_down) in archive vmlinux.aGary adds [1]:
Quoted 4 lines
Usually the fix on rustc side is to mark those functions as
#[inline]All of {midpoint,next_up,next_down} are indeed unstable functions not marked as inline...
Quoted 6 lines
Fix all those by adding those intrinsics to our usual workaround.
Put this one into rust-dev and confirm this could fix the issue with Rust 1.80. I also add a test with CONFIG_CC_OPTIMIZE_FOR_SIZE=y in my rust-dev script, so we can catch the similar issues earlier.
Regards,
Boqun
Quoted 50 lines
--- rust/Makefile | 4 ++-- rust/compiler_builtins.rs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)rust/Makefile +2
-2@@ -354,8 +354,8 @@ rust-analyzer: $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json redirect-intrinsics = \ - __addsf3 __eqsf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __unordsf2 \ - __adddf3 __ledf2 __ltdf2 __muldf3 __unorddf2 \ + __addsf3 __eqsf2 __extendsfdf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __truncdfsf2 __unordsf2 \ + __adddf3 __eqdf2 __ledf2 __ltdf2 __muldf3 __unorddf2 \ __muloti4 __multi3 \ __udivmodti4 __udivti3 __umodti3rust/compiler_builtins.rs +3
-0@@ -40,16 +40,19 @@ pub extern "C" fn $ident() {define_panicking_intrinsics! ("`f32` should not be used" , { __addsf3, __eqsf2, + __extendsfdf2, __gesf2, __lesf2, __ltsf2, __mulsf3, __nesf2, + __truncdfsf2, __unordsf2, });define_panicking_intrinsics! ("`f64` should not be used" , { __adddf3, + __eqdf2, __ledf2, __ltdf2, __muldf3,base-commit:
de9c2c66ad8e787abec7c9d7eff4f8c3cdd28aedSignature · 1 line
2.46.0
Quoted 4 lines · Boqun Feng
Put this one into rust-dev and confirm this could fix the issue with Rust 1.80. I also add a test with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yin my rust-dev script, so we can catch the similar issues earlier.
+1, same on my side.
Cheers,
Miguel
Quoted 31 lines · Miguel Ojeda
Alice reported [1] that an arm64 build failed with:
ld.lld: error: undefined symbol:
__extendsfdf2>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.a
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.ald.lld: error: undefined symbol:
__truncdfsf2
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.aRust 1.80.0 or later together with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yis what triggers it.In addition,
x86_64builds also fail the same way.Similarly, compiling with Rust 1.82.0 (currently in nightly) makes another one appear, possibly due to the LLVM 19 upgrade there:
ld.lld: error: undefined symbol:
__eqdf2
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_up) in archive vmlinux.a
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_down) in archive vmlinux.aGary adds [1]:
Quoted 2 lines
Usually the fix on rustc side is to mark those functions as
#[inline]
Quoted 8 lines
Quoted 2 lines
All of {midpoint,next_up,next_down} are indeed unstable functions not marked as inline...
Fix all those by adding those intrinsics to our usual workaround.
Should this link have the [1]?
Quoted 5 lines
Signed-off-by Miguel Ojeda <[email protected]>--- rust/Makefile | 4 ++-- rust/compiler_builtins.rs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
Also submitted a fix upstream https://github.com/rust-lang/rust/pull/128749.
- Trevor
Quoted 2 lines · Trevor Gross
Should this link have the
[1]?
Yeah, good eyes :)
Quoted 3 lines
Reviewed-by Trevor Gross <[email protected]>Also submitted a fix upstream https://github.com/rust-lang/rust/pull/128749.
Thanks a lot! Linked in the core sublist in issue #2.
Cheers,
Miguel
Quoted 33 lines · On Tue, 6 Aug 2024 17:06:19 +0200 Miguel Ojeda <[email protected]> wrote:
Alice reported [1] that an arm64 build failed with:
ld.lld: error: undefined symbol:
__extendsfdf2>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.a
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.ald.lld: error: undefined symbol:
__truncdfsf2
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.aRust 1.80.0 or later together with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yis what triggers it.In addition,
x86_64builds also fail the same way.Similarly, compiling with Rust 1.82.0 (currently in nightly) makes another one appear, possibly due to the LLVM 19 upgrade there:
ld.lld: error: undefined symbol:
__eqdf2
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_up) in archive vmlinux.a
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_down) in archive vmlinux.aGary adds [1]:
Quoted 4 lines
Usually the fix on rustc side is to mark those functions as
#[inline]All of {midpoint,next_up,next_down} are indeed unstable functions not marked as inline...
Quoted 6 lines
Fix all those by adding those intrinsics to our usual workaround.
Quoted 4 lines
--- rust/Makefile | 4 ++-- rust/compiler_builtins.rs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
Miguel Ojeda
AppliedQuoted 34 lines · Miguel Ojeda
Alice reported [1] that an arm64 build failed with:
ld.lld: error: undefined symbol:
__extendsfdf2>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.a
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.ald.lld: error: undefined symbol:
__truncdfsf2
>>> referenced by core.a6f5fc5794e7b7b3-cgu.0
>>> rust/core.o:(<f32>::midpoint) in archive vmlinux.aRust 1.80.0 or later together with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yis what triggers it.In addition,
x86_64builds also fail the same way.Similarly, compiling with Rust 1.82.0 (currently in nightly) makes another one appear, possibly due to the LLVM 19 upgrade there:
ld.lld: error: undefined symbol:
__eqdf2
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_up) in archive vmlinux.a
>>> referenced by core.20495ea57a9f069d-cgu.0
>>> rust/core.o:(<f64>::next_down) in archive vmlinux.aGary adds [1]:
Quoted 4 lines
Usually the fix on rustc side is to mark those functions as
#[inline]All of {midpoint,next_up,next_down} are indeed unstable functions not marked as inline...
Quoted 6 lines
Fix all those by adding those intrinsics to our usual workaround.
Applied to rust-fixes -- thanks everyone!
[ Trevor quickly submitted a fix to upstream Rust [2] that has already
been merged, to be released in Rust 1.82.0 (2024-10-17). - Miguel ]
[ Shortened Zulip link. - Miguel ]
Cheers,
Miguel