Android NDK, clang, and ODR violations

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Android NDK, clang, and ODR violations

Christopher Broadbent
I'm in the progress of updating some code to clang in the NDK (since
they are not longer supporting GCC), and getting some ODR errors which
seem to be caused by a bad link configuration.

The generated executables / shared libraries seem to link to both the
selected standard library, and libstdc++.so (android's minimal 'system'
standard lib, not gcc's c++ standard lib). This causes multiple
definitions of new/delete, triggering ODR warnings between 'libc++abi.a'
and 'libstdc++.so'

When using the gnustl_static, there's similar issues on the members of
'std::type_info', 'std::basic_string', and 'std::shared_ptr', but this
is now between our code and 'libgnustl_static.a' (possibly a clang vs
gcc code gen difference?)

This happens in cmake 3.7.2 and cmake 3.8

Is anyone successfully using cmake + clang on android, or have an idea
of where the configuration script might be wrong?

Here is my reproduction:

--- toolchain.cmake
set(CMAKE_SYSTEM_NAME       Android)
set(CMAKE_SYSTEM_VERSION    19)
set(CMAKE_ANDROID_ARCH_ABI  armeabi-v7a)
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang)
set(CMAKE_ANDROID_STL_TYPE  c++_static)
--- CMakeLists.txt
cmake_minimum_required(VERSION 3.7.2)
cmake_policy(VERSION 3.7.2)

project(reproduction)

string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,--detect-odr-violations")

add_executable(main main.cpp)
--- main.cpp
#include <iostream>
int main() {
   std::cout << "hello, world!\n";
}
---

Thanks,


Chris
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Android NDK, clang, and ODR violations

Christopher Broadbent
On 28/07/2017 02:28, Dan Albert wrote:

> (in case threading doesn't work since I'm not a list member and can't
> reply to the original message:
> https://cmake.org/pipermail/cmake/2017-July/065886.html)
>
> I'm pretty sure -Wl,--detect-odr-violations is just giving you false
> positives. Note that the warning message says "/possible/ ODR
> violation". We tried using this flag in the Android platform recently
> and found lots of false positives too.
>
> Those symbols are weak in libc++abi, so this is not an ODR violation
> (they're not weak in libstdc++.so, and that's a bug, but not a harmful
> one; I'm fixing it right now either way).
>
> FWIW, CMake shouldn't be linking libstdc++.so /and/ libc++_static.a in
> the same link either way, but this is actually something that both
> upstream CMake, the NDK's CMake toolchain file, and ndk-build all get
> wrong. It's something that we should resolve eventually, but it doesn't
> actually cause any problems so it hasn't been prioritized. Could argue
> that it has caused this problem, but this would still be firing on false
> positives if you'd added your own new/delete replacements, and this
> warning is still pretty much guaranteed to fire for libc++ because
> libandroid_support will do exactly the same thing and try to replace a
> bunch of things in libc.

Thanks, I'll move ahead with the switch, and look in to filtering out
the warnings on these symbols, rather than disabling the ODR checks
entirely.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Loading...