From 7ff9461b88678d4bc02ee31fc5159f57a1d7e2b2 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 6 Oct 2023 23:27:48 +0200 Subject: [PATCH] elf: test large alignment of funcs in exe --- test/link/elf.zig | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/link/elf.zig b/test/link/elf.zig index 7e5e002529..cd9ab5ea10 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -43,6 +43,10 @@ pub fn build(b: *Build) void { elf_step.dependOn(testDsoPlt(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); elf_step.dependOn(testDsoUndef(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); elf_step.dependOn(testLargeAlignmentDso(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); + + for (&[_]CrossTarget{ musl_target, glibc_target }) |target| { + elf_step.dependOn(testLargeAlignmentExe(b, .{ .target = target })); + } } fn testCommonSymbols(b: *Build, opts: Options) *Step { @@ -373,6 +377,49 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step { return test_step; } +fn testLargeAlignmentExe(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "large-alignment-exe", opts); + + const exe = addExecutable(b, opts); + addCSourceBytes(exe, + \\#include + \\#include + \\ + \\void hello() __attribute__((aligned(32768), section(".hello"))); + \\void world() __attribute__((aligned(32768), section(".world"))); + \\ + \\void hello() { + \\ printf("Hello"); + \\} + \\ + \\void world() { + \\ printf(" world"); + \\} + \\ + \\int main() { + \\ hello(); + \\ world(); + \\} + , &.{}); + exe.link_function_sections = true; + exe.is_linking_libc = true; + + const run = addRunArtifact(exe); + run.expectStdOutEqual("Hello world"); + test_step.dependOn(&run.step); + + const check = exe.checkObject(); + check.checkInSymtab(); + check.checkExtract("{addr1} {size1} {shndx1} FUNC LOCAL DEFAULT hello"); + check.checkInSymtab(); + check.checkExtract("{addr2} {size2} {shndx2} FUNC LOCAL DEFAULT world"); + check.checkComputeCompare("addr1 16 %", .{ .op = .eq, .value = .{ .literal = 0 } }); + check.checkComputeCompare("addr2 16 %", .{ .op = .eq, .value = .{ .literal = 0 } }); + test_step.dependOn(&check.step); + + return test_step; +} + fn testLinkingC(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "linking-c", opts);