This is an archive of the discontinued LLVM Phabricator instance.

[libc++][libunwind] Fixes to allow GCC 13 to compile libunwind/libc++abi/libc++
ClosedPublic

Authored by philnik on May 24 2023, 4:24 PM.

Details

Reviewers
ldionne
MaskRay
Group Reviewers
Restricted Project
Restricted Project
Commits
rG3537338d1ab9: [libc++][libunwind] Fixes to allow GCC 13 to compile libunwind/libc++abi/libc++
Summary

These are changes to allow GCC 13 to successfully compile the runtimes stack.

Diff Detail

Event Timeline

philnik created this revision.May 24 2023, 4:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 4:24 PM
philnik requested review of this revision.May 24 2023, 4:24 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 24 2023, 4:24 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
arichardson added inline comments.
libunwind/src/CMakeLists.txt
149

Why is this needed? Shouldn't it work without linking c++abi/standard library?

mstorsjo added inline comments.
libunwind/src/CMakeLists.txt
149

Indeed, libunwind must not rely on the C++ standard library - that's a layering violation. What's the issue that this tries to fix?

libunwind explicitly doesn't even include C++ standard library headers (building with -nostdinc++) in order to stay clear of any dependencies on it. Not sure if any of the CI configurations would show the issue here, but if we'd have the new CI configuration from D150766 merged, that one most definitely would fail on this change.

philnik added inline comments.May 25 2023, 7:51 AM
libunwind/src/CMakeLists.txt
149

GCC 13 doesn't accept -nostdlib++ in C mode. Given that these flags are passed explicitly, I don't think there should be a problem with invoking the driver in C++ mode.

ldionne accepted this revision as: Restricted Project, ldionne.May 25 2023, 8:26 AM
ldionne added a subscriber: power-llvm-team.

This LGTM. I think it should be fine to link libunwind as C++ since we pass -nostdlib++, but please make sure @arichardson and @mstorsjo are on board before landing.

libcxx/include/__type_traits/remove_cv.h
22–38
#if __has_builtin(__remove_cv)

// GCC can't mangle builtins so they can't appear in an alias directly
#   if !defined(_LIBCPP_COMPILER_GCC)
template <class _Tp>
using __remove_cv_t = __remove_cv(_Tp);
#else
template <class _Tp>
struct __libcpp_remove_cv {
  using type _LIBCPP_NODEBUG = __remove_cv(_Tp);
};

template <class _Tp>
using __remove_cv_t = typename __libcpp_remove_cv<_Tp>::type;
#endif

#else

template <class _Tp>
using __remove_cv_t = __remove_volatile_t<__remove_const_t<_Tp> >;

#endif // __has_builtin(__remove_cv)

This is equivalent but the logic seems a bit easier to follow.

libcxx/include/__type_traits/remove_cvref.h
23

Same comments here.

libunwind/src/CMakeLists.txt
1

@power-llvm-team Can you please help us understand the failure on AIX at https://buildkite.com/llvm-project/libcxx-ci/builds/24846#01885016-92a1-4955-a7cb-e87fc56b59e5 ?

All the tests on AIX are failing with something like:

Could not load program /scratch/powerllvm/cpap8008/llvm-project/libcxx-ci/build/aix/test/std/utilities/expected/expected.void/observers/Output/error.pass.cpp.dir/t.tmp.exe:
Symbol resolution failed for /scratch/powerllvm/cpap8008/llvm-project/libcxx-ci/build/aix/lib/libunwind.a(libunwind.so.1) because:
	Symbol unw_getcontext (number 14) is not exported from dependent
	  module /scratch/powerllvm/cpap8008/llvm-project/libcxx-ci/build/aix/lib/libunwind.a(libunwind.so.1).
	Symbol unw_init_local (number 15) is not exported from dependent
	  module /scratch/powerllvm/cpap8008/llvm-project/libcxx-ci/build/aix/lib/libunwind.a(libunwind.so.1).
	Symbol unw_step (number 16) is not exported from dependent
	  module /scratch/powerllvm/cpap8008/llvm-project/libcxx-ci/build/aix/lib/libunwind.a(libunwind.so.1).
	Symbol unw_get_reg (number 17) is not exported from dependent
	  module /scratch/powerllvm/cpap8008/llvm-project/libcxx-ci/build/aix/lib/libunwind.a(libunwind.so.1).
	Symbol unw_get_fpreg (number 18) is not exported from dependent
	  module /scratch/powerllvm/cpap8008/llvm-project/libcxx-ci/build/aix/lib/libunwind.a(libunwind.so.1).
        [...]
Examine .loader section symbols with the 'dump -Tv' command.

error: command failed with exit status: 255

This is likely related to changing the linker language from C to CXX and it seems like suddenly the symbol names exported by libunwind are not correct anymore, but that's weird cause everything should be in extern "C" context anyway.

mstorsjo added inline comments.May 25 2023, 12:38 PM
libunwind/src/CMakeLists.txt
149

Oh, right, we use that too - yes, with -nostdlib++ it's probably fine. But it would be nice to have D150766 in place so we'd have better CI coverage of that aspect.

I can run this patch through a test build from scratch in my config to be sure.

mstorsjo added inline comments.May 25 2023, 1:07 PM
libunwind/src/CMakeLists.txt
149

This did build fine for me, so consider this objection withdrawn.

MaskRay added inline comments.
libunwind/src/CMakeLists.txt
149

D95875 added -nostdlib++ here. Can we remove it or make it z/OS specific @zibi @SeanP

MaskRay accepted this revision.EditedJun 2 2023, 9:09 AM

libunwind LGTM, but I suspect the LINKER_LANGUAGE CXX change in libunwind is adding a workaround on top of another one D95875

Newer GCC supports g++ -nostdlib++ but not gcc -nostdlib++. If we don't add -nostdlib++ to link flags, we can keep LINKER_LANGUAGE C.

This revision is now accepted and ready to land.Jun 2 2023, 9:09 AM
zibi added inline comments.Jun 5 2023, 11:59 AM
libunwind/src/CMakeLists.txt
149

The -nostdlib++ can be removed. It was initially added for consistency with libcxx and libcxxabi configurations but those are built with CXX.

philnik updated this revision to Diff 547047.Aug 3 2023, 4:39 PM
philnik marked 9 inline comments as done.

Remove -nostdinc++

@MaskRay I've removed both -nostdinc++ and -nodefaultlibs, since the latter doesn't add anything that we don't re-add anyways. I'll try to make some cleanup patches later, but we should really get this fixed, since LLVM17 should support GCC13.

This revision was landed with ongoing or failed builds.Aug 4 2023, 12:51 AM
This revision was automatically updated to reflect the committed changes.