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(...@@ -2811,45 +2811,66 @@ fn addOneModuleTest(
28112811
2812 compile_c.addCSourceFile(.{2812 compile_c.addCSourceFile(.{
2813 .file = these_tests.getEmittedBin(),2813 .file = these_tests.getEmittedBin(),
2814 .flags = &.{2814 .flags = blk: {
2815 // Tracking issue for making the C backend generate C89 compatible code:2815 const invariant_cflags: []const []const u8 = &.{
2816 // https://github.com/ziglang/zig/issues/194682816 // Tracking issue for making the C backend generate C89 compatible code:
2817 "-std=c99",2817 // https://github.com/ziglang/zig/issues/19468
2818 "-Werror",2818 "-std=c99",
28192819 "-Werror",
2820 "-Wall",2820
2821 "-Wembedded-directive",2821 "-Wall",
2822 "-Wempty-translation-unit",2822 "-Wembedded-directive",
2823 "-Wextra",2823 "-Wempty-translation-unit",
2824 "-Wgnu",2824 "-Wextra",
2825 "-Winvalid-utf8",2825 "-Wgnu",
2826 "-Wkeyword-macro",2826 "-Winvalid-utf8",
2827 "-Woverlength-strings",2827 "-Wkeyword-macro",
28282828 "-Woverlength-strings",
2829 // Tracking issue for making the C backend generate code2829
2830 // that does not trigger warnings:2830 // Tracking issue for making the C backend generate code
2831 // https://github.com/ziglang/zig/issues/194672831 // that does not trigger warnings:
28322832 // https://github.com/ziglang/zig/issues/19467
2833 // spotted everywhere2833
2834 "-Wno-builtin-requires-header",2834 // spotted everywhere
28352835 "-Wno-builtin-requires-header",
2836 // spotted on linux2836
2837 "-Wno-braced-scalar-init",2837 // spotted on linux
2838 "-Wno-excess-initializers",2838 "-Wno-braced-scalar-init",
2839 "-Wno-incompatible-pointer-types-discards-qualifiers",2839 "-Wno-excess-initializers",
2840 "-Wno-unused",2840 "-Wno-incompatible-pointer-types-discards-qualifiers",
2841 "-Wno-unused-parameter",2841 "-Wno-unused",
28422842 "-Wno-unused-parameter",
2843 // spotted on darwin2843
2844 "-Wno-incompatible-pointer-types",2844 // spotted on darwin
28452845 "-Wno-incompatible-pointer-types",
2846 // https://github.com/llvm/llvm-project/issues/1533142846
2847 "-Wno-unterminated-string-initialization",2847 // https://github.com/llvm/llvm-project/issues/153314
28482848 "-Wno-unterminated-string-initialization",
2849 // In both Zig and C it is legal to return a pointer to a2849
2850 // local. The C backend lowers such thing directly, so the2850 // In both Zig and C it is legal to return a pointer to a
2851 // corresponding warning in C must be disabled.2851 // local. The C backend lowers such thing directly, so the
2852 "-Wno-return-stack-address",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;
2853 },2874 },
2854 });2875 });
2855 compile_c.addIncludePath(b.path("lib")); // for zig.h2876 compile_c.addIncludePath(b.path("lib")); // for zig.h