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

libc.so and time.h are inconsistent about when timegm was introduced #130

Closed
JonathanLennox opened this issue Jun 23, 2016 · 11 comments
Closed
Assignees
Labels
Milestone

Comments

@JonathanLennox
Copy link

In NDK r12b, libc.so and time.h are inconsistent about which Android platform versions have the timegm() function. The headers are written such that they were introduced in version 21, but the libraries indicate they were introduced in version 12.

$ cd ~/Android/android-ndk-r12b

$ grep timegm platforms/android-*/arch-arm/usr/include/time.h
platforms/android-21/arch-arm/usr/include/time.h:extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;
platforms/android-22/arch-arm/usr/include/time.h:extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;
platforms/android-23/arch-arm/usr/include/time.h:extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;
platforms/android-24/arch-arm/usr/include/time.h:extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;

$ ./toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-nm --print-file-name platforms/android-*/arch-arm/usr/lib/libc.so | grep -w timegm
platforms/android-12/arch-arm/usr/lib/libc.so:0000af0c T timegm
platforms/android-13/arch-arm/usr/lib/libc.so:0000af0c T timegm
platforms/android-14/arch-arm/usr/lib/libc.so:0000af0c T timegm
platforms/android-15/arch-arm/usr/lib/libc.so:0000af44 T timegm
platforms/android-16/arch-arm/usr/lib/libc.so:0000b344 T timegm
platforms/android-17/arch-arm/usr/lib/libc.so:0000b8d4 T timegm
platforms/android-18/arch-arm/usr/lib/libc.so:0000ba64 T timegm
platforms/android-19/arch-arm/usr/lib/libc.so:0000be9c T timegm
platforms/android-21/arch-arm/usr/lib/libc.so:0000f19c T timegm
platforms/android-22/arch-arm/usr/lib/libc.so:0000f19c T timegm
platforms/android-23/arch-arm/usr/lib/libc.so:0001004c T timegm
platforms/android-24/arch-arm/usr/lib/libc.so:00010aa0 T timegm

The problem this causes is that when building software that uses GNU autoconf (using a standalone toolchain) and targeting Android versions 12 - 19, autoconf's configure test detects that timegm exists, but the build fails at runtime because the function is undeclared.

checking for timegm... yes

/Users/jonathan/Android/android-ndk-r12b/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang -target armv7-none-linux-androideabi -gcc-toolchain /Users/jonathan/Android/android-ndk-r12b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64  -DANDROID --sysroot /Users/jonathan/Android/android-ndk-r12b/platforms/android-16/arch-arm  -g -O2 -Wall -Wextra -Wno-unused-parameter -fstack-protector -ffunction-sections -fdata-sections -march=armv7-a -mtune=cortex-a8 -mfloat-abi=softfp -mthumb -ftree-vectorize -fno-short-enums -fvisibility=hidden -fpic -Wc++-compat -Werror=implicit-function-declaration -D_REENTRANT -D_GNU_SOURCE -pthread  -MT Lmi/Ui/Client/LmiUiClient.o -MD -MP -MF $depbase.Tpo -c -o Lmi/Ui/Client/LmiUiClient.o /Users/jonathan/Cvs/Branch-2.2.0/SDK/Lmi/Ui/Client/LmiUiClient.c &&\
    mv -f $depbase.Tpo $depbase.Po
In file included from /Users/jonathan/Cvs/Branch-2.2.0/SDK/Lmi/Ui/Client/LmiUiClient.c:22:
In file included from /Users/jonathan/Cvs/Branch-2.2.0/SDK/Lmi/Client/LmiClient.h:25:
In file included from /Users/jonathan/Cvs/Branch-2.2.0/SDK/Lmi/Os/LmiLog.h:46:
In file included from /Users/jonathan/Cvs/Branch-2.2.0/SDK/Lmi/Os/LmiTime.h:1261:
/Users/jonathan/Cvs/Branch-2.2.0/SDK/Lmi/Os/LmiTimeInline.h:231:8: error: implicit declaration of function
      'timegm' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        val = timegm(&tmp_tm);
              ^
/Users/jonathan/Cvs/Branch-2.2.0/SDK/Lmi/Os/LmiTimeInline.h:231:8: note: did you mean 'time'?
/Users/jonathan/Android/android-ndk-r12b/platforms/android-16/arch-arm/usr/include/time.h:40:17: note: 'time'
      declared here
extern time_t   time(time_t *);
                ^
1 error generated.

This problem is new in NDK 12; NDK 11c does not have the problem.

$ cd ~/Android/android-ndk-r11c


$ grep timegm platforms/android-*/arch-arm/usr/include/time.h
platforms/android-21/arch-arm/usr/include/time.h:extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;
platforms/android-23/arch-arm/usr/include/time.h:extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;
platforms/android-24/arch-arm/usr/include/time.h:extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;

$ ./toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-nm --print-file-name platforms/android-*/arch-arm/usr/lib/libc.so | grep -w timegm
platforms/android-21/arch-arm/usr/lib/libc.so:0000f19c T timegm
platforms/android-23/arch-arm/usr/lib/libc.so:0001004c T timegm
platforms/android-24/arch-arm/usr/lib/libc.so:0001004c T timegm
@jmgao jmgao self-assigned this Jun 23, 2016
@jmgao jmgao added this to the r13 milestone Jun 23, 2016
@jmgao jmgao added the headers label Jun 23, 2016
@jmgao
Copy link
Contributor

jmgao commented Jun 23, 2016

This will be fixed by unified headers (#120)

@JonathanLennox
Copy link
Author

Is there any possibility it could be fixed sooner, manually, in an r12 update? As I said it's breaking our build.

@enh
Copy link
Contributor

enh commented Jun 24, 2016

until r13 you can manually fix it in your copy of <time.h>, just add

extern time_t timelocal(struct tm*);
extern time_t timegm(struct tm*);

to the appropriate time.h for the API level you're targeting (or to your generated stand-alone toolchain).

@enh enh closed this as completed Jun 24, 2016
@JonathanLennox
Copy link
Author

Unified headers have been pushed to r14. Can this be re-opened for r13?

@DanAlbert
Copy link
Member

Unfortunately they are still far from ready :\

@JonathanLennox
Copy link
Author

Yes -- given that, can a specific timegm() fix be made for r13, to the current non-unified headers? It should just be a matter of adding

extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;

to /usr/include/time.h for all the relevant platforms.

The relevant platforms are:

~/Android/android-ndk-r13-beta1$ for p in platforms/android-*/arch-*; do if nm $p/usr/lib*/libc.so | grep -ql timegm && ! grep -ql timegm $p/usr/include/time.h; then echo $p; fi; done
platforms/android-12/arch-arm
platforms/android-12/arch-mips
platforms/android-12/arch-x86
platforms/android-13/arch-arm
platforms/android-13/arch-mips
platforms/android-13/arch-x86
platforms/android-14/arch-arm
platforms/android-14/arch-mips
platforms/android-14/arch-x86
platforms/android-15/arch-arm
platforms/android-15/arch-mips
platforms/android-15/arch-x86
platforms/android-16/arch-arm
platforms/android-16/arch-mips
platforms/android-16/arch-x86
platforms/android-17/arch-arm
platforms/android-17/arch-mips
platforms/android-17/arch-x86
platforms/android-18/arch-arm
platforms/android-18/arch-mips
platforms/android-18/arch-x86
platforms/android-19/arch-arm
platforms/android-19/arch-mips
platforms/android-19/arch-x86
platforms/android-9/arch-arm
platforms/android-9/arch-mips
platforms/android-9/arch-x86

@DanAlbert
Copy link
Member

Ah, I misunderstood what you meant (I was thinking "pushed" in the git sense of the word).

Yeah, let me see if I can get a patch together. Should be fine pending any surprises.

@DanAlbert DanAlbert reopened this Sep 12, 2016
@DanAlbert DanAlbert self-assigned this Sep 12, 2016
@JonathanLennox
Copy link
Author

Thanks.

It looks like this affects timelocal() as well.

@DanAlbert
Copy link
Member

@DanAlbert
Copy link
Member

Submitted to master. Cherry-picks to r13 are waiting for presubmit.

@DanAlbert
Copy link
Member

Changes are in r13. Note that they aren't in the r13-beta2 release that was released earlier today (that build was actually finalized ~3 weeks ago), but they'll be in the stable release.

BoredOutOfMyGit pushed a commit to codeaurora-unofficial/platform-development that referenced this issue Sep 17, 2016
Add timegm and timelocal.

Test: run_tests.py --filter timegm
Bug: android/ndk#130
Change-Id: Icc8fa6ca1616bc0b6dd79519daa2a6a4316fab9c
BoredOutOfMyGit pushed a commit to codeaurora-unofficial/platform-development that referenced this issue Sep 17, 2016
Add timegm and timelocal.

Test: run_tests.py --filter timegm
Bug: android/ndk#130
Change-Id: Icc8fa6ca1616bc0b6dd79519daa2a6a4316fab9c
miodragdinic pushed a commit to MIPS/ndk that referenced this issue Apr 17, 2018
Test: ./checkbuild.py
Bug: android/ndk#130
Change-Id: I5be3410e1d1e69dd7192383520de11579f0dcb6a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants