Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined reference to `__muloti4' when using clang #295

Closed
fornwall opened this issue Feb 2, 2017 · 2 comments
Closed

Undefined reference to `__muloti4' when using clang #295

fornwall opened this issue Feb 2, 2017 · 2 comments

Comments

@fornwall
Copy link

fornwall commented Feb 2, 2017

When building some things I encounter undefined reference to __muloti4 when changing from gcc to clang using both NDK r13 and r14-beta2.

I've found the following minimal test case:

$NDK/build/tools/make_standalone_toolchain.py \
	--api 21 \
	--arch arm64 \
	--install-dir $TOOLCHAIN
export PATH=$TOOLCHAIN/bin:$PATH

curl -O https://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.xz
tar xf m4-1.4.18.tar.xz
cd m4-1.4.18

export CC=aarch64-linux-android-clang
./configure --host=aarch64-linux-android
make

Is this a known issue with some known workaround?

@DanAlbert
Copy link
Member

I just started turning up some similar issues: #294

Going to close this one and track on the other since the problem is fundamentally the same. Thanks for reporting another case of it.

@fornwall
Copy link
Author

fornwall commented Feb 2, 2017

Thanks! Just found https://llvm.org/bugs/show_bug.cgi?id=16404 which confirms that this is due to symbols not in libgcc but in compiler-rt, and can happen either when using -fsanitize=undefined or, as in the test case above, __builtin_mul_overflow.

grendello added a commit to grendello/xamarin-android that referenced this issue Aug 26, 2019
Context: android/ndk#294
Context: android/ndk#295
Context: https://bugs.llvm.org/show_bug.cgi?id=16404

Add a couple of functions to `Utils` taking advantage of the compiler builtin
functions to perform integer addition and multiplication while checking for
overflows. If an overflow is detected, the application is terminated.

Due to a bug in Android NDK's clang, the multiplication is not performed using
"open" types but rather, currently, only `size_t` for the multiplication
operands.

Using a template for them would result in a link error as the compiler would
generate code to use 128-bit integers to perform the operation, attempting to
call the `__muloti4` intrinsic function which is usually defined in `libgcc`,
`libcompiler_rt` or `libcompiler_rt-extras` libraries. In the NDK case the
64-bit targets do not contain implementation of the function in neither of the
libraries mentioned above.
grendello added a commit to grendello/xamarin-android that referenced this issue Aug 26, 2019
Context: android/ndk#294
Context: android/ndk#295
Context: https://bugs.llvm.org/show_bug.cgi?id=16404

Add a couple of functions to `Utils` taking advantage of the compiler builtin
functions to perform integer addition and multiplication while checking for
overflows. If an overflow is detected, the application is terminated.

Due to a bug in Android NDK's clang, the multiplication is not performed using
"open" types but rather, currently, only `size_t` for the multiplication
operands.

Using a template for them would result in a link error as the compiler would
generate code to use 128-bit integers to perform the operation, attempting to
call the `__muloti4` intrinsic function which is usually defined in `libgcc`,
`libcompiler_rt` or `libcompiler_rt-extras` libraries. In the NDK case the
64-bit targets do not contain implementation of the function in neither of the
libraries mentioned above.
grendello added a commit to grendello/xamarin-android that referenced this issue Aug 26, 2019
Context: android/ndk#294
Context: android/ndk#295
Context: https://bugs.llvm.org/show_bug.cgi?id=16404

Add a couple of functions to `Utils` taking advantage of the compiler builtin
functions to perform integer addition and multiplication while checking for
overflows. If an overflow is detected, the application is terminated.

Due to a bug in Android NDK's clang, the multiplication is not performed using
"open" types but rather, currently, only `size_t` for the multiplication
operands.

Using a template for them would result in a link error as the compiler would
generate code to use 128-bit integers to perform the operation, attempting to
call the `__muloti4` intrinsic function which is usually defined in `libgcc`,
`libcompiler_rt` or `libcompiler_rt-extras` libraries. In the NDK case the
64-bit targets do not contain implementation of the function in neither of the
libraries mentioned above.
grendello added a commit to grendello/xamarin-android that referenced this issue Aug 26, 2019
Context: android/ndk#294
Context: android/ndk#295
Context: https://bugs.llvm.org/show_bug.cgi?id=16404

Add a couple of functions to `Utils` taking advantage of the compiler builtin
functions to perform integer addition and multiplication while checking for
overflows. If an overflow is detected, the application is terminated.

Due to a bug in Android NDK's clang, the multiplication is not performed using
"open" types but rather, currently, only `size_t` for the multiplication
operands.

Using a template for them would result in a link error as the compiler would
generate code to use 128-bit integers to perform the operation, attempting to
call the `__muloti4` intrinsic function which is usually defined in `libgcc`,
`libcompiler_rt` or `libcompiler_rt-extras` libraries. In the NDK case the
64-bit targets do not contain implementation of the function in neither of the
libraries mentioned above.
jonpryor pushed a commit to dotnet/android that referenced this issue Aug 27, 2019
Context: android/ndk#294
Context: android/ndk#295
Context: https://bugs.llvm.org/show_bug.cgi?id=16404

Add a couple of functions to `Utils` taking advantage of the compiler
builtin functions to perform integer addition and multiplication
while checking for overflows.  If an overflow is detected, the
application is terminated.

Due to a bug in Android NDK's clang, the multiplication is not
performed using "open" types but rather, currently, only `size_t`
for the multiplication operands.

Using a template for them would result in a link error as the
compiler would generate code to use 128-bit integers to perform the
operation, attempting to call the `__muloti4` intrinsic function
which is usually defined in `libgcc`, `libcompiler_rt` or the
`libcompiler_rt-extras` libraries.  In the NDK case the 64-bit
targets do not contain implementation of the function in any of the 
libraries mentioned above.
jforissier added a commit to jforissier/optee_os that referenced this issue Oct 18, 2019
FIXME: untested

Clang (with the compiler-rt library [1]) has builtins for checked
arithmetic, such as __builtin_add_overflow() etc. Use them.

[1] If compiler-rt is not explicitly selected (either via the compiler
option --rtlib=compiler-rt, or, in case the linker is used directly,
by adding the compiler-rt library file to the link), undefined symbol
error may occur. See:
android/ndk#295 (comment) for
details.

Signed-off-by: Jerome Forissier <jerome@forissier.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants