| ... | @@ -11,6 +11,11 @@ pub fn build(b: *Build) void { | ... | @@ -11,6 +11,11 @@ pub fn build(b: *Build) void { |
| 11 | .os_tag = .linux, | 11 | .os_tag = .linux, |
| 12 | .abi = .musl, | 12 | .abi = .musl, |
| 13 | }; | 13 | }; |
| | 14 | const glibc_target = CrossTarget{ |
| | 15 | .cpu_arch = .x86_64, |
| | 16 | .os_tag = .linux, |
| | 17 | .abi = .gnu, |
| | 18 | }; |
| 14 | | 19 | |
| 15 | // Exercise linker with self-hosted backend (no LLVM) | 20 | // Exercise linker with self-hosted backend (no LLVM) |
| 16 | // elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false })); | 21 | // elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false })); |
| ... | @@ -24,6 +29,10 @@ pub fn build(b: *Build) void { | ... | @@ -24,6 +29,10 @@ pub fn build(b: *Build) void { |
| 24 | elf_step.dependOn(testLinkingCpp(b, .{ .target = musl_target })); | 29 | elf_step.dependOn(testLinkingCpp(b, .{ .target = musl_target })); |
| 25 | elf_step.dependOn(testLinkingZig(b, .{ .target = musl_target })); | 30 | elf_step.dependOn(testLinkingZig(b, .{ .target = musl_target })); |
| 26 | elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target })); | 31 | elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target })); |
| | 32 | |
| | 33 | for (&[_]CrossTarget{ glibc_target, musl_target }) |target| { |
| | 34 | elf_step.dependOn(testDsoPlt(b, .{ .target = target })); |
| | 35 | } |
| 27 | } | 36 | } |
| 28 | | 37 | |
| 29 | fn testCommonSymbols(b: *Build, opts: Options) *Step { | 38 | fn testCommonSymbols(b: *Build, opts: Options) *Step { |
| ... | @@ -122,6 +131,46 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { | ... | @@ -122,6 +131,46 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { |
| 122 | return test_step; | 131 | return test_step; |
| 123 | } | 132 | } |
| 124 | | 133 | |
| | 134 | fn testDsoPlt(b: *Build, opts: Options) *Step { |
| | 135 | const test_step = addTestStep(b, "dso-plt", opts); |
| | 136 | |
| | 137 | const dso = addSharedLibrary(b, opts); |
| | 138 | addCSourceBytes(dso, |
| | 139 | \\#include<stdio.h> |
| | 140 | \\void world() { |
| | 141 | \\ printf("world\n"); |
| | 142 | \\} |
| | 143 | \\void real_hello() { |
| | 144 | \\ printf("Hello "); |
| | 145 | \\ world(); |
| | 146 | \\} |
| | 147 | \\void hello() { |
| | 148 | \\ real_hello(); |
| | 149 | \\} |
| | 150 | , &.{"-fPIC"}); |
| | 151 | dso.is_linking_libc = true; |
| | 152 | |
| | 153 | const exe = addExecutable(b, opts); |
| | 154 | addCSourceBytes(exe, |
| | 155 | \\#include<stdio.h> |
| | 156 | \\void world() { |
| | 157 | \\ printf("WORLD\n"); |
| | 158 | \\} |
| | 159 | \\void hello(); |
| | 160 | \\int main() { |
| | 161 | \\ hello(); |
| | 162 | \\} |
| | 163 | , &.{}); |
| | 164 | exe.linkLibrary(dso); |
| | 165 | exe.is_linking_libc = true; |
| | 166 | |
| | 167 | const run = addRunArtifact(exe); |
| | 168 | run.expectStdOutEqual("Hello WORLD\n"); |
| | 169 | test_step.dependOn(&run.step); |
| | 170 | |
| | 171 | return test_step; |
| | 172 | } |
| | 173 | |
| 125 | fn testEmptyObject(b: *Build, opts: Options) *Step { | 174 | fn testEmptyObject(b: *Build, opts: Options) *Step { |
| 126 | const test_step = addTestStep(b, "empty-object", opts); | 175 | const test_step = addTestStep(b, "empty-object", opts); |
| 127 | | 176 | |
| ... | @@ -391,6 +440,16 @@ fn addStaticLibrary(b: *Build, opts: Options) *Compile { | ... | @@ -391,6 +440,16 @@ fn addStaticLibrary(b: *Build, opts: Options) *Compile { |
| 391 | }); | 440 | }); |
| 392 | } | 441 | } |
| 393 | | 442 | |
| | 443 | fn addSharedLibrary(b: *Build, opts: Options) *Compile { |
| | 444 | return b.addSharedLibrary(.{ |
| | 445 | .name = "a.so", |
| | 446 | .target = opts.target, |
| | 447 | .optimize = opts.optimize, |
| | 448 | .use_llvm = opts.use_llvm, |
| | 449 | .use_lld = false, |
| | 450 | }); |
| | 451 | } |
| | 452 | |
| 394 | fn addRunArtifact(comp: *Compile) *Run { | 453 | fn addRunArtifact(comp: *Compile) *Run { |
| 395 | const b = comp.step.owner; | 454 | const b = comp.step.owner; |
| 396 | const run = b.addRunArtifact(comp); | 455 | const run = b.addRunArtifact(comp); |