shadowsocks / shadowsocks-android

A shadowsocks client for Android
Other
35.25k stars 11.57k forks source link

fix implicit-function-declaration error when updating NDK to r26+ #3163

Closed AaronChen0 closed 3 months ago

AaronChen0 commented 3 months ago

https://github.com/android/ndk/wiki/Changelog-r26#changes

Since NDK r26, Clang now treats -Wimplicit-function-declaration as an error rather than a warning in C11 and newer.

In the submodules, function pipe2 in redsocks.c from redsocks and function arc4random_addrandom in evutil_rand.c from libevent are implicitly declared.

Mygod commented 3 months ago

Hi thanks but this does not seem to work properly:


C/C++: ld.lld: error: undefined symbol: arc4random_addrandom
C/C++: >>> referenced by evutil_rand.c:198 (src/main/jni/libevent/evutil_rand.c:198)
C/C++: >>>               evutil_rand.o:(evutil_secure_rng_add_bytes) in archive /home/circleci/code/core/build/intermediates/cxx/Debug/4474u345/obj/local/arm64-v8a/libevent.a
C/C++: clang: error: linker command failed with exit code 1 (use -v to see invocation)
C/C++: make: *** [/home/circleci/android-sdk/ndk/27.0.12077973/build/core/build-binary.mk:674: /home/circleci/code/core/build/intermediates/cxx/Debug/4474u345/obj/local/arm64-v8a/libredsocks.so] Error 1```
AaronChen0 commented 3 months ago

It works in a release build.

Actually, the function evutil_secure_rng_add_bytes is not used in redsocks.

In a debug build, if no changes in libevent submodules, it's hard to fix this undefined symbol error. The arc4random_addrandom is defined in arc4random.c which contains another undefined symbol: ARC4_LOCK_. And ARC4_LOCK_ is defined in evutil_rand.c, but it depends on a EVENT__HAVE_ARC4RANDOM macro being undefined.

A solution is removing the function evutil_secure_rng_add_bytes in libevent since we don't use it in redsocks. Or is there a clang flag to turn this error off?

AaronChen0 commented 3 months ago

What a day! v2ray-plugin and v2ray-plugin-android also get updates. :)

Mygod commented 3 months ago

Ideally debug should be built too. :)

AaronChen0 commented 3 months ago

If there is not a clang flag to turn this error off, I can make a pull request to shadowsocks/libevent repo to remove the function evutil_secure_rng_add_bytes since this function is not used in redsocks and by other functions in libevent. What do you think?

Mygod commented 3 months ago

Hmm libevent hasn't been updated in a while. Maybe pulling upstream is needed.

Check: https://github.com/shadowsocks/libevent/tree/shadowsocks-android

AaronChen0 commented 3 months ago

Made a pull request at https://github.com/shadowsocks/libevent/pull/3

Mygod commented 3 months ago

Does that fix this?

AaronChen0 commented 3 months ago

Yes. The arc4random_addrandom function is now wrapped around a macro for a change from libevent upstream. I tested on a test branch. The build finished successfully, and the debug build apk worked in my phone.

Check https://github.com/AaronChen0/shadowsocks-android/tree/update_libevent

After that libevent pull request is merged, I will add a commit to this pull request to update submodule and Android.mk.

AaronChen0 commented 3 months ago

Ready to merge.