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

libclang_rt.asan-aarch64-android.so is missing. #2403

Closed
sebras opened this issue May 5, 2018 · 8 comments
Closed

libclang_rt.asan-aarch64-android.so is missing. #2403

sebras opened this issue May 5, 2018 · 8 comments
Labels
help wanted Help is wanted in order to solve the issue.

Comments

@sebras
Copy link

sebras commented May 5, 2018

I'm trying to compile something inside termux that uses clang's AddressSanitizer.

This is how to reproduce my issue (there might be shorter ways, but this works):

echo -e '#include <stdio.h>\nint main() { printf("hello\n"); }' > testing.c
clang -g -fsanitize=address -o testing testing.c`

When linking it fails with:

/data/data/com.termux/files/usr/bin/ld: cannot find /data/data/com.termux/files/usr/lib/clang/6.0.0/lib/linux/libclang_rt.asan-aarch64-android.so: No such file or directory

It would be nice to have this ASAN library because the resulting binaries catch many of the same errors as valgrind does, but the program consumes less resources when run (because all instructions are not emulated, it is just a subset that are instrumented). Besides running the same program in valgrind like this, results in lots of irrelevant warnings:

echo -e '#include <stdio.h>\nint main() { printf("hello\n"); }' > testing.c
clang -g -o testing testing.c`
valgrind ./testing

I'm open to testing a pre-release version of a compiled version of this library if it helps you in any way. Oh, and thanks for putting effort into termux, I just started using it. :)

@its-pointless
Copy link
Contributor

You can compile libcompiler_rt on device which should give you the needed library.

@sebras
Copy link
Author

sebras commented May 9, 2018

You can compile libcompiler_rt on device which should give you the needed library.

Sounds good, but it would be even better if clang was distributed with the library so people wouldn't have to compile it on their own. After all, it is part of the compiler. :)

@pd0wm
Copy link

pd0wm commented May 10, 2018

I ran into the same problem too, and added theses lines to the libllvm build script. If this is something you guys want to upstream I can make a pull request.

diff --git a/packages/libllvm/build.sh b/packages/libllvm/build.sh
index fd494ad4..e76a935a 100644
--- a/packages/libllvm/build.sh
+++ b/packages/libllvm/build.sh
@@ -56,6 +56,15 @@ termux_step_post_extract_package () {
        tar -xf $TERMUX_PKG_CACHEDIR/$CLANG_SRC_TAR -C tools
        mv tools/cfe-${TERMUX_PKG_VERSION}.src tools/clang

+       local COMPILER_RT_SRC_TAR=compiler-rt-${TERMUX_PKG_VERSION}.src.tar.xz
+       termux_download \
+                 https://releases.llvm.org/${TERMUX_PKG_VERSION}/$COMPILER_RT_SRC_TAR \
+                 $TERMUX_PKG_CACHEDIR/$COMPILER_RT_SRC_TAR \
+                 d0cc1342cf57e9a8d52f5498da47a3b28d24ac0d39cbc92308781b3ee0cea79a
+
+       tar -xf $TERMUX_PKG_CACHEDIR/$COMPILER_RT_SRC_TAR -C projects
+       mv projects/compiler-rt-${TERMUX_PKG_VERSION}.src projects/compiler-rt
+
        local LLD_SRC_TAR=lld-${TERMUX_PKG_VERSION}.src.tar.xz
        termux_download \
                https://llvm.org/releases/${TERMUX_PKG_VERSION}/$LLD_SRC_TAR \

@sebras
Copy link
Author

sebras commented May 10, 2018

@pd0wm assuming that compile-rt-*.src.tar.xz contains the source for the asan-library it looks alright to me. Does everything compile successfully with this patch? I assume it does, but better to ask. If so I'd like for this to be a PR that hopefully is included. :)

@tomty89
Copy link
Contributor

tomty89 commented May 10, 2018

If anyone is going to add it, please add it as a separate package.

@its-pointless
Copy link
Contributor

I already have a build script for it as a separate package. I made the lib available on my repo if anyone wants to test etc...

@pmatos
Copy link

pmatos commented Jan 13, 2020

I already have a build script for it as a separate package. I made the lib available on my repo if anyone wants to test etc...

Which repo are you talking about? Does this include the undefined behaviour sanitizer?

@ghost ghost added the help wanted Help is wanted in order to solve the issue. label May 6, 2020
Grimler91 added a commit that referenced this issue Sep 22, 2020
Grimler91 added a commit that referenced this issue Sep 22, 2020
Grimler91 added a commit that referenced this issue Sep 22, 2020
Grimler91 added a commit that referenced this issue Sep 23, 2020
@harieamjari
Copy link
Contributor

harieamjari commented Feb 9, 2021

You can compile libcompiler_rt on device which should give you the needed library.

I've tried compiling compiler-rt-9.0.0.src for my clang 9.0.0, and of course! it did gave me an error:

/data/data/com.termux/files/home/compiler-rt-9.0.0.src/lib/builtins/arm/sync_fetch_and_add_4.S:19:160: error: instruction requires: data-barriers
.p2align 2; .thumb; .syntax unified; .arm ; ; .globl __sync_fetch_and_add_4 ; .type __sync_fetch_and_add_4,%function ; ; .thumb_func ; __sync_fetch_and_add_4: dmb; mov r12, r0; .L_tryatomic_add_4 : ldrex r0, [r12]; add r2, r0, r1; strex r3, r2, [r12]; cmp r3, #0; bne .L_tryatomic_add_4; dmb; bx lr


                           ^

Note: I'm using a legacy Termux environment.

Edit:
I've tried using the prebuilt shared library from https://github.com/urho3d/android-ndk/blob/master/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/6.0.2/lib/linux/libclang_rt.asan-arm-android.so. Below is my short finding.

Compiling,

#include <stdlib.h>
int main(){
  int *a = malloc(sizeof(int));
  return 0;
}

with clang -g -O0 -fsanitize=address t.c did not produce an memory leak error from AddressSanitizer, however,

int main(){
  int *a=NULL;*a=1;
  return 0;
}

Did produce an error:

AddressSanitizer:DEADLYSIGNAL
=================================================================
==5697==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000 (pc 0xb6ef1ba4 bp 0xbebf6bd8 sp 0xbebf6bc0 T0)
==5697==The signal is caused by a WRITE memory access.
==5697==Hint: address points to the zero page.
    #0 0xb6ef1ba3  (a.out+0xba3)
    #1 0xb68c74ad  (/system/lib/libc.so+0x174ad)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (a.out+0xba3)
==5697==ABORTING
Aborted

This confirms that AddressSanitizer is working, but not properly.

Harshiv-Patel pushed a commit to Harshiv-Patel/termux-packages that referenced this issue May 13, 2021
@ghost ghost locked and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Help is wanted in order to solve the issue.
Projects
None yet
Development

No branches or pull requests

6 participants