From 59f01e327a124f73873d08bd42e59b0ff4097516 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 20 Jul 2023 23:29:09 +0200 Subject: [PATCH] elf: test handling of preinit array --- test/elf.zig | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/elf.zig b/test/elf.zig index 7fc9ae4d..f953f83f 100644 --- a/test/elf.zig +++ b/test/elf.zig @@ -41,6 +41,7 @@ pub fn addElfTests(b: *Build, opts: Options) *Step { elf_step.dependOn(testLinkerScript(b, opts)); elf_step.dependOn(testNoEhFrameHdr(b, opts)); elf_step.dependOn(testPltGot(b, opts)); + elf_step.dependOn(testPreinitArray(b, opts)); elf_step.dependOn(testTlsDesc(b, opts)); elf_step.dependOn(testTlsDescImport(b, opts)); elf_step.dependOn(testTlsDescStatic(b, opts)); @@ -1663,6 +1664,39 @@ fn testPltGot(b: *Build, opts: Options) *Step { return test_step; } +fn testPreinitArray(b: *Build, opts: Options) *Step { + const test_step = b.step("test-elf-preinit-array", ""); + + { + const obj = cc(b, opts); + obj.addCSource("void _start() {}"); + obj.addArg("-c"); + + const exe = ld(b, opts); + exe.addFileSource(obj.out); + + const check = exe.check(); + check.checkInDynamicSection(); + check.checkNotPresent("PREINIT_ARRAY"); + } + + { + const exe = cc(b, opts); + exe.addCSource( + \\void preinit_fn() {} + \\int main() {} + \\__attribute__((section(".preinit_array"))) + \\void *preinit[] = { preinit_fn }; + ); + + const check = exe.check(); + check.checkInDynamicSection(); + check.checkContains("PREINIT_ARRAY"); + } + + return test_step; +} + fn testTlsDesc(b: *Build, opts: Options) *Step { const test_step = b.step("test-elf-tls-desc", "");