This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: error: implicit declaration of function 'sendfile' is invalid in C99
Type: Stage: resolved
Components: Cross-Build Versions: Python 3.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Alex.Willmer, christian.heimes, methane, muhzi, xdegaye, yan12125
Priority: normal Keywords:

Created on 2019-03-01 22:00 by muhzi, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pyconfig.h muhzi, 2019-03-01 22:00
Messages (9)
msg336958 - (view) Author: (muhzi) Date: 2019-03-01 22:00
I encountered yet another issue with cross compilation on android, it so happens that these errors occur only when I cross compile for non 64-bit archs. i.e. I could cross compile just fine for arm64 & x86_64 but the 32-bit version of these archs produces the following error during compilation:

./Modules/posixmodule.c:8457:19: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            ret = sendfile(out, in, NULL, count);
                  ^
./Modules/posixmodule.c:8457:19: warning: this function declaration is not a prototype [-Wstrict-prototypes]
./Modules/posixmodule.c:8470:15: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        ret = sendfile(out, in, &offset, count);
              ^
./Modules/posixmodule.c:9057:14: error: implicit declaration of function 'truncate' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    result = truncate(path->narrow, length);
             ^
./Modules/posixmodule.c:9057:14: note: did you mean 'ftruncate'?
/home/muhzi/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/unistd.h:220:5: note: 'ftruncate' declared here
int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12);
    ^
./Modules/posixmodule.c:9057:14: warning: this function declaration is not a prototype [-Wstrict-prototypes]
    result = truncate(path->narrow, length);


I attached pyconfig.h for reference, it seems that the configuration step went fine. I checked that these missing functions are able to have their corresponding headers included. Also figured after misplacing some include lines in posixmodule.c that when the preprocessor includes Python.h it fails to include definitions from successively included headers.
msg336959 - (view) Author: (muhzi) Date: 2019-03-01 22:08
Using the latest NDK r19. Here is my compilation steps for arm:

export PATH="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
export CC="armv7a-linux-androideabi16-clang"
export CXX="$CC++"

export AR="arm-linux-androideabi-ar"
export LD="arm-linux-androideabi-ld"
export AS="arm-linux-androideabi-as"
export STRIP="arm-linux-androideabi-strip"
export RANLIB="arm-linux-androideabi-ranlib"
export READELF="arm-linux-androideabi-readelf"

export CFLAGS=""
export CXXFLAGS=$CFLAGS
export LDFLAGS="-pie"

export CONFIG_SITE="config.site"

./configure --host=armv7a-linux-androideabi --build=x86_64-linux-gnu --disable-ipv6
make
make altinstall DESTDIR=$INSTALL_DIR
msg336976 - (view) Author: (muhzi) Date: 2019-03-02 00:30
After some testing, it works and builds extensions OK for android arm with API>=21. fails on lower API versions (e.g. 16).
msg337001 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2019-03-02 11:36
The presence of sendfile and truncate is detected by configure. Your copy of configure defines HAVE_SENDFILE and HAVE_SYS_SENDFILE_H. Please check config.log and see why configure detects the functions.
msg337003 - (view) Author: (muhzi) Date: 2019-03-02 11:55
Yes it is detected by configure because they exist.

From config.log:

configure:11514: checking for truncate
configure:11514: armv7a-linux-androideabi21-clang -o conftest   -pie -march=armv7-a -Wl,--fix-cortex-a8 conftest.c -ldl  >&5
configure:11514: $? = 0
configure:11514: result: yes


I can include the corresponding headers in a separate test file and call these missing methods and I get no compilation errors. But it seems they don't work in posixmodule.c and for some reason when #include <sys/sendfile.h> is put before #include "Python.h", the compiler doesn't give errors for those particular functions. I'm guessing this is an API level < 21 issue, it might have propagated from the configuration step (if any faults) but not sure. I use the same steps to compile this for API level 21 with no errors.
msg337004 - (view) Author: (muhzi) Date: 2019-03-02 12:07
err, wrong logs sorry... 

configure:11514: checking for truncate
configure:11514: armv7a-linux-androideabi16-clang -o conftest   -pie -march=armv7-a -Wl,--fix-cortex-a8 conftest.c -ldl  >&5
configure:11514: $? = 0
configure:11514: result: yes


configure:7954: checking sys/sendfile.h usability
configure:7954: armv7a-linux-androideabi16-clang -c   conftest.c >&5
configure:7954: $? = 0
configure:7954: result: yes
configure:7954: checking sys/sendfile.h presence
configure:7954: armv7a-linux-androideabi16-clang -E  conftest.c
configure:7954: $? = 0
configure:7954: result: yes
configure:7954: checking for sys/sendfile.h
configure:7954: result: yes
msg337013 - (view) Author: (yan12125) * Date: 2019-03-02 15:58
CPython requires several changes to build for Android < 21. There was an attempt in issue32654 but it's abandoned.
msg337278 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2019-03-06 05:04
May I close this issue?  I feel target SDK v21 is too old.

https://android-developers.googleblog.com/2017/12/improving-app-security-and-performance.html
msg337283 - (view) Author: (muhzi) Date: 2019-03-06 08:48
Yeah, makes sense
History
Date User Action Args
2022-04-11 14:59:11adminsetgithub: 80343
2019-03-06 10:13:13methanesetstatus: open -> closed
resolution: wont fix
stage: resolved
2019-03-06 08:48:44muhzisetmessages: + msg337283
2019-03-06 05:04:52methanesetnosy: + methane
messages: + msg337278
2019-03-02 15:58:41yan12125setnosy: + yan12125
messages: + msg337013
2019-03-02 12:07:17muhzisetmessages: + msg337004
2019-03-02 11:55:55muhzisetmessages: + msg337003
2019-03-02 11:36:41christian.heimessetnosy: + christian.heimes
messages: + msg337001
2019-03-02 00:30:59muhzisetmessages: + msg336976
2019-03-01 22:08:13muhzisetmessages: + msg336959
2019-03-01 22:00:18muhzicreate