8000 Fix cross-compiling for android with the NDK by turistu · Pull Request #252 · strace/strace · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix cross-compiling for android with the NDK #252

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

turistu
Copy link
@turistu turistu commented May 8, 2023

The only thing not quite obvious is the patch to configure.ac:

before looking for whatever armv7a compiler the user may have in her path (as the current "heuristics" does), look for a analogously named compiler in the same path as the aarch64 one.

Comment on lines -899 to +917
static_assert((NUM_HEXSTR_OPTS - 1) <= (QUOTE_HEXSTR_MASK >> QUOTE_HEXSTR_SHIFT),
_Static_assert((NUM_HEXSTR_OPTS - 1) <= (QUOTE_HEXSTR_MASK >> QUOTE_HEXSTR_SHIFT),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change is needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the build will fail without it?

The android headers only define static_assert when in c11 mode, thence:

        ./mpers.sh m32 "-std=gnu99 " $f || exit; \
done
In file included from mpers-m32/struct_blk_user_trace_setup.c:10:
./defs.h:899:32: error: expected ')'
static_assert((NUM_HEXSTR_OPTS - 1) <= (QUOTE_HEXSTR_MASK >> QUOTE_HEXST...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have static_assert.h (included by defs.h) to handle this on various platforms.
Please have a look why it didn't work out in your case.

Comment on lines 18 to +19
/* The following function might be unused, hence the inline qualifier. */
static inline void
static inline void __attribute__((unused))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this change is not needed, the compiler shouldn't issue any warnings for static inline functions.
On the contrary, the compiler will issue a warning if a function marked as unused is actually used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your supposition is false:

 echo 'static inline void foo(){}' | clang -Wall -Werror -c -xc -
<stdin>:1:20: error: unused function 'foo'
      [-Werror,-Wunused-function]
static inline void foo(){}
                   ^
1 error generated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then this is a compiler bug, a lot of software relies on this static inline thing, please report it to compiler people instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to gcc documentation,

-Wunused-function

    Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall.

Sorry, I'm not going to workaround incorrect warnings reported by non-compliant compilers.

@turistu
Copy link
Author
turistu commented May 9, 2023 via email

@turistu
Copy link
Author
turistu commented May 9, 2023 via email

@esyr
Copy link
Member
esyr commented May 9, 2023

when called with the -mx32 option, the ndk's clang cross compiler driver ends up running the system's gcc

This sounds like a clang bug.

# First try $CC with 'aarch64' replaced with 'arm' and 'android'
# replaced with 'androideabi'
cc=${CC%/aarch64-*}/armv7a-${CC##*/aarch64-}
cc=${cc%-android*}-androideabi${cc##*-android}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why exactly should it take priority over all the other options? Also, since the CC differs from the one that ./configure would detect, I guess it is provided explicitly, why not provide CC_FOR_M32 explicitly as well?

# First try $CC with 'aarch64' replaced with 'arm' and 'android'
# replaced with 'androideabi'
cc=${CC%/aarch64-*}/armv7a-${CC##*/aarch64-}
cc=${cc%-android*}-androideabi${cc##*-android}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see androideabi is not present among the currently checked ABI options, would simply adding it to triplet3 set help?

@turistu
Copy link
Author
turistu commented May 9, 2023 via email

@turistu
Copy link
Author
turistu commented May 9, 2023 via email

@ldv-alt
Copy link
Member
ldv-alt commented May 9, 2023 via email

@esyr
Copy link
Member
esyr commented May 9, 2023

Why exactly should it take priority over all the other options?

Because it's the only one that makes sense anyway. Picking up whatever arm cross compiler comes first in PATH does not make any sense whatsoever.

It makes sense in the most common case of an isolated build environment, as there's normally only one cross-compiler installed for the specific ABI, the one is that is needed for the build.

I see value of having a heuristic for setting the CC_FOR_M32 cross-compiler based on CC cross-compiler, but it probably ought to be expressed differently, likely as an additional first values in the triple* sets.

Also, since the CC differs from the one that ./configure would detect, I guess it is provided explicitly, why not provide CC_FOR_M32 explicitly as well?

Because that does not work, AC_CHECK_PROGS does not accept absolute paths.

I'm not exactly sure how this is related to the variables passed to ./configure, since the it just picks up whatever is provided verbatim (as generated by, well, by AC_CHECK_PROGS macro's shell code).

@turistu
Copy link
Author
turistu commented May 9, 2023 via email

@codecov
Copy link
codecov bot commented May 9, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.16%. Comparing base (c3ae2b2) to head (46a4113).

Current head 46a4113 differs from pull request most recent head 58e1836

Please upload reports for the commit 58e1836 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #252      +/-   ##
==========================================
+ Coverage   87.89%   90.16%   +2.27%     
==========================================
  Files         286      290       +4     
  Lines       24895    25031     +136     
  Branches     3624        0    -3624     
==========================================
+ Hits        21881    22569     +688     
- Misses       2049     2462     +413     
+ Partials      965        0     -965     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ldv-alt ldv-alt added the wontfix label Sep 3, 2023
@turistu turistu force-pushed the for-upstream branch 2 times, most recently from 15622ec to e847aa4 Compare October 27, 2024 19:06
@turistu turistu force-pushed the for-upstream branch 3 times, most recently from 2c28f3a to 09c9f2d Compare November 4, 2024 16:21
@turistu turistu force-pushed the for-upstream branch 4 times, most recently from ba1226c to efeb7b4 Compare November 19, 2024 13:45
@turistu turistu force-pushed the for-upstream branch 3 times, most recently from bed4534 to 503f099 Compare December 2, 2024 13:46
@turistu turistu force-pushed the for-upstream branch 2 times, most recently from a711a20 to b2bbeae Compare December 5, 2024 13:46
@turistu turistu force-pushed the for-upstream branch 3 times, most recently from 76ef3a7 to 2c6846c Compare January 23, 2025 13:40
@turistu turistu force-pushed the for-upstream branch 2 times, most recently from af547d7 to 0a8a582 Compare March 17, 2025 13:45
@turistu turistu force-pushed the for-upstream branch 2 times, most recently from 9bab8fe to 9ba681b Compare March 25, 2025 13:45
@turistu turistu force-pushed the for-upstream branch 2 times, most recently from f1739c2 to 1004a13 Compare May 21, 2025 13:49
turistu added 6 commits May 26, 2025 13:48
…in/aarch64-linux-android21-clang ./configure ..

when determining the compiler for -m32 on aarch64, first look for one
similarly named with s/aarch64/armv7a/ and s/android/&eabi/
…in/aarch64-linux-android21-clang ./configure ..

header include hell
…in/aarch64-linux-android21-clang ./configure ..

fix the errors triggered by -Wundef and -Wunused- with -Werror
keep only m32

when called with the -mx32 option, the ndk's clang cross compiler
driver ends up running the system's gcc

YUCK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0