mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-09 15:19:07 +00:00
elf: test basic DSO generation and linking
This commit is contained in:
parent
ac03a35e82
commit
e53fa93170
1 changed files with 59 additions and 0 deletions
|
|
@ -11,6 +11,11 @@ pub fn build(b: *Build) void {
|
||||||
.os_tag = .linux,
|
.os_tag = .linux,
|
||||||
.abi = .musl,
|
.abi = .musl,
|
||||||
};
|
};
|
||||||
|
const glibc_target = CrossTarget{
|
||||||
|
.cpu_arch = .x86_64,
|
||||||
|
.os_tag = .linux,
|
||||||
|
.abi = .gnu,
|
||||||
|
};
|
||||||
|
|
||||||
// Exercise linker with self-hosted backend (no LLVM)
|
// Exercise linker with self-hosted backend (no LLVM)
|
||||||
// elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false }));
|
// elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false }));
|
||||||
|
|
@ -24,6 +29,10 @@ pub fn build(b: *Build) void {
|
||||||
elf_step.dependOn(testLinkingCpp(b, .{ .target = musl_target }));
|
elf_step.dependOn(testLinkingCpp(b, .{ .target = musl_target }));
|
||||||
elf_step.dependOn(testLinkingZig(b, .{ .target = musl_target }));
|
elf_step.dependOn(testLinkingZig(b, .{ .target = musl_target }));
|
||||||
elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target }));
|
elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target }));
|
||||||
|
|
||||||
|
for (&[_]CrossTarget{ glibc_target, musl_target }) |target| {
|
||||||
|
elf_step.dependOn(testDsoPlt(b, .{ .target = target }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn testCommonSymbols(b: *Build, opts: Options) *Step {
|
fn testCommonSymbols(b: *Build, opts: Options) *Step {
|
||||||
|
|
@ -122,6 +131,46 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step {
|
||||||
return test_step;
|
return test_step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn testDsoPlt(b: *Build, opts: Options) *Step {
|
||||||
|
const test_step = addTestStep(b, "dso-plt", opts);
|
||||||
|
|
||||||
|
const dso = addSharedLibrary(b, opts);
|
||||||
|
addCSourceBytes(dso,
|
||||||
|
\\#include<stdio.h>
|
||||||
|
\\void world() {
|
||||||
|
\\ printf("world\n");
|
||||||
|
\\}
|
||||||
|
\\void real_hello() {
|
||||||
|
\\ printf("Hello ");
|
||||||
|
\\ world();
|
||||||
|
\\}
|
||||||
|
\\void hello() {
|
||||||
|
\\ real_hello();
|
||||||
|
\\}
|
||||||
|
, &.{"-fPIC"});
|
||||||
|
dso.is_linking_libc = true;
|
||||||
|
|
||||||
|
const exe = addExecutable(b, opts);
|
||||||
|
addCSourceBytes(exe,
|
||||||
|
\\#include<stdio.h>
|
||||||
|
\\void world() {
|
||||||
|
\\ printf("WORLD\n");
|
||||||
|
\\}
|
||||||
|
\\void hello();
|
||||||
|
\\int main() {
|
||||||
|
\\ hello();
|
||||||
|
\\}
|
||||||
|
, &.{});
|
||||||
|
exe.linkLibrary(dso);
|
||||||
|
exe.is_linking_libc = true;
|
||||||
|
|
||||||
|
const run = addRunArtifact(exe);
|
||||||
|
run.expectStdOutEqual("Hello WORLD\n");
|
||||||
|
test_step.dependOn(&run.step);
|
||||||
|
|
||||||
|
return test_step;
|
||||||
|
}
|
||||||
|
|
||||||
fn testEmptyObject(b: *Build, opts: Options) *Step {
|
fn testEmptyObject(b: *Build, opts: Options) *Step {
|
||||||
const test_step = addTestStep(b, "empty-object", opts);
|
const test_step = addTestStep(b, "empty-object", opts);
|
||||||
|
|
||||||
|
|
@ -391,6 +440,16 @@ fn addStaticLibrary(b: *Build, opts: Options) *Compile {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn addSharedLibrary(b: *Build, opts: Options) *Compile {
|
||||||
|
return b.addSharedLibrary(.{
|
||||||
|
.name = "a.so",
|
||||||
|
.target = opts.target,
|
||||||
|
.optimize = opts.optimize,
|
||||||
|
.use_llvm = opts.use_llvm,
|
||||||
|
.use_lld = false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn addRunArtifact(comp: *Compile) *Run {
|
fn addRunArtifact(comp: *Compile) *Run {
|
||||||
const b = comp.step.owner;
|
const b = comp.step.owner;
|
||||||
const run = b.addRunArtifact(comp);
|
const run = b.addRunArtifact(comp);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue