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

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

Merged
merged 3 commits into from
Aug 21, 2024

Conversation

AaronChen0
Copy link
Contributor

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
Copy link
Contributor

Mygod commented Aug 12, 2024

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
Copy link
Contributor Author

AaronChen0 commented Aug 13, 2024

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
Copy link
Contributor Author

AaronChen0 commented Aug 13, 2024

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

@Mygod
Copy link
Contributor

Mygod commented Aug 13, 2024

Ideally debug should be built too. :)

@AaronChen0
Copy link
Contributor Author

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
Copy link
Contributor

Mygod commented Aug 18, 2024

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

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

@AaronChen0
Copy link
Contributor Author

Made a pull request at shadowsocks/libevent#3

@Mygod
Copy link
Contributor

Mygod commented Aug 18, 2024

Does that fix this?

@AaronChen0
Copy link
Contributor Author

AaronChen0 commented Aug 19, 2024

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
Copy link
Contributor Author

Ready to merge.

@Mygod Mygod merged commit 3b1aa91 into shadowsocks:master Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants