[clang] [Clang] Add clang driver option -fpartition-static-data-sections (PR #124991)
Mingming Liu via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 26 09:40:11 PST 2025
mingmingl-llvm wrote:
> > > Can we ensure that `-z,keep-data-section-prefix` gets passed to the linker too from the driver? Should it be part of this pull request?
> >
> >
> > I actually did wonder about it when making the changes; inferred from the current status, it's more canonical to let users specify linker options separately.
> > [tools::gnutools::Linker::ConstructJob](https://github.com/llvm/llvm-project/blob/1cb99036b41562b233e7bb44801202742733f5d3/clang/lib/Driver/ToolChains/Gnu.cpp#L271) and its caller [LinkerWrapper::ConstructJob](https://github.com/llvm/llvm-project/blob/4e44e8761795d4672121368929b9c99f6dbaffa7/clang/lib/Driver/ToolChains/Clang.cpp#L9223) [1](#user-content-fn-1-26e65359c78b52e446e24e4987530693) constructs the linker options, and PGO linker options like `-keep-text-section-prefix` are not implied; toolchain users typically specify `-Wl,-z,keep-text-section-prefix` besides `-fprofile-use` to partition text sections.
> > ## Footnotes
> >
> > 1. While 'gnu' is in the namespace / filename, the functions get invoked when compiling a binary the common way. [↩](#user-content-fnref-1-26e65359c78b52e446e24e4987530693)
>
> Thanks for looking at it. As long as we have some documentation somewhere it sgtm.
Added comment as lightweight code documentation. Will also mention this in the user guide.
Regarding why Clang driver option doesn't imply linker option, my best guess is that using Clang with a non-lld linker is supported, and Clang driver is kept simple (and more consistent across linkers) this way (i.e., no need to look at linker flavor or its version to add options conditionally).
https://github.com/llvm/llvm-project/pull/124991
More information about the cfe-commits
mailing list