Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[bug] asan + arm64 + shared libc++.so + -fuse_ld=lld + exceptions #988

@arturbac

Description

@arturbac

NDK 20-beta3
ABI arm64
ANDROID 8.1
I got a crash duringsanitizing application on armv64 when exception is thrown
I have build with -fuse-ld=lld which works perfectly for standard release application as i link staticaly to libc++
But when building sanitized application with wrap.sh i have to use shared libc++ and i found that it is linked to libgcc. As I remeber this will not work and i wll have crash on parsing eh frames, as I have. This problem doesn't exists in x86 code.

The last address in libc++ points to unwind from libgcc

llvm-symbolizer -demangle -addresses -inlining -pretty-print -functions=short -color -e aAM-libs/asan_dev/arm64-v8a/lc++_shared.so 0xb8f7c
0xb8f7c: _Unwind_SetGR at /usr/local/google/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/libgcc/unwind-dw2.c:275:0

And now I'm wondering where is problem in libc++ linked against libgcc instead of llvm/libclang_rt or something or in my build configuration

 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
 LineageOS Version: '15.1-20190412-NIGHTLY-santoni'
 Build fingerprint: 'Xiaomi/santoni/santoni:7.1.2/N2G47H/V9.2.1.0.NAMCNEK:user/release-keys'
 Revision: '0'
 ABI: 'arm64'
 pid: 27755, tid: 27857, name: Map  >>> pl.aqurat.automapa.dev <<<
 signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
     x0   0000000000000000  x1   0000000000006cd1  x2   0000000000000006  x3   0000000000000008
     x4   feff026ef0949b0a  x5   feff026ef0949b0a  x6   feff026ef0949b0a  x7   7f7f7f7fffffff7f
     x8   0000000000000083  x9   2adfd3b160362759  x10  0000001000000000  x11  0000000000000001
     x12  ffffffffffffffff  x13  000000000000000e  x14  0000000000000700  x15  0000000000000000
     x16  0000005943c72fa8  x17  000000791f0eb00c  x18  00000000787a5158  x19  0000000000006c6b
     x20  0000000000006cd1  x21  434c4e47432b2b00  x22  0000000000000000  x23  00000078443fc588
     x24  0000000000000000  x25  0000001f0875d2c0  x26  0000007843ae96a0  x27  0000007843ae9600
     x28  0000007843ae9660  x29  00000078443f8700  x30  000000791f09fa34
     sp   00000078443f86c0  pc   000000791f09fa50  pstate 0000000060000000
derer: Initialized EGL, version 1.4
derer: Swap behavior 2
 
 backtrace:

     #00 pc 000000000001da50  /system/lib64/libc.so (abort+104)
     #01 pc 00000000000b8f7c  /data/app/pl.aqurat.automapa.dev-VjYgEvoSwPZYI_d1drJDww==/lib/arm64/libc++_shared.so
     #02 pc 00000000000b5324  /data/app/pl.aqurat.automapa.dev-VjYgEvoSwPZYI_d1drJDww==/lib/arm64/libc++_shared.so (__gxx_pers
     #03 pc 00000000000da550  /data/app/pl.aqurat.automapa.dev-VjYgEvoSwPZYI_d1drJDww==/lib/arm64/libclang_rt.asan-aarch64-and
     #04 pc 00000000000da874  /data/app/pl.aqurat.automapa.dev-VjYgEvoSwPZYI_d1drJDww==/lib/arm64/libclang_rt.asan-aarch64-and
     #05 pc 0000000000069ad4  /system/lib64/libc++.so (__cxa_throw+112)
......

stripped important flags from final linking

--target=aarch64-none-linux-android27 --gcc-toolchain=/opt/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/opt/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fno-stack-protector -no-canonical-prefixes -fno-addrsig  -fPIC -std=gnu++17  -ggdb  -Ofast3  -stdlib=libc++  -Wl,--no-undefined  -fvisibility=default  -fsigned-char  -fintegrated-as  -ftemplate-depth=1024  -fno-data-sections  -fno-function-sections -fno-omit-frame-pointer  -fsanitize=address -fsanitize-address-use-after-scope -fno-optimize-sibling-calls  -fsanitize=alignment,bool,builtin,bounds,enum,float-cast-overflow,float-divide-by-zero,implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change,integer-divide-by-zero,nonnull-attribute,null,nullability-arg,nullability-assign,nullability-return,object-size,pointer-overflow,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,unsigned-integer-overflow,vla-bound  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack  -fuse-ld=lld -Wl,--build-id -shared -Wl,-soname,lib_mylib****_.so

And i don't understand that __cxa_throw is called from system wide libc++.so as I linked library against libc++_shared.so and it is attached with appliation and is used on aprsing eh frames.

#02 pc .../lib/arm64/libc++_shared.so (__gxx_pers
#05   /system/lib64/libc++.so (__cxa_throw+112)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions