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

[r12] Compiling any static executable leads to "error: undefined reference to 'atexit'" #132

Closed
chenxiaolong opened this issue Jun 24, 2016 · 6 comments
Assignees
Milestone

Comments

@chenxiaolong
Copy link

Test repo available here: https://github.com/chenxiaolong/ndk_atexit_test

Starting with the r12 release, it's no longer possible to compile static executables (at least with clang). The repo above contains a C program that does nothing except return EXIT_SUCCESS and it fails with the an undefined reference to atexit error.

[ndk_atexit_test] ./test.sh                                                                                                              13:02:54  ☁  master ☂ ⚡ ✭
--- Testing android-24 ---
[armeabi-v7a] Compile thumb  : main <= main.c
[armeabi-v7a] Executable     : main
external/jemalloc/src/jemalloc.c:707: error: undefined reference to 'atexit'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/opt/android-ndk/build/core/build-binary.mk:691: out/ndk_armeabi-v7a/obj/local/armeabi-v7a/main] Error 1

This happens with platforms 24, 23, 22, and 21. r11c did not have this issue.

@chenxiaolong
Copy link
Author

It seems like crtbegin_static.o is missing the atexit symbol in r12:

[lib] nm /opt/android-ndk/platforms/android-24/arch-arm/usr/lib/crtbegin_static.o | grep -i atexit
[lib] nm /opt/android-ndk-r11c/platforms/android-24/arch-arm/usr/lib/crtbegin_static.o | grep -i atexit 
00000088 T atexit
00000000 T __atexit_handler_wrapper
         U __cxa_atexit

chenxiaolong pushed a commit to chenxiaolong/DualBootPatcher that referenced this issue Jun 24, 2016
@DanAlbert DanAlbert added this to the r13 milestone Jun 27, 2016
@DanAlbert DanAlbert self-assigned this Jun 27, 2016
@DanAlbert
Copy link
Member

I think the breaking change was https://android-review.googlesource.com/#/c/219746/

Found some more skeletons in the closet. Looks like for some inexplicable reason crtbegin_static.c was a symlink to crtbegin_dynamic.c. The static one expects atexit to come from libc.a, while the dynamic one includes the implementation via atexit.h. Starting with android-21, atexit is no longer in libc.a.

@DanAlbert
Copy link
Member

These three changes ought to fix this: https://android-review.googlesource.com/#/q/topic:fix-static-exe

Awaiting review, but unless further testing finds any issues with it this should be good to go for r13.

@chenxiaolong: It's not quite all static executables that are broken. If you can target something lower than android-21 then it will build fine. Is that workaround sufficient for you?

@chenxiaolong
Copy link
Author

@DanAlbert Thanks for the fixes! I won't be able to compile and test until after I return from my business trip on Wednesday though.

Unfortunately, I can't use anything lower than android-21 because I need the xattr functions (fsetxattr, fgetxattr, etc.).

@DanAlbert
Copy link
Member

Changes are submitted.

BoredOutOfMyGit pushed a commit to codeaurora-unofficial/platform-development that referenced this issue Jul 17, 2016
The only difference between crtbegin_static.c and crtbegin_dynamic.c
is the inclusion of the atexit implementation. Until android-21,
atexit was included in libc.a. After android-21, it's expected to
come from crtbegin. In true NDK fashion, this isn't true across all
architectures. x86 and mips always had this coming from crtbegin.

Copy the android-9 ARM CRT files to android-21 and merge the crtbegin
implementations.

We should probably take a closer look at everything going on here at
some point to make sure we don't need anything new from the bionic
sources.

Test: Improved tests/device/static-executable in the NDK, built ARM
      NDK, tested with and without `--platform android-21`.
Bug: android/ndk#132
Change-Id: Ibc73984db25359590384391583bf24f738c8dd30
chenxiaolong pushed a commit to chenxiaolong/DualBootPatcher that referenced this issue Aug 28, 2016
chenxiaolong pushed a commit to chenxiaolong/DualBootPatcher that referenced this issue Aug 28, 2016
miodragdinic pushed a commit to MIPS/ndk that referenced this issue Jan 12, 2017
The static-executable test couldn't have caught
android/ndk#132 because it's already
marked broken for a different issue (duplicate symbols caused by L's
libc.a including new/delete and friends colliding with libsupc++ for
exception support).

To make our test suite marginally less useless, split this into two
tests. static-executable will be the bare minimum static executable
test, and static-executable-exceptions will make sure exception
support works (or, for now, doesn't).

Test: Applied with other patches in topic (one of which removes the
      broken annotation for static-executable), static-executable
      passes for ARM android-21 and static-executable-exceptions
      remains a known failure.
Bug: http://b/24468267
Bug: android/ndk#132

Change-Id: Ib83c8f01974db5139ab4069996a6bf2187e51a94
miodragdinic pushed a commit to MIPS/ndk that referenced this issue Jan 12, 2017
Before this, if an older platform level had separate source files for
crtbegin_dynamic.o and crtbegin_static.o and a newer platform level
had a shared source file, the shared source would not be used for the
static version because the destination directory would have been
pre-populated by the old version.

Test: Together with the other CLs in the topic, built the ARM NDK and
      ran tests/device/static-executable with and without
      `--platform android-21`.
Bug: android/ndk#132

Change-Id: I8d656076a64361935c427d6cbb7f7f418db8af21
@arielmingrone
Copy link

I have this problem with platform 24 in r14b compiling ffmpeg libs into static one
external/jemalloc/src/jemalloc.c:707: error: undefined reference to 'atexit'
external/jemalloc/src/prof.c:1377: error: undefined reference to 'atexit'
Maybe you can help?

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

No branches or pull requests

3 participants