Skip to content

Update to 18.1.7#28

Merged
alexey-milovidov merged 12 commits intomasterfrom
u18.1.7
Jun 20, 2024
Merged

Update to 18.1.7#28
alexey-milovidov merged 12 commits intomasterfrom
u18.1.7

Conversation

@al13n321
Copy link
Copy Markdown
Member

Did this:

  1. Delete everything and copy libunwind/ directory from https://github.com/llvm/llvm-project/tree/llvmorg-18.1.7
  2. Look through these 68 commits: llvm-mirror/libunwind@master...ClickHouse:libunwind:854538ce337d631b619010528adff22cd58f9dce and cherry-pick the ones that are still relevant.

Context: this submodule is a fork of a discontinued mirror of llvm-libunwind. This fork is now completely divorced from that mirror, and we're copying the libunwind directory from https://github.com/llvm/llvm-project instead.

Perhaps we should delete contrib/libunwind and use contrib/llvm-project/libunwind instead. One obstacle is that contrib/llvm-project is quite old, and updating it seems like a lot of work. And maybe we'll want to use different versions of libunwind vs llvm. We could "update" contrib/llvm-project/libunwind without updating the rest of contrib/llvm-project (by copying the directory, just like this PR does), that would be easy, but then it doesn't seem that different than what we're doing here. In any case, this PR doesn't conflict with any future efforts to migrate to contrib/llvm-project/libunwind.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 20, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
6 out of 7 committers have signed the CLA.

✅ al13n321
✅ alexey-milovidov
✅ KochetovNicolai
✅ hanfei1991
✅ azat
✅ kitaisreal
❌ laplab
You have signed the CLA already but the status is still pending? Let us recheck it.

@alexey-milovidov alexey-milovidov merged commit 010ea7c into master Jun 20, 2024
_LIBUNWIND_WEAK_ALIAS(__unw_resume, unw_resume)

/// ClickHouse: Convenient helper (added for jemalloc)
int unw_backtrace(void **buffer, int size) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is - what prevents having this helper outside of this library in our code? Does it use private API?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't use private API. IIUC:

  • this function is present in the original libunwind, but not in llvm-libunwind,
  • jemalloc uses it: contrib/jemalloc/src/prof_sys.c includes <libunwind.h> and calls unw_backtrace().

So we have to put it in libunwind.h, or patch jemalloc, or (if I'm reading the code correctly) use mallctl("experimental.hooks.prof_backtrace", nullptr, nullptr, &unw_backtrace, 8) to provide the function at runtime.

Copy link
Copy Markdown
Member

@azat azat Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jemalloc uses it: contrib/jemalloc/src/prof_sys.c includes <libunwind.h> and calls unw_backtrace().

It does not use unw_backtrace, since JEMALLOC_PROF_LIBUNWIND is not defined, JEMALLOC_PROF_LIBGCC is used - https://github.com/ClickHouse/ClickHouse/blob/9e9862066fcf5fae5342289c6134627b335126f2/contrib/jemalloc-cmake/CMakeLists.txt#L182-L187

Example of stacktrace - https://pastila.nl/?00d7b55b/044b1c710ec1b6f40a1142ba6d8555ab#1spY2b4S8szuWI9B3XSdRA== (by @antonio2368 )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out! There are 2 more uses of unw_backtrace, both in our own code:

  • contrib/llvm-project/libcxx/include/exception
  • src/Common/StackTrace.cpp
    After removing these it builds. We should probably replace them both with _Unwind_Backtrace.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Egh, now, it is used - ClickHouse/ClickHouse#66346

So I'm suggesting to leave it as-is for now, until all the callers will be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants