authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-06 23:13:32+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:04+02:00
log11bdfe11791b530f991e9e03c647b1897dd1ad69
tree23694688f90c3821acf3ddb9a8a10b2e9466ed85
parent031e12b963726d47d6e0e0a10e51cfbb73baa0e3

elf: test large alignment of funcs in DSO


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

test/link/elf.zig+48
...@@ -42,6 +42,7 @@ pub fn build(b: *Build) void {...@@ -42,6 +42,7 @@ pub fn build(b: *Build) void {
4242
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}46}
4647
47fn testCommonSymbols(b: *Build, opts: Options) *Step {48fn testCommonSymbols(b: *Build, opts: Options) *Step {
...@@ -325,6 +326,53 @@ fn testGcSections(b: *Build, opts: Options) *Step {...@@ -325,6 +326,53 @@ fn testGcSections(b: *Build, opts: Options) *Step {
325 return test_step;326 return test_step;
326}327}
327328
329fn testLargeAlignmentDso(b: *Build, opts: Options) *Step {
330 const test_step = addTestStep(b, "large-alignment-dso", opts);
331
332 const dso = addSharedLibrary(b, opts);
333 addCSourceBytes(dso,
334 \\#include <stdio.h>
335 \\#include <stdint.h>
336 \\void hello() __attribute__((aligned(32768), section(".hello")));
337 \\void world() __attribute__((aligned(32768), section(".world")));
338 \\void hello() {
339 \\ printf("Hello");
340 \\}
341 \\void world() {
342 \\ printf(" world");
343 \\}
344 \\void greet() {
345 \\ hello();
346 \\ world();
347 \\}
348 , &.{"-fPIC"});
349 dso.link_function_sections = true;
350 dso.is_linking_libc = true;
351
352 const check = dso.checkObject();
353 check.checkInSymtab();
354 check.checkExtract("{addr1} {size1} {shndx1} FUNC GLOBAL DEFAULT hello");
355 check.checkInSymtab();
356 check.checkExtract("{addr2} {size2} {shndx2} FUNC GLOBAL DEFAULT world");
357 check.checkComputeCompare("addr1 16 %", .{ .op = .eq, .value = .{ .literal = 0 } });
358 check.checkComputeCompare("addr2 16 %", .{ .op = .eq, .value = .{ .literal = 0 } });
359 test_step.dependOn(&check.step);
360
361 const exe = addExecutable(b, opts);
362 addCSourceBytes(exe,
363 \\void greet();
364 \\int main() { greet(); }
365 , &.{});
366 exe.linkLibrary(dso);
367 exe.is_linking_libc = true;
368
369 const run = addRunArtifact(exe);
370 run.expectStdOutEqual("Hello world");
371 test_step.dependOn(&run.step);
372
373 return test_step;
374}
375
328fn testLinkingC(b: *Build, opts: Options) *Step {376fn testLinkingC(b: *Build, opts: Options) *Step {
329 const test_step = addTestStep(b, "linking-c", opts);377 const test_step = addTestStep(b, "linking-c", opts);
330378