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

-fsanitize=signed-integer-overflow causes linker errors #184

Closed
ngg opened this issue Aug 26, 2016 · 6 comments
Closed

-fsanitize=signed-integer-overflow causes linker errors #184

ngg opened this issue Aug 26, 2016 · 6 comments
Assignees
Labels
Milestone

Comments

@ngg
Copy link

ngg commented Aug 26, 2016

If I compile with -fsanitize=signed-integer-overflow flag the binaries try to call the __mulodi4 function and it will give an undefined reference linker error. This happens both on ARM and x86 archs. Most of the other similar sanitizers work well.

@DanAlbert DanAlbert added this to the unplanned milestone Sep 14, 2016
@DanAlbert DanAlbert removed this from the unplanned milestone Sep 14, 2016
@DanAlbert
Copy link
Member

Sorry, somehow I didn't see this bug until now.

__mulodi4 isn't provided by libgcc which is needed to implement the trapping integer overflow arithmetic. We need to start using compiler-rt for the NDK to provide support for this. It's something that we have people looking in to, but I don't have an estimate on the timeline (though @stephenhines might).

@stephenhines
Copy link
Collaborator

https://llvm.org/bugs/show_bug.cgi?id=28629 is the upstream bug for this. The truth is that we want to switch to compiler-rt, but just haven't had the ability to complete the transition. It is something we are looking at doing, however I don't have a great estimate on when it will be completed. You can add your own weak versions of those symbols in the meantime to get unblocked.

@sitsofe
Copy link

sitsofe commented Oct 12, 2017

(For others who might end up here via a search: if you're trying to compile using clang's undefined sanitizer on a regular 32 bit Linux distro and you're hitting the "undefined reference to `__mulodi4'" a workaround might be to link against the appropriate libclang_rt.builtins* :

$ cat <<EOF > mulodi4.c 
int main(void) {
	long long ll = 1;
	int i1 = 2;
	return (ll * i1);
}
EOF
$ clang-4.0 -fsanitize=undefined mulodi4.c
/tmp/foo-605e44.o: In function `main':
foo.c:(.text+0x5a): undefined reference to `__mulodi4'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ clang-4.0 -fsanitize=undefined mulodi4.c /usr/lib/llvm-4.0/lib/clang/4.0.0/lib/linux/libclang_rt.builtins-i686.a 
$ echo $?
0

See ldc-developers/ldc#813 for an example of a project that works around the problem)

hubot pushed a commit to aosp-mirror/platform_system_core that referenced this issue Nov 8, 2017
The parent change ran into an issue where enabling UBSan on an i686
build caused it to use __mulodi4.

android/ndk#184 documents linking against
libclang_rt.builtins-i686.a, but that's not available from soong either.

Bug: 62378620
Bug: 29412086
Test: x86 builds work again
Change-Id: I730d59558aa4ed28f8a11b5393e037111e320f29
@DanAlbert DanAlbert added this to the r18 milestone Mar 16, 2018
@DanAlbert
Copy link
Member

This no longer happens for this particular case in r17. Seems Clang isn't generating this call for signed-integer-overflow any more.

Closing in favor of #294 as the root cause rather than the symptom.

smokku pushed a commit to D-os/libcutils that referenced this issue Jul 2, 2018
The parent change ran into an issue where enabling UBSan on an i686
build caused it to use __mulodi4.

android/ndk#184 documents linking against
libclang_rt.builtins-i686.a, but that's not available from soong either.

Bug: 62378620
Bug: 29412086
Test: x86 builds work again
Change-Id: I730d59558aa4ed28f8a11b5393e037111e320f29
@AstralStorm
Copy link

AstralStorm commented Oct 29, 2018

Happens again in r18 on armv7, 18.1.5063045:
ndk-bundle/sources/cxx-stl/llvm-libc++/include/chrono:388: error: undefined reference to '__mulodi4'

@DanAlbert
Copy link
Member

It's fixed in r19 though, so nothing to do here: #294.

Kudo added a commit to Kudo/jsc-android-buildscripts that referenced this issue Apr 12, 2019
Summary:
    Error message:
    DerivedSources/ForwardingHeaders/wtf/CheckedArithmetic.h:458: error: undefined reference to '__mulodi4'

    This happens only on debug build + ARMv7

    NDK r19 did fix this:
    android/ndk#184

    To aligned NDK r17c with RN, fallback to use non bulitin overflow
    check.

    Related context:
    https://codereview.chromium.org/2011073002
Mrick343 pushed a commit to euclidTeam/system_core that referenced this issue May 8, 2024
The parent change ran into an issue where enabling UBSan on an i686
build caused it to use __mulodi4.

android/ndk#184 documents linking against
libclang_rt.builtins-i686.a, but that's not available from soong either.

Bug: 62378620, 29412086
Test: x86 builds work again
Change-Id: I730d59558aa4ed28f8a11b5393e037111e320f29
Mrick343 pushed a commit to euclidTeam/system_core that referenced this issue May 8, 2024
The parent change ran into an issue where enabling UBSan on an i686
build caused it to use __mulodi4.

android/ndk#184 documents linking against
libclang_rt.builtins-i686.a, but that's not available from soong either.

Bug: 62378620
Test: x86 builds work again
Change-Id: I730d59558aa4ed28f8a11b5393e037111e320f29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants