simde icon indicating copy to clipboard operation
simde copied to clipboard

Undefined reference to roundeven functions

Open mbsmith opened this issue 1 year ago • 2 comments

I did a little poking around and didn't find the source of this issue. It seems like it should be using the gcc builtins for this, but instead are looking to musl which doesn't implement those at the moment. I did at least verify that this gcc version has those builtins via __has_builtin.

Compiler: GCC 14.2.0 Libc: Musl 1.2.5 test command: meson test --no-rebuild --print-errorlogs -C output

ninja: job failed: gcc  -o test/arm/neon/rndn-native-c test/arm/neon/rndn-native-c.p/rndn.c.o -Wl,--as-needed -Wl,--no-undefined -pie -Wl,--as-needed,-O1,--sort-common -Wl,-z,pack-relative-relocs -Os -fstack-clash-protection -Wformat -Werror=format-security -fno-plt -lm
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-native-c.p/rndn.c.o: in function `test_simde_vrndnq_f64':
rndn.c:(.text+0x619): undefined reference to `roundeven'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-native-c.p/rndn.c.o: in function `test_simde_vrndn_f32':
rndn.c:(.text+0x6cb): undefined reference to `roundevenf'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-native-c.p/rndn.c.o: in function `test_simde_vrndnh_f16':
rndn.c:(.text+0x7d6): undefined reference to `roundevenf'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-native-c.p/rndn.c.o: in function `test_simde_vrndn_f64':
rndn.c:(.text+0x940): undefined reference to `roundeven'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-native-c.p/rndn.c.o: in function `test_simde_vrndnq_f32':
rndn.c:(.text+0x9db): undefined reference to `roundevenf'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-native-c.p/rndn.c.o: in function `test_simde_vrndnq_f16':
rndn.c:(.text+0xafc): undefined reference to `roundevenf'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-native-c.p/rndn.c.o: in function `test_simde_vrndn_f16':
rndn.c:(.text+0xc36): undefined reference to `roundevenf'
collect2: error: ld returned 1 exit status
ninja: job failed: gcc  -o test/arm/neon/rndn-emul-c test/arm/neon/rndn-emul-c.p/rndn.c.o -Wl,--as-needed -Wl,--no-undefined -pie -Wl,--as-needed,-O1,--sort-common -Wl,-z,pack-relative-relocs -Os -fstack-clash-protection -Wformat -Werror=format-security -fno-plt -lm
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-emul-c.p/rndn.c.o: in function `test_simde_vrndnq_f64':
rndn.c:(.text+0x619): undefined reference to `roundeven'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-emul-c.p/rndn.c.o: in function `test_simde_vrndn_f32':
rndn.c:(.text+0x6cb): undefined reference to `roundevenf'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-emul-c.p/rndn.c.o: in function `test_simde_vrndnh_f16':
rndn.c:(.text+0x7d6): undefined reference to `roundevenf'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-emul-c.p/rndn.c.o: in function `test_simde_vrndn_f64':
rndn.c:(.text+0x940): undefined reference to `roundeven'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-emul-c.p/rndn.c.o: in function `test_simde_vrndnq_f32':
rndn.c:(.text+0x9db): undefined reference to `roundevenf'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-emul-c.p/rndn.c.o: in function `test_simde_vrndnq_f16':
rndn.c:(.text+0xafc): undefined reference to `roundevenf'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test/arm/neon/rndn-emul-c.p/rndn.c.o: in function `test_simde_vrndn_f16':
rndn.c:(.text+0xc36): undefined reference to `roundevenf'
collect2: error: ld returned 1 exit status
ninja: subcommands failed

mbsmith avatar Aug 12 '24 01:08 mbsmith

Yes, this sounds correct. emscripten uses musl and ran into this as well:

https://github.com/simd-everywhere/simde/blob/bd0532032487df1ea501ae8dc3f8e32abd5309b1/simde/simde-math.h#L1269

One could add a SIMDE_MUSL (or similar) to also skip the use of __builtin_roundeven for other musl users, unless there is a way for a header-only library to detect the use of musl at compile time

mr-c avatar Aug 12 '24 07:08 mr-c

ah, maybe there is a way to detect musl!

https://stackoverflow.com/a/78062291/1585509

mr-c avatar Aug 12 '24 07:08 mr-c

I have similar error when trying to build for android using new ndk version. And it's only for armv7 (arm64 builds fine).

  ld.lld: error: undefined symbol: roundevenf
  >>> referenced by sse.h:685 (../lib/simd_wrapper/simde/x86/sse.h:685)
  >>>               cpusimd.o:(simd4f_exp2_ps) in archive /mnt/data/prg/supertuxkart/supertuxkart-git/android/build/intermediates/cxx/Debug/3a1y6c28/obj/local/armeabi-v7a/libgraphics_utils.a
  >>> referenced by sse.h:685 (../lib/simd_wrapper/simde/x86/sse.h:685)
  >>>               cpusimd.o:(simd4f_pow12d5_ps) in archive /mnt/data/prg/supertuxkart/supertuxkart-git/android/build/intermediates/cxx/Debug/3a1y6c28/obj/local/armeabi-v7a/libgraphics_utils.a
  >>> referenced by sse.h:685 (../lib/simd_wrapper/simde/x86/sse.h:685)
  >>>               cpusimd.o:(simd4f_pow5d12_ps) in archive /mnt/data/prg/supertuxkart/supertuxkart-git/android/build/intermediates/cxx/Debug/3a1y6c28/obj/local/armeabi-v7a/libgraphics_utils.a
  >>> referenced 47 more times
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  make: *** [/opt/android/android-sdk/ndk/28.1.13356709/build/core/build-binary.mk:662: /mnt/data/prg/supertuxkart/supertuxkart-git/android/build/intermediates/cxx/Debug/3a1y6c28/obj/local/armeabi-v7a/libmain.so] Error 1

Should I just

#if 0

rather than

  #if \
     ((!defined(HEDLEY_EMSCRIPTEN_VERSION) || HEDLEY_EMSCRIPTEN_VERSION_CHECK(3, 1, 43)) && HEDLEY_HAS_BUILTIN(__builtin_roundevenf)) || \
      HEDLEY_GCC_VERSION_CHECK(10,0,0)

so that it doesn't try to use builtin roundevenf?

deveee avatar Aug 06 '25 21:08 deveee

Thank you @deveee ; I'm preparing a PR to automatically fix this for MUSL; but I'd like to have a test that builds SIMDE using musl to confirm. Advice on how to compile using MUSL on Debian/Ubuntu would be appreciated.

mr-c avatar Aug 07 '25 08:08 mr-c

@deveee , what is your musl version? I am unable to reproduce this issue for x86_64 & musl https://musl.cc/x86_64-linux-musl-cross.tgz ; but their musl version is old (git-b76f37f (2021-09-23))

mr-c avatar Aug 07 '25 10:08 mr-c