On AIX, we have to ship libatomic.a for compatibility. First, a new clang_rt.atomic is added. Second, use added cmake modules for AIX, we are able to build a compatible libatomic.a for AIX. The second step can't be perfectly implemented with cmake now since AIX's archive approach is kinda unique, i.e., archiving shared libraries into a static archive file.
Details
- Reviewers
jsji daltenty ldionne phosek xingxue cebowleratibm nemanjai howard.hinnant samsonov efriedma - Group Reviewers
Restricted Project - Commits
- rGd56729b4a439: [AIX][compiler-rt] Build and install standalone libatomic
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks @lkail ! In general, I think we can try to make the Modules platform dependent.
compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake | ||
---|---|---|
3 ↗ | (On Diff #344001) | Can we make *ALL* the code in this file platform independent? Although there are NO other users in other platform, we can make it reusable in case there are similar requests from other platform. So, please remove AIX_ prefix here. |
47 ↗ | (On Diff #344001) | Same, remove _aix_ here, also pass down compile_flag and link flag. |
60 ↗ | (On Diff #344001) | Why this has to be OFF? Isn't SHARED needs PIC? Also AIX defaults to PIC. |
61 ↗ | (On Diff #344001) | Can we pass the flag into this functions instead of hardcoding them here. |
62 ↗ | (On Diff #344001) | Same as above, these flags should be passed down from CMakeLists.txt , not hardcoding them here. |
74 ↗ | (On Diff #344001) | Remove _aix_, also add options to control building 32 bit only, 64 bit only, or both. |
80 ↗ | (On Diff #344001) | Can we make this another function like generate_export_list? |
99 ↗ | (On Diff #344001) | ar flags should be passed down, or can have default, and can be overwritten by args. |
compiler-rt/lib/builtins/CMakeLists.txt | ||
753 | Set the compile flags, linker flags, ar flags here. |
compiler-rt/lib/builtins/CMakeLists.txt | ||
---|---|---|
751 | Maybe a more generic CMake option (e.g. COMPILER_RT_BUILD_LIBATOMIC) with an appropriate default for AIX would be better here? |
Address comments by following method introduced by @daltenty in https://reviews.llvm.org/D101959. Now compiling shared atomic library is platform independent.
I like the part in compiler-rt/lib/builtins/CMakeLists.txt -- it is essentially the same principle of what we suggested yesterday -- make the code platform independent,
but I don't like the overall fact that we need to invoke compiler-rt/utils/aix-install-libatomic.sh as an additional step, and call cmake again...
I know CMake can NOT handle AIX archives well for now, I believe we can just implement that part using ar and add TODO to fix it once CMake support is ready.
What do you think?
compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake | ||
---|---|---|
54 ↗ | (On Diff #344798) | Why not just store this as an .exp file in the source tree if we are just going to write it out? (That would similar to what's in libcxx I believe) |
Looks mostly good to me as long as you address David's comments.
compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake | ||
---|---|---|
54 ↗ | (On Diff #344798) | Yes, agree. |
compiler-rt/lib/builtins/CMakeLists.txt | ||
765 | This should be platform independent? So that people can override libatomic link flags to be different than builtin link flags. |
compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake | ||
---|---|---|
62 ↗ | (On Diff #344798) | nit: don't some of these duplicate the driver default link flags for building a shared library? |
compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake | ||
---|---|---|
62 ↗ | (On Diff #344798) | I've checked generated build.ninja LANGUAGE_COMPILE_FLAGS = -O3 -DNDEBUG LINK_FLAGS = -Wl,-brtl -m64 -Wl,-H512 -Wl,-D0 -Wl,-T512 -Wl,-bhalt:4 -Wl,-bernotok -Wl,-bnoentry -Wl,-bexport:/home/lkail/llvm/dev/llvm-project/compiler-rt/lib/builtins/atomic.exp -Wl,-bmodtype:SRE -Wl,-lc LINK_LIBRARIES = -Wl,-blibpath:/usr/lib:/lib OBJECT_DIR = lib/builtins/CMakeFiles/clang_rt.atomic-dynamic-powerpc64.dir POST_BUILD = : PRE_LINK = : Looks no duplicated item in flags. |
- Introduce COMPILER_RT_LIBATOMIC_LINK_FLAGS
- New file atomic.exp under compiler-rt/lib/builtins
- Minor tweak of dependencies
LGTM. Thanks. Please wait one or two days in case there are other feedback.
compiler-rt/lib/builtins/CMakeLists.txt | ||
---|---|---|
760 | Maybe put atomic.exp into ppc subdir would be better. |
Maybe a more generic CMake option (e.g. COMPILER_RT_BUILD_LIBATOMIC) with an appropriate default for AIX would be better here?