Commit 9222758
authored
cpp_build: disable LTO to preserve metadata in .data section (#116)
The cpp crate communicates type metadata (sizes, alignments, trait
flags) from the build script to the proc-macro by embedding a struct
with a magic byte pattern in the .data section of the compiled static
library. The proc-macro then scans the .a file for this pattern using
aho-corasick.
When LTO is enabled via environment CXXFLAGS (e.g. -flto=auto, as is
the default on Arch Linux's makepkg), the C++ compiler emits GIMPLE
intermediate representation instead of native machine code. This
leaves the .data and .text sections empty — all content lives in
.gnu.lto_* sections as serialized IR. The magic bytes are no longer
visible to the byte-level scan, causing the proc-macro to panic with:
"Struct metadata not present in target library file."
Fix this by passing -fno-lto when compiling the generated C++ library.
This ensures the metadata struct is always present as raw bytes in
.data, regardless of the environment's LTO settings.
Fixes builds on distributions that enable LTO by default (Arch Linux,
Fedora, Gentoo with LTO profiles).1 parent cc63bb0 commit 9222758
1 file changed
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
657 | 666 | | |
658 | 667 | | |
659 | 668 | | |
| |||
0 commit comments