LoginSignup
1
2

More than 3 years have passed since last update.

Android NDK r21 C++ コンパイルオプションのメモ

Posted at

背景

  • Gradle 経由で CMake で C++ ビルドしている.

arm64-v8a ターゲット + デフォルトのビルドタイプ(debug?) + libc++_shared で .so ビルドでは以下の構成になりました.

/home/syoyo/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android28 --gcc-toolchain=/home/syoyo/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/syoyo/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot  -Dnative_submodule_EXPORTS  -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security   -fPIC -MD -MT CMakeFiles/native_submodule.dir/home/syoyo/work/flutter_native_vulkan_experiment/ios/Classes/native_submodule.cpp.o -MF CMakeFiles/native_submodule.dir/home/syoyo/work/flutter_native_vulkan_experiment/ios/Classes/native_submodule.cpp.o.d -o CMakeFiles/native_submodule.dir/home/syoyo/work/flutter_native_vulkan_experiment/ios/Classes/native_submodule.cpp.o -c /home/syoyo/work/flutter_native_vulkan_experiment/ios/Classes/native_submodule.cpp

参考情報

オプション

気になるオプションをリストアップしてみます.

-fdata-sections, -ffunction-sections

コンパイル単位(.o)ごとに data section, function sections を作るっぽい

Query on -ffunction-section & -fdata-sections options of gcc
https://stackoverflow.com/questions/4274804/query-on-ffunction-section-fdata-sections-options-of-gcc

ANDROID_FUNCTION_LEVEL_LINKING cmake option で制御できる.

-fnunwind-tables

stack trace 用っぽい

-fstack-protector-strong

gcc 4.9 から. スタックのチェックをより強く行う?

-no-canonical-prefixes

ヘッダのファイル探索パス用など.
シンボリックリンクを展開しない, ファイルパスを絶対パスにする.

-fno-addrsig

clang 限定.

By default, Clang emits an address-significance table into every ELF object file when using the integrated assemble

リンカ周りで安全に処理する仕組みっぽい.

その他一般

android.toolchain.cmake にいくつか記述があります.

以前は ANDROID_DISABLE_RELRO とかありましたが, r20 or r21 からなくなっていますね.

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2