authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-15 15:38:32+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:06+02:00
log5423778f6f9d1ec424bf74d40c16c433f20681b2
treed5899390e0ab2d9097949ec9def9f7791787f058
parent7b2cbcf0fe6dcaea7ee108c13422f6d00ed4bc8e

elf: add self-hosted tests


1 files changed, 67 insertions(+), 1 deletions(-)

test/link/elf.zig+67-1
...@@ -18,7 +18,9 @@ pub fn build(b: *Build) void {...@@ -18,7 +18,9 @@ pub fn build(b: *Build) void {
18 };18 };
1919
20 // Exercise linker with self-hosted backend (no LLVM)20 // Exercise linker with self-hosted backend (no LLVM)
21 // elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false }));21 elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false }));
22 elf_step.dependOn(testImportingDataDynamic(b, .{ .use_llvm = false, .target = glibc_target }));
23 elf_step.dependOn(testImportingDataStatic(b, .{ .use_llvm = false, .target = musl_target }));
2224
23 // Exercise linker with LLVM backend25 // Exercise linker with LLVM backend
24 // musl tests26 // musl tests
...@@ -1223,6 +1225,70 @@ fn testImageBase(b: *Build, opts: Options) *Step {...@@ -1223,6 +1225,70 @@ fn testImageBase(b: *Build, opts: Options) *Step {
1223 return test_step;1225 return test_step;
1224}1226}
12251227
1228fn testImportingDataDynamic(b: *Build, opts: Options) *Step {
1229 const test_step = addTestStep(b, "importing-data-dynamic", opts);
1230
1231 const dso = addSharedLibrary(b, "a", .{
1232 .target = opts.target,
1233 .optimize = opts.optimize,
1234 .use_llvm = true,
1235 });
1236 addCSourceBytes(dso, "int foo = 42;", &.{});
1237
1238 const main = addExecutable(b, "main", opts);
1239 addZigSourceBytes(main,
1240 \\extern var foo: i32;
1241 \\pub fn main() void {
1242 \\ @import("std").debug.print("{d}\n", .{foo});
1243 \\}
1244 );
1245 main.pie = true;
1246 main.strip = true; // TODO temp hack
1247 main.linkLibrary(dso);
1248 main.linkLibC();
1249
1250 const run = addRunArtifact(main);
1251 run.expectStdErrEqual("42\n");
1252 test_step.dependOn(&run.step);
1253
1254 return test_step;
1255}
1256
1257fn testImportingDataStatic(b: *Build, opts: Options) *Step {
1258 const test_step = addTestStep(b, "importing-data-static", opts);
1259
1260 const obj = addObject(b, "a", .{
1261 .target = opts.target,
1262 .optimize = opts.optimize,
1263 .use_llvm = true,
1264 });
1265 addCSourceBytes(obj, "int foo = 42;", &.{});
1266
1267 const lib = addStaticLibrary(b, "a", .{
1268 .target = opts.target,
1269 .optimize = opts.optimize,
1270 .use_llvm = true,
1271 });
1272 lib.addObject(obj);
1273
1274 const main = addExecutable(b, "main", opts);
1275 addZigSourceBytes(main,
1276 \\extern var foo: i32;
1277 \\pub fn main() void {
1278 \\ @import("std").debug.print("{d}\n", .{foo});
1279 \\}
1280 );
1281 main.strip = true; // TODO temp hack
1282 main.linkLibrary(lib);
1283 main.linkLibC();
1284
1285 const run = addRunArtifact(main);
1286 run.expectStdErrEqual("42\n");
1287 test_step.dependOn(&run.step);
1288
1289 return test_step;
1290}
1291
1226fn testInitArrayOrder(b: *Build, opts: Options) *Step {1292fn testInitArrayOrder(b: *Build, opts: Options) *Step {
1227 const test_step = addTestStep(b, "init-array-order", opts);1293 const test_step = addTestStep(b, "init-array-order", opts);
12281294