Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DWARF input format #55450

Merged
merged 6 commits into from Oct 17, 2023
Merged

DWARF input format #55450

merged 6 commits into from Oct 17, 2023

Conversation

al13n321
Copy link
Member

@al13n321 al13n321 commented Oct 10, 2023

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

  • Added DWARF input format that reads debug symbols from an ELF executable/library/object file.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Because grepping dwarfdump output is very slow and inconvenient.

@robot-clickhouse robot-clickhouse added the pr-feature Pull request with new product feature label Oct 10, 2023
@robot-clickhouse
Copy link
Member

robot-clickhouse commented Oct 10, 2023

This is an automated comment for commit abd35e0 with description of existing statuses. It's updated for the latest CI running

✅ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub✅ success
Docs CheckBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub✅ success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool✅ success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style CheckRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@al13n321 al13n321 added the force tests Force test ignoring fast test output. label Oct 10, 2023
@al13n321 al13n321 added the can be tested Allows running workflows for external contributors label Oct 10, 2023
@al13n321 al13n321 removed the force tests Force test ignoring fast test output. label Oct 10, 2023
@al13n321 al13n321 marked this pull request as ready for review October 10, 2023 20:50
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the submodule changed At least one submodule changed in this PR. label Oct 11, 2023
@antonio2368 antonio2368 self-assigned this Oct 11, 2023
auto tag_names = ColumnString::create();
/// Note: TagString() returns empty string for tags that don't exist, and tag 0 doesn't exist.
for (uint32_t tag = 0; tag <= UINT16_MAX; ++tag)
append(tag_names, removePrefix(llvm::dwarf::TagString(tag), strlen("DW_TAG_")));
Copy link
Member

Choose a reason for hiding this comment

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

we will repeat strlen for each tag, no? why not store the prefix_size in variable?

Copy link
Member Author

@al13n321 al13n321 Oct 12, 2023

Choose a reason for hiding this comment

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

Compilers usually optimize it out: https://godbolt.org/z/M7dTqPvKK . Even if not (e.g. in debug build), doing a short strlen 64 K times is cheap enough.

So I thought it's not worth the extra code to avoid this... except I didn't realize that it's only 1 line of extra code. Guess I'll add it, just to prevent the next reader of the code from wondering about this.

Comment on lines 309 to 312
if (need[COL_ATTR_FORM] || need[COL_ATTR_INT] || need[COL_ATTR_STR])
need[COL_ATTR_NAME] = true;
if (need[COL_ANCESTOR_OFFSETS])
need[COL_ANCESTOR_TAGS] = true;
Copy link
Member

Choose a reason for hiding this comment

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

can these be a simple assignment?

Suggested change
if (need[COL_ATTR_FORM] || need[COL_ATTR_INT] || need[COL_ATTR_STR])
need[COL_ATTR_NAME] = true;
if (need[COL_ANCESTOR_OFFSETS])
need[COL_ANCESTOR_TAGS] = true;
need[COL_ATTR_NAME] = need[COL_ATTR_FORM] || need[COL_ATTR_INT] || need[COL_ATTR_STR];
need[COL_ANCESTOR_TAGS] = need[COL_ANCESTOR_OFFSETS];

Copy link
Member Author

Choose a reason for hiding this comment

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

(That would be |=, which annoyingly produces compiler warnings-treated-as-errors for bool. Will change to x = x || y, which still looks nicer than the ifs, I guess.)

{
if (attr.Attr == llvm::dwarf::DW_AT_language) // programming language
append(col_attr_str, removePrefix(llvm::dwarf::LanguageString(static_cast<uint32_t>(val.getRawUValue())),
strlen("DW_LANG_")));
Copy link
Member

Choose a reason for hiding this comment

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

does it make sense to create static constexpr std::string_view for these common prefixes so you can simply call .size() method on them?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, nice trick, constexpr size_t x = strlen("foo") doesn't work (lame) but constexpr std::string_view x = "foo"; ... x.size() does.

@al13n321
Copy link
Member Author

Uh oh, MSAN fails with this nonsense:

Oct 12 05:06:26   ORIGIN: invalid (0). Might be a bug in MemorySanitizer origin tracking.
Oct 12 05:06:26     This could still be a bug in your code, too!

They can't distinguish between a compiler bug and a program bug! What kind of design is that. Why do I keep running into sanitizer-related compiler bugs.

https://s3.amazonaws.com/clickhouse-builds/PRs/55450/637822e163aac09f0fed7badcf609d0fae03c2e4/package_msan/build_log.log

@@ -54,9 +54,6 @@ if (SANITIZE)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SAN_FLAGS} ${UBSAN_FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SAN_FLAGS} ${UBSAN_FLAGS}")

# llvm-tblgen, that is used during LLVM build, doesn't work with UBSan.
set (ENABLE_EMBEDDED_COMPILER 0 CACHE BOOL "")
Copy link
Member Author

Choose a reason for hiding this comment

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

This seemed redundant with the check in contrib/llvm-project-cmake/CMakeLists.txt, moved the comment into there.

else()
set (ENABLE_EMBEDDED_COMPILER_DEFAULT ON)
set (ENABLE_EMBEDDED_COMPILER_DEFAULT ${ENABLE_LIBRARIES})
Copy link
Member Author

Choose a reason for hiding this comment

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

Made ENABLE_LIBRARIES=0 imply ENABLE_EMBEDDED_COMPILER=0 by default. Hope there isn't a good reason why it wasn't done this way originally.

@@ -1,6 +1,5 @@
# Quick syntax check (2 minutes on 16-core server)
# Relatively quick syntax check (20 minutes on 16-core server)
Copy link
Member Author

@al13n321 al13n321 Oct 12, 2023

Choose a reason for hiding this comment

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

20 minutes is how long it took for me (on master branch without this PR). Did clang get 10x slower in 5 years? :o (More than that because computers got faster. But less because the code got bigger. Let's guess that these two effects roughly cancel out.) I heard that llvm gets slower with each version, but would have expected less than 1.6x/year.

@al13n321
Copy link
Member Author

Some possible features for future:

  • Decompressing ELF sections. E.g. libc debug symbols binaries at /usr/lib/debug/.build-id/*/*.debug have compressed .debug_* sections (flag ELFCOMPRESS_ZLIB), at least on Ubuntu on my machine.
  • Parse .gnu_debuglink section and load symbols from a different file (e.g. libc library has no symbols but has .gnu_debuglink pointing to somewhere in /usr/lib/debug/.build-id/*/*.debug to an ELF file with all the .debug_* sections). Maybe don't actually open the other file, that sounds sketchy, just throw an exception with the path of the file with symbols.
  • Parse locations (DW_AT_location/DW_AT_frame_base) into a column, maybe pretty-printing DWARF expressions.

@al13n321 al13n321 merged commit ce7eca0 into master Oct 17, 2023
283 checks passed
@al13n321 al13n321 deleted the dwarf branch October 17, 2023 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can be tested Allows running workflows for external contributors pr-feature Pull request with new product feature submodule changed At least one submodule changed in this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants