ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.68k stars 2.47k forks source link

LTO ignores linker script KEEP directives #9844

Open leecannon opened 2 years ago

leecannon commented 2 years ago

A linker script with a section containing a KEEP directive and with a symbol exported into that section is not present in the binary if LTO is enabled.

in linker script:

.stivale2hdr ALIGN(4K) : {
    KEEP(*(.stivale2hdr))
} :rodata

in root zig file:

pub export const header linksection(".stivale2hdr") = // struct initalization here

If want_lto is set to false or null then the binary will contain the stivale2hdr section

andrewrk commented 2 years ago

Next step will be to file an upstream bug report to LLD/LLVM.