This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Use interface library for libcxx-abi-shared
ClosedPublic

Authored by nikic on Sep 9 2022, 2:29 AM.

Details

Reviewers
ldionne
dim
Group Reviewers
Restricted Project
Commits
rG57c7bb3ec895: [libcxx] Use interface library for libcxx-abi-shared
Summary

The libc++.so linker script generation uses the IMPORTED_LIBNAME
target property on libcxx-abi-shared. However, libcxx-abi-shared
is not an interface library and as such cannot have an
IMPORTED_LIBNAME target property.

Convert libcxx-abi-shared into an imported interface library
and use IMPORTED_LIBNAME in place of IMPORTED_LOCATION. This makes
linker script generation work correctly with system-libcxxabi.

I believe this fixes the issue that D131037 was intended to fix.

Diff Detail

Event Timeline

nikic created this revision.Sep 9 2022, 2:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 2:29 AM
Herald added a subscriber: mgorny. · View Herald Transcript
nikic requested review of this revision.Sep 9 2022, 2:29 AM
ldionne added inline comments.Sep 9 2022, 5:47 AM
libcxx/cmake/Modules/HandleLibCXXABI.cmake
67–68

Instead, why don't we make this:

add_library(${target} ${kind} INTERFACE IMPORTED GLOBAL)
# current stuff
set_target_properties(${target} PROPERTIES IMPORTED_LIBNAME ${name})

And then we could keep using imported_library below? Or is setting IMPORTED_LOCATION not valid on an INTERFACE IMPORTED library?

nikic added a comment.Sep 9 2022, 6:16 AM

For the record, here is the reproducer:

cmake -G Ninja -S runtimes -B build-libcxx \
    -DLLVM_ENABLE_RUNTIMES="libcxx" \
    -DLIBCXX_CXX_ABI=system-libcxxabi \
    -DLIBCXX_CXX_ABI_INCLUDE_PATHS=/usr/include
ninja -Cbuild-libcxx

I think the linker script is currently corrupted for any value of LIBCXX_CXX_ABI other than libcxxabi.

libcxx/cmake/Modules/HandleLibCXXABI.cmake
67–68

From a quick test, setting IMPORTED_LOCATION on an interface library seems to be allowed, while setting IMPORTED_LIBNAME on a non-interface library is forbidden. However, I'm not sure why we would want to set IMPORTED_LOCATION, if we already set and use IMPORTED_LIBNAME.

ldionne added inline comments.Sep 9 2022, 6:21 AM
libcxx/cmake/Modules/HandleLibCXXABI.cmake
67–68

It's just that if we set both, we can use the same function to declare both our static and our shared library targets. The only thing I don't like with the patch as-is is that it introduces a second function that differs from the existing imported_library function only in a really subtle way. Someone adding a new choice of LIBCXX_CXX_ABI would have a hard time understanding why to use one over the other, I think.

Instead, I'd add

# Necessary for linker script generation
set_target_properties(${target} PROPERTIES IMPORTED_LIBNAME ${name})

to imported_library and use that for both our static and shared libraries below.

nikic updated this revision to Diff 460385.Sep 15 2022, 5:54 AM

Use import_static_library() and import_shared_library() functions for clearer semantics.

libcxx/cmake/Modules/HandleLibCXXABI.cmake
67–68

What do you think about this variant? The updated names should make it clear when to use each function, and allow us to drop some more code that is no longer necessary.

ldionne accepted this revision.Sep 15 2022, 8:06 AM
This revision is now accepted and ready to land.Sep 15 2022, 8:06 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 16 2022, 1:13 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript