Improve build path mapping to produce clean relative paths in stack traces by Algunenano · Pull Request #102000 · ClickHouse/ClickHouse · GitHub
Skip to content

Improve build path mapping to produce clean relative paths in stack traces#102000

Merged
Algunenano merged 2 commits into
ClickHouse:masterfrom
Algunenano:improve-build-path-mapping
Apr 8, 2026
Merged

Improve build path mapping to produce clean relative paths in stack traces#102000
Algunenano merged 2 commits into
ClickHouse:masterfrom
Algunenano:improve-build-path-mapping

Conversation

@Algunenano

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

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

Stack traces now show clean bare relative paths (e.g. src/Common/Exception.cpp) instead of paths polluted with the build directory (e.g. ./ci/tmp/fast_build/./src/Common/Exception.cpp).

Description

ENABLE_BUILD_PATH_MAPPING previously used -ffile-prefix-map=${SOURCE_DIR}=., which mapped source paths to ./src/Foo.cpp but left DW_AT_comp_dir pointing at the build directory. The symbolizer joined them, producing paths like ./ci/tmp/fast_build/./src/Common/Exception.cpp in out-of-tree CI builds.

This PR replaces the single flag with two Clang-specific flags:

  • -fdebug-compilation-dir=. — pins DW_AT_comp_dir to . unconditionally, regardless of where the build directory is located.
  • -ffile-prefix-map=${SOURCE_DIR}/= — strips the source root prefix including the separator, leaving bare relative paths like src/Foo.cpp.

It also fixes Dwarf::LineNumberVM::getFullFileName to skip a directory entry of "." when building file paths. The DWARF 5 line number program stores the compilation directory as an explicit entry (index 0), which after the prefix mapping becomes ".". Prepending it produced ./src/Foo.cpp for .cpp translation units while inlined header frames showed as src/Common/Foo.h — inconsistent. Treating "." as an empty directory makes all paths consistently bare relative.

Before:

1. ./ci/tmp/fast_build/./src/Common/Exception.cpp:139:7: ...
2. src/Common/Exception.h:171:100: ...
5. ./programs/server/Server.cpp:2942:23: ...

After:

1. src/Common/Exception.cpp:139:7: ...
2. src/Common/Exception.h:171:100: ...
5. programs/server/Server.cpp:2942:23: ...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

…races

Previously, `ENABLE_BUILD_PATH_MAPPING` used `-ffile-prefix-map=${SOURCE_DIR}=.`,
which mapped source paths to `./src/Foo.cpp` but left `DW_AT_comp_dir` pointing
at the build directory. The symbolizer joined them, producing paths like
`./ci/tmp/fast_build/./src/Foo.cpp` in out-of-tree CI builds.

Replace the single flag with two Clang-specific flags:
- `-fdebug-compilation-dir=.` — pins `DW_AT_comp_dir` to `.` unconditionally,
  regardless of where the build directory is located.
- `-ffile-prefix-map=${SOURCE_DIR}/=` — strips the source root prefix including
  the separator, leaving bare relative paths like `src/Foo.cpp`.

Also fix `Dwarf::LineNumberVM::getFullFileName` to skip a directory entry of `"."`
when building file paths. The DWARF 5 line number program stores the compilation
directory as an explicit entry (index 0), which after the prefix mapping becomes
`"."`. Prepending it produced `./src/Foo.cpp` for `.cpp` translation units while
inlined header frames (whose directory entries were absolute paths that mapped to
`src/Common`) showed as `src/Common/Foo.h` — inconsistent. Treating `"."` as
an empty directory makes all paths consistently bare relative.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added the pr-build Pull request with build/testing/packaging improvement label Apr 7, 2026
Comment thread CMakeLists.txt
@alexey-milovidov alexey-milovidov self-assigned this Apr 7, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

The test 02859_replicated_db_name_zookeeper is fixed in #101952

@clickhouse-gh

clickhouse-gh Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.90% 83.90% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.40% 76.40% +0.00%

Changed lines: 100.00% (4/4) · Uncovered code

Full report · Diff report

@Algunenano Algunenano added this pull request to the merge queue Apr 8, 2026
Merged via the queue into ClickHouse:master with commit cf5fb46 Apr 8, 2026
160 of 163 checks passed
@Algunenano Algunenano deleted the improve-build-path-mapping branch April 8, 2026 18:33
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants