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

Doesn't compile with -Werror on clang due to implicit addition of -Wa,noexecstack #171

Closed
vlovich opened this issue Jul 26, 2016 · 16 comments
Assignees
Milestone

Comments

@vlovich
Copy link

vlovich commented Jul 26, 2016

It looks like clang doesn't understand this argument so supplying Werror causes the build to break.
An example of this is libquic which fails to build because the project itself adds Werror (& -Wa,noexecstack) which results in an "argument unused during compilation" warning.

When the clang toolchain is used, then the correct set of arguments should be configured to be used instead.

@DanAlbert
Copy link
Member

Works for me, though the argument is spelled -Wa,--noexecstack (note the --).

Assuming that wasn't your issue, are you using ndk-build or something else? Sounds like maybe -Wa,--noexecstack is being passed at link time as well, in which case the warning is valid.

@NikolaVeljkovic-Img
Copy link

NikolaVeljkovic-Img commented Aug 2, 2016

Not sure if @vlovich got to the error in the same way, but I got it by trying to build audio-echo NDK sample with cmake. This is with today's NDK build.

git clone https://github.com/googlesamples/android-ndk.git
cd android-ndk/
git checkout master-cmake
mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake \
       -DANDROID_NDK=$NDK_ROOT            \
       -DCMAKE_BUILD_TYPE=Release         \
       -DANDROID_ABI="arm64-v8a"          \
       ../audio-echo/app/src/main/cpp/

@DanAlbert DanAlbert added this to the r13 milestone Aug 9, 2016
@DanAlbert
Copy link
Member

dumganhar pushed a commit to android-source/platform_tools_cmake-utils that referenced this issue Dec 21, 2016
CMake automatically forwards all compiler flags to the linker,
and clang doesn't like having -Wa flags being used for linking.

To prevent CMake from doing this would require meddling with the
CMAKE_<LANG>_COMPILE_OBJECT rules, which would get quite messy.

Bug: android/ndk#171
Change-Id: I3295948db64d3459db3af7ba3f0d431689812f80
(cherry picked from commit 78eb716552a0b43c2fc36bebf8ad991e6c77dca9)
miodragdinic pushed a commit to MIPS/ndk that referenced this issue Jan 12, 2017
CMake automatically forwards all compiler flags to the linker,
and clang doesn't like having -Wa flags being used for linking.

To prevent CMake from doing this would require meddling with the
CMAKE_<LANG>_COMPILE_OBJECT rules, which would get quite messy.

Bug: android/ndk#171
Change-Id: I3295948db64d3459db3af7ba3f0d431689812f80
@minggo
Copy link

minggo commented Nov 30, 2017

I uses NDK r16 with standalone toolchain, i pass -Wa,--noexecstack to clang, also trigger the warning message:

clang50: warning: argument unused during compilation: '-Wa,--noexecstack' [-Wunused-command-line-argument]

Then i change to use -Wl,-z,noexecstack, but also has warning message:

clang50: warning: -Wl,-z,noexecstack: 'linker' input unused [-Wunused-command-line-argument]

So is there any side effect of the warning message? Can i just remove -Wa,--noexecstack?
Thanks

@DanAlbert
Copy link
Member

Are you passing that while compiling or while linking?

@minggo
Copy link

minggo commented Nov 30, 2017

I use cmake, and pass it to CFLAGS, then use cmake and make to build target. So i think it is used in compiling.

@DanAlbert
Copy link
Member

Wait, are you using a standalone toolchain or are you using cmake? You've said both.

@minggo
Copy link

minggo commented Nov 30, 2017

Mixing standalone toolchain and cmake, is there any problem? Standalone toolchain just used to assign CC, CXX and so on.

@DanAlbert
Copy link
Member

If you're not using our cmake toolchain file then you don't have the fix for this. See the commit message for the change up the thread for an explanation of why this happens with CMake.

There's no reason to use a standalone toolchain with CMake. The whole point of standalone toolchains is to interface with build systems we don't natively support. Just use our cmake toolchain file.

@minggo
Copy link

minggo commented Nov 30, 2017

Just use our cmake toolchain file.

Could you show me how to? Now what i do is:

  • build standalone toolchain with NDK
  • export CC, CXX and so on
  • passing CFLAGS and CXXFLAGS to cmake
  • then invoke make

Currently everything works fine. I just use the building system to build 3rd party libraries used in game engine.

If you're not using our cmake toolchain file then you don't have the fix for this

But i has the same warning messages. Is it any problem?

@minggo
Copy link

minggo commented Nov 30, 2017

3rd party libraries, such as png, doesn't use NDK cmake toolchain, but almost all uses configure, cmake and make to build.

@rcdailey
Copy link

I wanted to bump this issue for @DanAlbert. I'm seeing this error with ccache + linux + NDK r17 + clang. I'm using the toolchain as follows:

cmake "$root_path" -G"Ninja" \
    -DCMAKE_BUILD_TYPE="Release" \
    -DANDROID_PLATFORM=android-15 \
    -DANDROID_ABI=armeabi-v7a \
    -DANDROID_STL=c++_shared \
    -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
    -DBUILD_TESTING=OFF

Here is the command that ccache tries to run (It runs this in 'direct mode' to try to determine if the object file is cached and available):

/usr/local/bin/android-ndk-r17b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi --gcc-toolchain=/usr/local/bin/android-ndk-r17b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/usr/local/bin/android-ndk-r17b/sysroot -g -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -Os -fPIC -Wno-inconsistent-missing-override -Werror -std=c++14 -DANDROID -DBETTER_ENUMS_STRICT_CONVERSION -DBOOST_ALL_NO_LIB -DBOOST_BIND_NO_PLACEHOLDERS -DBOOST_FILESYSTEM_NO_DEPRECATED -DBOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX -DCEREAL_RAPIDJSON_NAMESPACE=cereal_rapidjson -DZIOSK_ENABLE_DEVELOPER_LOGS -DZIOSK_ENABLE_ZPAY_DIAGNOSTICS -DZIOSK_MODULE_NAME="zApp" -DzApp_EXPORTS -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/zApp/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Core/UI/Source -ICore/UI/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/PowerVR/sdk/Include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/PowerVR/tools/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/PowerVR/tools/include/OGLES2 -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/boost/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/openssl/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/sqlite/. -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/cereal/cereal/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/cereal/cereal_optional_nvp/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/rapidxml/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/better-enums/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/libpng/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/duktape/src -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/uri/source/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/fmt/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/stb_image/include -I/home/TABLETOPMEDIA/robert/frontend/source/Core/MsrInterface/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/bsp/msr/include -I/usr/local/bin/android-ndk-r17b/sources/android/cpufeatures -I/usr/local/bin/android-ndk-r17b/sources/android/native_app_glue -I/home/TABLETOPMEDIA/robert/frontend/source/Core/Barcode/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/zxing/include -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/DynamicUI/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Core/WebServices/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/OrderEntry/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Services/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/zPayService/Interface/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Core/ThirdParty/bsp/zpaylib/include -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/zPayService/ZPayUtilities/ZPayUtilities/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/PATT/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/Loyalty/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/MSRServiceInterface/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/Survey/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/EmailClub/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/SettingsManager/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/MessagingModule/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/ETM/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Applications/GoogleGiftCard/Source -I/home/TABLETOPMEDIA/robert/frontend/source/Core/AdPlatform/Source -isystem /usr/local/bin/android-ndk-r17b/sources/cxx-stl/llvm-libc++/include -isystem /usr/local/bin/android-ndk-r17b/sources/android/support/include -isystem /usr/local/bin/android-ndk-r17b/sources/cxx-stl/llvm-libc++abi/include -isystem /usr/local/bin/android-ndk-r17b/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=15 -DANDROID -DNDEBUG -MD -MT Applications/zApp/CMakeFiles/zApp.dir/Source/ZioskApp.cpp.o -MF Applications/zApp/CMakeFiles/zApp.dir/Source/ZioskApp.cpp.o.d -E /home/TABLETOPMEDIA/robert/frontend/source/Applications/zApp/Source/ZioskApp.cpp

I get error:

clang++: error: argument unused during compilation: '-Wa,--noexecstack' [-Werror,-Wunused-command-line-argument]

By removing the -Wa,--noexecstack option via the following CMake code, ccache is working correctly now. Although I have not tried to execute the shared library on an actual ARM device. I'm worried that arbitrarily removing this compiler flag might have repercussions. I'm not sure what this flag to clang does. Can you explain? Is it safe to remove? Why is it failing in the first place?

string( REPLACE "-Wa,--noexecstack" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )

@pirama-arumuga-nainar
Copy link
Collaborator

@rcdailey -Wunused-command-line-argument is expected when using clang with ccache. It's safe to ignore and silence.

@rcdailey
Copy link

@pirama-arumuga-nainar So basically I have to do:

string( APPEND CMAKE_CXX_FLAGS " -Qunused-arguments" )
string( APPEND CMAKE_C_FLAGS " -Qunused-arguments" )

I'll give it a shot.

@jeduden
Copy link

jeduden commented Feb 27, 2019

@rcdailey -Wunused-command-line-argument is expected when using clang with ccache. It's safe to ignore and silence.

@rcdailey could you explain why the flag is there in the first place ? if it is not used ?
Thank you in advance !

@pirama-arumuga-nainar
Copy link
Collaborator

@jeduden See the link in the comment:

The reason for this is that ccache splits the compilation into separate calls to the preprocessor and the compiler proper..

Since --Wa,--noexecstack is not used during the preprocessor step (because assembler is not invoked), Clang reports that argument as unused. The alternatives are to either stop using ccache or silence the -Wunused-command-line-argument warning.

samuel40791765 added a commit to aws/aws-lc that referenced this issue Nov 11, 2021
### Issues:
Resolves #192

### Description of changes: 
* Clang with the Android NDK doesn't compile with `-Werror` on clang due to implicit addition of `-Wa,noexecstack`. Since `--Wa,--noexecstack` is not used during the preprocessor step (because assembler is not invoked), Clang reports that argument as unused. Added a removal the flag during FIPS builds for Android. 
Context: android/ndk#171

* CMAKE inserts a `\` before whitespaces in arguments, which Android line does not recognize when using
  `add_custom_command`. This caused `${CMAKE_ASM_COMPILER}` to fail during the preprocessing step. Replacing whitespaces with `;` fixes this. 
  Context: https://stackoverflow.com/questions/8925396/why-does-cmake-prefixes-spaces-with-backslashes-when-executing-a-command

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
DominicDams pushed a commit to DominicDams/aws-lc that referenced this issue Nov 30, 2021
### Issues:
Resolves aws#192

### Description of changes: 
* Clang with the Android NDK doesn't compile with `-Werror` on clang due to implicit addition of `-Wa,noexecstack`. Since `--Wa,--noexecstack` is not used during the preprocessor step (because assembler is not invoked), Clang reports that argument as unused. Added a removal the flag during FIPS builds for Android. 
Context: android/ndk#171

* CMAKE inserts a `\` before whitespaces in arguments, which Android line does not recognize when using
  `add_custom_command`. This caused `${CMAKE_ASM_COMPILER}` to fail during the preprocessing step. Replacing whitespaces with `;` fixes this. 
  Context: https://stackoverflow.com/questions/8925396/why-does-cmake-prefixes-spaces-with-backslashes-when-executing-a-command

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants