This is an archive of the discontinued LLVM Phabricator instance.

[AIX][compiler-rt] Build and install standalone libatomic
ClosedPublic

Authored by lkail on May 10 2021, 1:40 AM.

Details

Summary

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.

Diff Detail

Event Timeline

lkail created this revision.May 10 2021, 1:40 AM
lkail requested review of this revision.May 10 2021, 1:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2021, 1:40 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
lkail retitled this revision from [AIX] Build and install libatomic.a to [AIX][compiler-rt] Build and install libatomic.a .May 10 2021, 1:40 AM
lkail added a reviewer: samsonov.
lkail retitled this revision from [AIX][compiler-rt] Build and install libatomic.a to [AIX][compiler-rt] Add cmake module to build libatomic.a.May 10 2021, 2:02 AM
jsji added a comment.May 10 2021, 9:08 AM

Thanks @lkail ! In general, I think we can try to make the Modules platform dependent.

compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
4

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.

48

Same, remove _aix_ here, also pass down compile_flag and link flag.

61

Why this has to be OFF? Isn't SHARED needs PIC? Also AIX defaults to PIC.

62

Can we pass the flag into this functions instead of hardcoding them here.

63

Same as above, these flags should be passed down from CMakeLists.txt , not hardcoding them here.

75

Remove _aix_, also add options to control building 32 bit only, 64 bit only, or both.

81

Can we make this another function like generate_export_list?

100

ar flags should be passed down, or can have default, and can be overwritten by args.

compiler-rt/lib/builtins/CMakeLists.txt
757

Set the compile flags, linker flags, ar flags here.

daltenty added inline comments.May 10 2021, 9:56 AM
compiler-rt/lib/builtins/CMakeLists.txt
755

Maybe a more generic CMake option (e.g. COMPILER_RT_BUILD_LIBATOMIC) with an appropriate default for AIX would be better here?

lkail updated this revision to Diff 344339.May 11 2021, 3:11 AM
lkail retitled this revision from [AIX][compiler-rt] Add cmake module to build libatomic.a to [AIX][compiler-rt] Add scripts and cache file for building libatomic.
lkail edited the summary of this revision. (Show Details)

Address comments by following method introduced by @daltenty in https://reviews.llvm.org/D101959. Now compiling shared atomic library is platform independent.

lkail marked 2 inline comments as done.May 11 2021, 3:24 AM
lkail updated this revision to Diff 344344.May 11 2021, 3:26 AM
jsji added a comment.May 11 2021, 7:17 AM

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?

What do you think?

Yes, invoking cmake twice does introduce more complexity.

lkail updated this revision to Diff 344705.May 12 2021, 12:54 AM
lkail retitled this revision from [AIX][compiler-rt] Add scripts and cache file for building libatomic to [AIX][compiler-rt] Build and install standalone libatomic.
lkail edited the summary of this revision. (Show Details)

Try to implement all in cmake.

lkail marked 2 inline comments as done.May 12 2021, 12:59 AM
lkail added inline comments.
compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
4

I assume only AIX's binder need these exported symbols, so I make them AIX specific.

62

I leave these flags as default options, we can use -DAIX_LIBATOMIC_LINK_FLAGS to change.

lkail edited the summary of this revision. (Show Details)May 12 2021, 1:17 AM
lkail edited the summary of this revision. (Show Details)
lkail updated this revision to Diff 344794.May 12 2021, 6:01 AM
lkail updated this revision to Diff 344798.May 12 2021, 6:15 AM
daltenty added inline comments.May 12 2021, 8:40 AM
compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
55

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)

jsji added a comment.May 12 2021, 8:48 AM

Looks mostly good to me as long as you address David's comments.

compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
55

Yes, agree.

compiler-rt/lib/builtins/CMakeLists.txt
769

This should be platform independent? So that people can override libatomic link flags to be different than builtin link flags.

daltenty added inline comments.May 12 2021, 10:38 AM
compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
63

nit: don't some of these duplicate the driver default link flags for building a shared library?

lkail added inline comments.May 12 2021, 8:01 PM
compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
63

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.

lkail updated this revision to Diff 345023.May 12 2021, 8:44 PM
  • Introduce COMPILER_RT_LIBATOMIC_LINK_FLAGS
  • New file atomic.exp under compiler-rt/lib/builtins
  • Minor tweak of dependencies
lkail updated this revision to Diff 345025.May 12 2021, 8:44 PM
lkail marked an inline comment as done.
lkail marked 2 inline comments as done.May 12 2021, 8:46 PM
jsji accepted this revision as: jsji.May 12 2021, 9:14 PM

LGTM. Thanks. Please wait one or two days in case there are other feedback.

compiler-rt/lib/builtins/CMakeLists.txt
764

Maybe put atomic.exp into ppc subdir would be better.

This revision is now accepted and ready to land.May 12 2021, 9:14 PM
lkail updated this revision to Diff 345047.May 12 2021, 10:13 PM
lkail marked an inline comment as done.May 12 2021, 10:14 PM
lkail updated this revision to Diff 345048.May 12 2021, 10:21 PM
  • Put atomic.exp in ppc folder
  • Move set(BUILTIN_DEPS builtins) under AIX check
This revision was automatically updated to reflect the committed changes.