| ... | ... | @@ -16,6 +16,7 @@ pub fn build(b: *Build) void { |
| 16 | 16 | // elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false })); |
| 17 | 17 | |
| 18 | 18 | // Exercise linker with LLVM backend |
| 19 | elf_step.dependOn(testCommonSymbols(b, .{ .target = musl_target })); |
| 19 | 20 | elf_step.dependOn(testEmptyObject(b, .{ .target = musl_target })); |
| 20 | 21 | elf_step.dependOn(testGcSections(b, .{ .target = musl_target })); |
| 21 | 22 | elf_step.dependOn(testLinkingC(b, .{ .target = musl_target })); |
| ... | ... | @@ -24,12 +25,39 @@ pub fn build(b: *Build) void { |
| 24 | 25 | elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target })); |
| 25 | 26 | } |
| 26 | 27 | |
| 28 | fn testCommonSymbols(b: *Build, opts: Options) *Step { |
| 29 | const test_step = addTestStep(b, "common-symbols", opts); |
| 30 | |
| 31 | const exe = addExecutable(b, opts); |
| 32 | addCSourceBytes(exe, |
| 33 | \\int foo; |
| 34 | \\int bar; |
| 35 | \\int baz = 42; |
| 36 | , &.{"-fcommon"}); |
| 37 | addCSourceBytes(exe, |
| 38 | \\#include<stdio.h> |
| 39 | \\int foo; |
| 40 | \\int bar = 5; |
| 41 | \\int baz; |
| 42 | \\int main() { |
| 43 | \\ printf("%d %d %d\n", foo, bar, baz); |
| 44 | \\} |
| 45 | , &.{"-fcommon"}); |
| 46 | exe.is_linking_libc = true; |
| 47 | |
| 48 | const run = addRunArtifact(exe); |
| 49 | run.expectStdOutEqual("0 5 42\n"); |
| 50 | test_step.dependOn(&run.step); |
| 51 | |
| 52 | return test_step; |
| 53 | } |
| 54 | |
| 27 | 55 | fn testEmptyObject(b: *Build, opts: Options) *Step { |
| 28 | 56 | const test_step = addTestStep(b, "empty-object", opts); |
| 29 | 57 | |
| 30 | 58 | const exe = addExecutable(b, opts); |
| 31 | | addCSourceBytes(exe, "int main() { return 0; }"); |
| 32 | | addCSourceBytes(exe, ""); |
| 59 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 60 | addCSourceBytes(exe, "", &.{}); |
| 33 | 61 | exe.is_linking_libc = true; |
| 34 | 62 | |
| 35 | 63 | const run = addRunArtifact(exe); |
| ... | ... | @@ -58,7 +86,7 @@ fn testGcSections(b: *Build, opts: Options) *Step { |
| 58 | 86 | \\ printf("%d %d\n", live_var1, live_var2); |
| 59 | 87 | \\ live_fn2(); |
| 60 | 88 | \\} |
| 61 | | ); |
| 89 | , &.{}); |
| 62 | 90 | obj.link_function_sections = true; |
| 63 | 91 | obj.link_data_sections = true; |
| 64 | 92 | obj.is_linking_libc = true; |
| ... | ... | @@ -139,7 +167,7 @@ fn testLinkingC(b: *Build, opts: Options) *Step { |
| 139 | 167 | \\ printf("Hello World!\n"); |
| 140 | 168 | \\ return 0; |
| 141 | 169 | \\} |
| 142 | | ); |
| 170 | , &.{}); |
| 143 | 171 | exe.is_linking_libc = true; |
| 144 | 172 | |
| 145 | 173 | const run = addRunArtifact(exe); |
| ... | ... | @@ -168,7 +196,7 @@ fn testLinkingCpp(b: *Build, opts: Options) *Step { |
| 168 | 196 | \\ std::cout << "Hello World!" << std::endl; |
| 169 | 197 | \\ return 0; |
| 170 | 198 | \\} |
| 171 | | ); |
| 199 | , &.{}); |
| 172 | 200 | exe.is_linking_libc = true; |
| 173 | 201 | exe.is_linking_libcpp = true; |
| 174 | 202 | |
| ... | ... | @@ -231,7 +259,7 @@ fn testTlsStatic(b: *Build, opts: Options) *Step { |
| 231 | 259 | \\ printf("%d %d %c\n", a, b, c); |
| 232 | 260 | \\ return 0; |
| 233 | 261 | \\} |
| 234 | | ); |
| 262 | , &.{}); |
| 235 | 263 | exe.is_linking_libc = true; |
| 236 | 264 | |
| 237 | 265 | const run = addRunArtifact(exe); |
| ... | ... | @@ -297,16 +325,16 @@ fn addZigSourceBytes(comp: *Compile, comptime bytes: []const u8) void { |
| 297 | 325 | comp.root_src = file; |
| 298 | 326 | } |
| 299 | 327 | |
| 300 | | fn addCSourceBytes(comp: *Compile, comptime bytes: []const u8) void { |
| 328 | fn addCSourceBytes(comp: *Compile, comptime bytes: []const u8, flags: []const []const u8) void { |
| 301 | 329 | const b = comp.step.owner; |
| 302 | 330 | const file = WriteFile.create(b).add("a.c", bytes); |
| 303 | | comp.addCSourceFile(.{ .file = file, .flags = &.{} }); |
| 331 | comp.addCSourceFile(.{ .file = file, .flags = flags }); |
| 304 | 332 | } |
| 305 | 333 | |
| 306 | | fn addCppSourceBytes(comp: *Compile, comptime bytes: []const u8) void { |
| 334 | fn addCppSourceBytes(comp: *Compile, comptime bytes: []const u8, flags: []const []const u8) void { |
| 307 | 335 | const b = comp.step.owner; |
| 308 | 336 | const file = WriteFile.create(b).add("a.cpp", bytes); |
| 309 | | comp.addCSourceFile(.{ .file = file, .flags = &.{} }); |
| 337 | comp.addCSourceFile(.{ .file = file, .flags = flags }); |
| 310 | 338 | } |
| 311 | 339 | |
| 312 | 340 | fn addAsmSourceBytes(comp: *Compile, comptime bytes: []const u8) void { |