| ... | ... | @@ -72,6 +72,8 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 72 | 72 | elf_step.dependOn(testLinkingC(b, .{ .target = musl_target })); |
| 73 | 73 | elf_step.dependOn(testLinkingCpp(b, .{ .target = musl_target })); |
| 74 | 74 | elf_step.dependOn(testLinkingZig(b, .{ .target = musl_target })); |
| 75 | elf_step.dependOn(testMergeStrings(b, .{ .target = musl_target })); |
| 76 | elf_step.dependOn(testMergeStrings2(b, .{ .target = musl_target })); |
| 75 | 77 | // https://github.com/ziglang/zig/issues/17451 |
| 76 | 78 | // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = musl_target })); |
| 77 | 79 | elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target })); |
| ... | ... | @@ -2267,6 +2269,100 @@ fn testLinkingZig(b: *Build, opts: Options) *Step { |
| 2267 | 2269 | return test_step; |
| 2268 | 2270 | } |
| 2269 | 2271 | |
| 2272 | // Adapted from https://github.com/rui314/mold/blob/main/test/elf/mergeable-strings.sh |
| 2273 | fn testMergeStrings(b: *Build, opts: Options) *Step { |
| 2274 | const test_step = addTestStep(b, "merge-strings", opts); |
| 2275 | |
| 2276 | const obj1 = addObject(b, opts, .{ .name = "a.o" }); |
| 2277 | addCSourceBytes(obj1, |
| 2278 | \\#include <uchar.h> |
| 2279 | \\#include <wchar.h> |
| 2280 | \\char *cstr1 = "foo"; |
| 2281 | \\wchar_t *wide1 = L"foo"; |
| 2282 | \\char16_t *utf16_1 = u"foo"; |
| 2283 | \\char32_t *utf32_1 = U"foo"; |
| 2284 | , &.{"-O2"}); |
| 2285 | obj1.linkLibC(); |
| 2286 | |
| 2287 | const obj2 = addObject(b, opts, .{ .name = "b.o" }); |
| 2288 | addCSourceBytes(obj2, |
| 2289 | \\#include <stdio.h> |
| 2290 | \\#include <assert.h> |
| 2291 | \\#include <uchar.h> |
| 2292 | \\#include <wchar.h> |
| 2293 | \\extern char *cstr1; |
| 2294 | \\extern wchar_t *wide1; |
| 2295 | \\extern char16_t *utf16_1; |
| 2296 | \\extern char32_t *utf32_1; |
| 2297 | \\char *cstr2 = "foo"; |
| 2298 | \\wchar_t *wide2 = L"foo"; |
| 2299 | \\char16_t *utf16_2 = u"foo"; |
| 2300 | \\char32_t *utf32_2 = U"foo"; |
| 2301 | \\int main() { |
| 2302 | \\ printf("%p %p %p %p %p %p %p %p\n", |
| 2303 | \\ cstr1, cstr2, wide1, wide2, utf16_1, utf16_2, utf32_1, utf32_2); |
| 2304 | \\ assert((void*)cstr1 == (void*)cstr2); |
| 2305 | \\ assert((void*)wide1 == (void*)wide2); |
| 2306 | \\ assert((void*)utf16_1 == (void*)utf16_2); |
| 2307 | \\ assert((void*)utf32_1 == (void*)utf32_2); |
| 2308 | \\ assert((void*)wide1 == (void*)utf32_1); |
| 2309 | \\ assert((void*)cstr1 != (void*)wide1); |
| 2310 | \\ assert((void*)cstr1 != (void*)utf32_1); |
| 2311 | \\ assert((void*)wide1 != (void*)utf16_1); |
| 2312 | \\} |
| 2313 | , &.{"-O2"}); |
| 2314 | obj2.linkLibC(); |
| 2315 | |
| 2316 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 2317 | exe.addObject(obj1); |
| 2318 | exe.addObject(obj2); |
| 2319 | exe.linkLibC(); |
| 2320 | |
| 2321 | const run = addRunArtifact(exe); |
| 2322 | run.expectExitCode(0); |
| 2323 | test_step.dependOn(&run.step); |
| 2324 | |
| 2325 | return test_step; |
| 2326 | } |
| 2327 | |
| 2328 | fn testMergeStrings2(b: *Build, opts: Options) *Step { |
| 2329 | const test_step = addTestStep(b, "merge-strings2", opts); |
| 2330 | |
| 2331 | const obj1 = addObject(b, opts, .{ .name = "a.o", .zig_source_bytes = |
| 2332 | \\const std = @import("std"); |
| 2333 | \\export fn foo() void { |
| 2334 | \\ var arr: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 }; |
| 2335 | \\ const slice = std.mem.sliceTo(&arr, 3); |
| 2336 | \\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable; |
| 2337 | \\} |
| 2338 | }); |
| 2339 | |
| 2340 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = |
| 2341 | \\const std = @import("std"); |
| 2342 | \\extern fn foo() void; |
| 2343 | \\pub fn main() void { |
| 2344 | \\ foo(); |
| 2345 | \\ var arr: [5:0]u16 = [_:0]u16{ 5, 4, 3, 2, 1 }; |
| 2346 | \\ const slice = std.mem.sliceTo(&arr, 3); |
| 2347 | \\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable; |
| 2348 | \\} |
| 2349 | }); |
| 2350 | exe.addObject(obj1); |
| 2351 | |
| 2352 | const run = addRunArtifact(exe); |
| 2353 | run.expectExitCode(0); |
| 2354 | test_step.dependOn(&run.step); |
| 2355 | |
| 2356 | const check = exe.checkObject(); |
| 2357 | check.dumpSection(".rodata.str"); |
| 2358 | check.checkContains("\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x00\x00"); |
| 2359 | check.dumpSection(".rodata.str"); |
| 2360 | check.checkContains("\x05\x00\x04\x00\x03\x00\x02\x00\x01\x00\x00\x00"); |
| 2361 | test_step.dependOn(&check.step); |
| 2362 | |
| 2363 | return test_step; |
| 2364 | } |
| 2365 | |
| 2270 | 2366 | fn testNoEhFrameHdr(b: *Build, opts: Options) *Step { |
| 2271 | 2367 | const test_step = addTestStep(b, "no-eh-frame-hdr", opts); |
| 2272 | 2368 | |