Android, llvm-ar and setLastModificationAndAccessTime

Hi,

I’ve been trying to get LLVM working as a JIT compiler on Android for a while. It works now, except that the setLastModificationAndAccessTime function won’t build because the Bionic C library lacks both futimes and futimens. There doesn’t appear to be any “nice” workaround for this problem: the only ways I can think of to make setLastModificationAndAccessTime work are either to go by /proc/self/fd or invoke the system call directly (the second option isn’t helped by the fact that the Android headers don’t define the relevant system call number and it varies between platforms).

Right now the only part of LLVM that uses this function is llvm-ar, so it’s not as if lack of support for this function is a serious shortcoming. I don’t really know the history of PathV1/PathV2 but I think the simplest solutions are:

  1. Have setLastModificationAndAccessTime fail on platforms without futimes/futimens (by ENOSYS). This is pretty ugly because having a function which can never succeed seems likely to confuse users.
  2. Only declare setLastModificationAndAccessTime if it is actually available (add something to llvm-config.h to indicate this). The downside here is that (in theory at least) users need to know that setLastModificationAndAccessTime might be missing, although in practise they can probably ignore the issue.

(1) is trivial to implement and is what I’m doing now; I can also create a patch to do (2), I just thought I’d ask for opinions first.

Regards,

James

futimens() is available in Android KitKat. We work extensively with LLVM and this allowed us to remove our ugly workaround for not having this functionality.

Steve

futimens() is available in Android KitKat. We work extensively with LLVM and this allowed us to remove our ugly workaround for not having this functionality.

Hi Steve,

Is your work on a branch somewhere?

James is putting a lot of time into this, and the LLVM community has been making best efforts to help review his patches which can be difficult for those who don't normally work with the Android platform.

So if the work is already out there, that'd be useful to know in order to avoid duplication of effort. There are lots of other useful things we could be doing if support for that platform is already complete somewhere on Github :slight_smile:

Cheers,
Alp.

futimens() is available in Android KitKat. We work extensively with LLVM
and this allowed us to remove our ugly workaround for not having this
functionality.

Hi Steve,

Is your work on a branch somewhere?

It is all available as part of the Android Open Source Project (AOSP). I
should mention that we do not use the JIT path, but LLVM does require
futimens() to build properly for Android (hence us fixing this missing part
of bionic). If you want to look at local patches that we have for
LLVM/Clang, those are available in "external/llvm" and "external/clang". We
have very few differences from upstream LLVM.

James is putting a lot of time into this, and the LLVM community has been
making best efforts to help review his patches which can be difficult for
those who don't normally work with the Android platform.

So if the work is already out there, that'd be useful to know in order to
avoid duplication of effort. There are lots of other useful things we could
be doing if support for that platform is already complete somewhere on
Github :slight_smile:

http://source.android.com has instructions for how to pull down AOSP. We
don't use github.

Steve

Hmmm.... following up on your point I've noticed something strange. futimens is missing from the NDK (r9b; it's not in any headers and the libc.so files are the same all the way back to android-9), which is why I thought it's missing from Android generally. The NDK is by far the easiest way to cross-compile since it provides a standalone cross-compilation toolchain. It is however present in

https://android.googlesource.com/platform/prebuilts/ndk/+/master/9/platforms/android-19/arch-arm/usr/include/sys/stat.h

which seems odd to me. Steve, perhaps you know whether this is intentional? My googling isn't getting me anywhere on why the file I've linked is different to platforms/android-19/arch-arm/usr/include/sys/stat.h in the NDK.

James

This is only available for apps that target API level 19 and up. On 18 and lower, the futimens() function won’t be available via libc.so. You will need to target API 19 (KitKat) in order to actually use it. If I do an “nm -D prebuilts/ndk/9/platforms/android-19/arch-arm/usr/lib/libc.so”, I can see futimens() is present. On the others, it is definitely missing.

Steve

I think this is an NDK bug then. I just re-downloaded it to check, and indeed in the NDK from http://developer.android.com/tools/sdk/ndk/index.html that's not true, platforms/android-19/arch-arm/usr/lib/libc.so and platforms/android-9/arch-arm/usr/lib/libc.so are identical.

James

Have setLastModificationAndAccessTime fail on platforms without
futimes/futimens (by ENOSYS). This is pretty ugly because having a function
which can never succeed seems likely to confuse users.

This is probably OK. This is just for use in llvm-ar, so it doesn't
have to be fully general. In fact, moving this function to llvm-ar
itself is probably OK too.

Cheers,
Rafael