authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-06 23:27:48+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:05+02:00
log7ff9461b88678d4bc02ee31fc5159f57a1d7e2b2
tree00e40517e495172cbd4475b0bc925f11bd3faba6
parent11bdfe11791b530f991e9e03c647b1897dd1ad69

elf: test large alignment of funcs in exe


1 files changed, 47 insertions(+), 0 deletions(-)

test/link/elf.zig+47
...@@ -43,6 +43,10 @@ pub fn build(b: *Build) void {...@@ -43,6 +43,10 @@ pub fn build(b: *Build) void {
43 elf_step.dependOn(testDsoPlt(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker }));43 elf_step.dependOn(testDsoPlt(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker }));
44 elf_step.dependOn(testDsoUndef(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker }));44 elf_step.dependOn(testDsoUndef(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker }));
45 elf_step.dependOn(testLargeAlignmentDso(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker }));45 elf_step.dependOn(testLargeAlignmentDso(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker }));
46
47 for (&[_]CrossTarget{ musl_target, glibc_target }) |target| {
48 elf_step.dependOn(testLargeAlignmentExe(b, .{ .target = target }));
49 }
46}50}
4751
48fn testCommonSymbols(b: *Build, opts: Options) *Step {52fn testCommonSymbols(b: *Build, opts: Options) *Step {
...@@ -373,6 +377,49 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step {...@@ -373,6 +377,49 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step {
373 return test_step;377 return test_step;
374}378}
375379
380fn testLargeAlignmentExe(b: *Build, opts: Options) *Step {
381 const test_step = addTestStep(b, "large-alignment-exe", opts);
382
383 const exe = addExecutable(b, opts);
384 addCSourceBytes(exe,
385 \\#include <stdio.h>
386 \\#include <stdint.h>
387 \\
388 \\void hello() __attribute__((aligned(32768), section(".hello")));
389 \\void world() __attribute__((aligned(32768), section(".world")));
390 \\
391 \\void hello() {
392 \\ printf("Hello");
393 \\}
394 \\
395 \\void world() {
396 \\ printf(" world");
397 \\}
398 \\
399 \\int main() {
400 \\ hello();
401 \\ world();
402 \\}
403 , &.{});
404 exe.link_function_sections = true;
405 exe.is_linking_libc = true;
406
407 const run = addRunArtifact(exe);
408 run.expectStdOutEqual("Hello world");
409 test_step.dependOn(&run.step);
410
411 const check = exe.checkObject();
412 check.checkInSymtab();
413 check.checkExtract("{addr1} {size1} {shndx1} FUNC LOCAL DEFAULT hello");
414 check.checkInSymtab();
415 check.checkExtract("{addr2} {size2} {shndx2} FUNC LOCAL DEFAULT world");
416 check.checkComputeCompare("addr1 16 %", .{ .op = .eq, .value = .{ .literal = 0 } });
417 check.checkComputeCompare("addr2 16 %", .{ .op = .eq, .value = .{ .literal = 0 } });
418 test_step.dependOn(&check.step);
419
420 return test_step;
421}
422
376fn testLinkingC(b: *Build, opts: Options) *Step {423fn testLinkingC(b: *Build, opts: Options) *Step {
377 const test_step = addTestStep(b, "linking-c", opts);424 const test_step = addTestStep(b, "linking-c", opts);
378425