authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-01 14:44:13+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-01 14:46:00+02:00
log4219825042057ce901df1261e089ef477c381fe7
tree115ebebba1704257e3add611afd1f5ae9284eb05
parent7be3b1de455c9cf247dc3ab8c4fd75c9b16d77cf
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

test: use -ffunction-sections -fdata-sections for C backend module tests if needed

We need this for certain targets for the same reason we do it when bootstrapping the compiler from zig1.wasm.

1 files changed, 60 insertions(+), 39 deletions(-)

test/tests.zig+60-39
......@@ -2811,45 +2811,66 @@ fn addOneModuleTest(
28112811
28122812 compile_c.addCSourceFile(.{
28132813 .file = these_tests.getEmittedBin(),
2814 .flags = &.{
2815 // Tracking issue for making the C backend generate C89 compatible code:
2816 // https://github.com/ziglang/zig/issues/19468
2817 "-std=c99",
2818 "-Werror",
2819
2820 "-Wall",
2821 "-Wembedded-directive",
2822 "-Wempty-translation-unit",
2823 "-Wextra",
2824 "-Wgnu",
2825 "-Winvalid-utf8",
2826 "-Wkeyword-macro",
2827 "-Woverlength-strings",
2828
2829 // Tracking issue for making the C backend generate code
2830 // that does not trigger warnings:
2831 // https://github.com/ziglang/zig/issues/19467
2832
2833 // spotted everywhere
2834 "-Wno-builtin-requires-header",
2835
2836 // spotted on linux
2837 "-Wno-braced-scalar-init",
2838 "-Wno-excess-initializers",
2839 "-Wno-incompatible-pointer-types-discards-qualifiers",
2840 "-Wno-unused",
2841 "-Wno-unused-parameter",
2842
2843 // spotted on darwin
2844 "-Wno-incompatible-pointer-types",
2845
2846 // https://github.com/llvm/llvm-project/issues/153314
2847 "-Wno-unterminated-string-initialization",
2848
2849 // In both Zig and C it is legal to return a pointer to a
2850 // local. The C backend lowers such thing directly, so the
2851 // corresponding warning in C must be disabled.
2852 "-Wno-return-stack-address",
2814 .flags = blk: {
2815 const invariant_cflags: []const []const u8 = &.{
2816 // Tracking issue for making the C backend generate C89 compatible code:
2817 // https://github.com/ziglang/zig/issues/19468
2818 "-std=c99",
2819 "-Werror",
2820
2821 "-Wall",
2822 "-Wembedded-directive",
2823 "-Wempty-translation-unit",
2824 "-Wextra",
2825 "-Wgnu",
2826 "-Winvalid-utf8",
2827 "-Wkeyword-macro",
2828 "-Woverlength-strings",
2829
2830 // Tracking issue for making the C backend generate code
2831 // that does not trigger warnings:
2832 // https://github.com/ziglang/zig/issues/19467
2833
2834 // spotted everywhere
2835 "-Wno-builtin-requires-header",
2836
2837 // spotted on linux
2838 "-Wno-braced-scalar-init",
2839 "-Wno-excess-initializers",
2840 "-Wno-incompatible-pointer-types-discards-qualifiers",
2841 "-Wno-unused",
2842 "-Wno-unused-parameter",
2843
2844 // spotted on darwin
2845 "-Wno-incompatible-pointer-types",
2846
2847 // https://github.com/llvm/llvm-project/issues/153314
2848 "-Wno-unterminated-string-initialization",
2849
2850 // In both Zig and C it is legal to return a pointer to a
2851 // local. The C backend lowers such thing directly, so the
2852 // corresponding warning in C must be disabled.
2853 "-Wno-return-stack-address",
2854 };
2855
2856 const function_data_sections = switch (target.cpu.arch) {
2857 .arm,
2858 .armeb,
2859 .thumb,
2860 .thumbeb,
2861 .hexagon,
2862 .powerpc,
2863 .powerpcle,
2864 .powerpc64,
2865 .powerpc64le,
2866 => true,
2867 else => false,
2868 };
2869
2870 break :blk if (function_data_sections) invariant_cflags ++ &[_][]const u8{
2871 "-ffunction-sections",
2872 "-fdata-sections",
2873 } else invariant_cflags;
28532874 },
28542875 });
28552876 compile_c.addIncludePath(b.path("lib")); // for zig.h