Skip to content

Enable full RELRO - #119037

Merged
Algunenano merged 1 commit into
ClickHouse:masterfrom
Algunenano:full-relro
Sep 10, 2026
Merged

Algunenano merged 1 commit into
ClickHouse:masterfrom
Algunenano:full-relro

Conversation

@Algunenano

@Algunenano Algunenano commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Link executables with -z relro -z now. All dynamic relocations are resolved at startup and the global offset table is mapped read-only afterwards. Previously only the linker default applied, which leaves the table writable for the lifetime of the process, so an arbitrary write could redirect a call through it.

Resolving everything at startup is free here: we link dynamically only against libc and we forbid dlopen.

Not enabled on Darwin, where ld64 does not accept -z options.

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

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

Harden official builds by enabling full RELRO: the global offset table is now mapped read-only after startup.


Workflow [PR]
Sync PR [sync-upstream/pr/119037]

Version info

  • Merged into: 26.9.1.1121 (included in 26.9 and later)

Link executables with `-z relro -z now`, so that all dynamic relocations
are resolved at startup and the global offset table is mapped read-only
afterwards. Previously only the linker default applied, which leaves the
table writable for the lifetime of the process, so an arbitrary write
could redirect a call through it.

Resolving everything at startup is free here: we link dynamically only
against libc and we forbid `dlopen`.

Not enabled on Darwin, where `ld64` does not accept `-z` options.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [274f40b]

Summary: ✅


AI Review

Summary

This PR adds -Wl,-z,relro,-z,now to executable link flags to enable full RELRO. That hardening makes sense for ELF targets, but the current guard is too broad and also applies the flag set to the tree's OS_WASM toolchain, where the stated GOT/RELRO model does not exist.

Findings

⚠️ Majors

  • [CMakeLists.txt:656] NOT OS_DARWIN is not the same as "ELF target". The tree still has an OS_WASM configuration, and cmake/tools.cmake routes it through emcc/wasm-ld; forwarding -z relro/-z now there does not provide the hardening this PR is claiming for executables. Gate this on the actual ELF platforms (OS_LINUX, OS_ANDROID, OS_FREEBSD, OS_SUNOS) instead of every non-Darwin target.
Final Verdict

Changes requested: narrow the condition to the supported ELF targets before merging.

LLVM Coverage Report

Measured on commit 274f40b.

Metric Baseline Current Δ
Lines 88.90% 88.90% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage).

Newly covered: +343 lines in 90 files (-149 lines lost coverage) · Details

Full report

@clickhouse-gh clickhouse-gh Bot added the pr-build Pull request with build/testing/packaging improvement label Sep 9, 2026
Comment thread CMakeLists.txt
# Resolving everything at startup costs nothing here because we link dynamically only against libc
# and we forbid dlopen (see programs/main.cpp).
# Not on Darwin: ld64 does not accept '-z' options.
if (NOT OS_DARWIN)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NOT OS_DARWIN is broader than the set of targets that actually have ELF RELRO/NOW semantics. This tree still has an OS_WASM configuration, and cmake/tools.cmake routes it through emcc/wasm-ld, so this condition forwards ELF-only -z flags to a non-ELF link step where the promised GOT hardening cannot happen.

Please gate this on the actual ELF platforms we support instead of every non-Darwin target.

@clickhouse-gh clickhouse-gh Bot added the comp-build-system Build system (CMake, compilation, platform builds). label Sep 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 274f40b29 with master 8845ae7a2 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@Algunenano

Copy link
Copy Markdown
Member Author

No noticeable performance changes

@Algunenano
Algunenano added this pull request to the merge queue Sep 10, 2026
Merged via the queue into ClickHouse:master with commit c625830 Sep 10, 2026
343 of 344 checks passed
@Algunenano
Algunenano deleted the full-relro branch September 10, 2026 12:14
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-build-system Build system (CMake, compilation, platform builds). 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.

2 participants