| ... | ... | @@ -21,6 +21,7 @@ pub fn build(b: *Build) void { |
| 21 | 21 | // elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false })); |
| 22 | 22 | |
| 23 | 23 | // Exercise linker with LLVM backend |
| 24 | // musl tests |
| 24 | 25 | elf_step.dependOn(testAbsSymbols(b, .{ .target = musl_target })); |
| 25 | 26 | elf_step.dependOn(testCommonSymbols(b, .{ .target = musl_target })); |
| 26 | 27 | elf_step.dependOn(testCommonSymbolsInArchive(b, .{ .target = musl_target })); |
| ... | ... | @@ -29,11 +30,17 @@ pub fn build(b: *Build) void { |
| 29 | 30 | elf_step.dependOn(testGcSections(b, .{ .target = musl_target })); |
| 30 | 31 | elf_step.dependOn(testImageBase(b, .{ .target = musl_target })); |
| 31 | 32 | elf_step.dependOn(testInitArrayOrder(b, .{ .target = musl_target })); |
| 33 | elf_step.dependOn(testLargeAlignmentExe(b, .{ .target = musl_target })); |
| 34 | // https://github.com/ziglang/zig/issues/17449 |
| 35 | // elf_step.dependOn(testLargeBss(b, .{ .target = musl_target })); |
| 32 | 36 | elf_step.dependOn(testLinkingC(b, .{ .target = musl_target })); |
| 33 | 37 | elf_step.dependOn(testLinkingCpp(b, .{ .target = musl_target })); |
| 34 | 38 | elf_step.dependOn(testLinkingZig(b, .{ .target = musl_target })); |
| 39 | // https://github.com/ziglang/zig/issues/17451 |
| 40 | // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = musl_target })); |
| 35 | 41 | elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target })); |
| 36 | 42 | |
| 43 | // glibc tests |
| 37 | 44 | elf_step.dependOn(testAsNeeded(b, .{ .target = glibc_target })); |
| 38 | 45 | // https://github.com/ziglang/zig/issues/17430 |
| 39 | 46 | // elf_step.dependOn(testCanonicalPlt(b, .{ .target = glibc_target })); |
| ... | ... | @@ -63,7 +70,13 @@ pub fn build(b: *Build) void { |
| 63 | 70 | elf_step.dependOn(testInitArrayOrder(b, .{ .target = glibc_target })); |
| 64 | 71 | elf_step.dependOn(testLargeAlignmentDso(b, .{ .target = glibc_target })); |
| 65 | 72 | elf_step.dependOn(testLargeAlignmentExe(b, .{ .target = glibc_target })); |
| 73 | elf_step.dependOn(testLargeBss(b, .{ .target = glibc_target })); |
| 74 | elf_step.dependOn(testLinkOrder(b, .{ .target = glibc_target })); |
| 75 | // https://github.com/ziglang/zig/issues/17451 |
| 76 | // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = glibc_target })); |
| 66 | 77 | elf_step.dependOn(testPie(b, .{ .target = glibc_target })); |
| 78 | elf_step.dependOn(testPltGot(b, .{ .target = glibc_target })); |
| 79 | elf_step.dependOn(testPreinitArray(b, .{ .target = glibc_target })); |
| 67 | 80 | } |
| 68 | 81 | |
| 69 | 82 | fn testAbsSymbols(b: *Build, opts: Options) *Step { |
| ... | ... | @@ -1353,6 +1366,85 @@ fn testLargeAlignmentExe(b: *Build, opts: Options) *Step { |
| 1353 | 1366 | return test_step; |
| 1354 | 1367 | } |
| 1355 | 1368 | |
| 1369 | fn testLargeBss(b: *Build, opts: Options) *Step { |
| 1370 | const test_step = addTestStep(b, "large-bss", opts); |
| 1371 | |
| 1372 | const exe = addExecutable(b, "main", opts); |
| 1373 | addCSourceBytes(exe, |
| 1374 | \\char arr[0x100000000]; |
| 1375 | \\int main() { |
| 1376 | \\ return arr[2000]; |
| 1377 | \\} |
| 1378 | , &.{}); |
| 1379 | exe.linkLibC(); |
| 1380 | |
| 1381 | const run = addRunArtifact(exe); |
| 1382 | test_step.dependOn(&run.step); |
| 1383 | |
| 1384 | return test_step; |
| 1385 | } |
| 1386 | |
| 1387 | fn testLinkOrder(b: *Build, opts: Options) *Step { |
| 1388 | const test_step = addTestStep(b, "link-order", opts); |
| 1389 | |
| 1390 | const obj = addObject(b, "obj", opts); |
| 1391 | addCSourceBytes(obj, "void foo() {}", &.{}); |
| 1392 | obj.force_pic = true; |
| 1393 | |
| 1394 | const dso = addSharedLibrary(b, "a", opts); |
| 1395 | dso.addObject(obj); |
| 1396 | |
| 1397 | const lib = addStaticLibrary(b, "b", opts); |
| 1398 | lib.addObject(obj); |
| 1399 | |
| 1400 | const main_o = addObject(b, "main", opts); |
| 1401 | addCSourceBytes(main_o, |
| 1402 | \\void foo(); |
| 1403 | \\int main() { |
| 1404 | \\ foo(); |
| 1405 | \\} |
| 1406 | , &.{}); |
| 1407 | |
| 1408 | // https://github.com/ziglang/zig/issues/17450 |
| 1409 | // { |
| 1410 | // const exe = addExecutable(b, "main1", opts); |
| 1411 | // exe.addObject(main_o); |
| 1412 | // exe.linkSystemLibrary2("a", .{}); |
| 1413 | // exe.addLibraryPath(dso.getEmittedBinDirectory()); |
| 1414 | // exe.addRPath(dso.getEmittedBinDirectory()); |
| 1415 | // exe.linkSystemLibrary2("b", .{}); |
| 1416 | // exe.addLibraryPath(lib.getEmittedBinDirectory()); |
| 1417 | // exe.addRPath(lib.getEmittedBinDirectory()); |
| 1418 | // exe.linkLibC(); |
| 1419 | // exe.verbose_link = true; |
| 1420 | |
| 1421 | // const check = exe.checkObject(); |
| 1422 | // check.checkInDynamicSection(); |
| 1423 | // check.checkContains("libb.so"); |
| 1424 | // test_step.dependOn(&check.step); |
| 1425 | // } |
| 1426 | |
| 1427 | { |
| 1428 | const exe = addExecutable(b, "main2", opts); |
| 1429 | exe.addObject(main_o); |
| 1430 | exe.linkSystemLibrary2("b", .{}); |
| 1431 | exe.addLibraryPath(lib.getEmittedBinDirectory()); |
| 1432 | exe.addRPath(lib.getEmittedBinDirectory()); |
| 1433 | exe.linkSystemLibrary2("a", .{}); |
| 1434 | exe.addLibraryPath(dso.getEmittedBinDirectory()); |
| 1435 | exe.addRPath(dso.getEmittedBinDirectory()); |
| 1436 | exe.linkLibC(); |
| 1437 | exe.verbose_link = true; |
| 1438 | |
| 1439 | const check = exe.checkObject(); |
| 1440 | check.checkInDynamicSection(); |
| 1441 | check.checkNotPresent("libb.so"); |
| 1442 | test_step.dependOn(&check.step); |
| 1443 | } |
| 1444 | |
| 1445 | return test_step; |
| 1446 | } |
| 1447 | |
| 1356 | 1448 | fn testLinkingC(b: *Build, opts: Options) *Step { |
| 1357 | 1449 | const test_step = addTestStep(b, "linking-c", opts); |
| 1358 | 1450 | |
| ... | ... | @@ -1438,6 +1530,23 @@ fn testLinkingZig(b: *Build, opts: Options) *Step { |
| 1438 | 1530 | return test_step; |
| 1439 | 1531 | } |
| 1440 | 1532 | |
| 1533 | fn testNoEhFrameHdr(b: *Build, opts: Options) *Step { |
| 1534 | const test_step = addTestStep(b, "no-eh-frame-hdr", opts); |
| 1535 | |
| 1536 | const exe = addExecutable(b, "main", opts); |
| 1537 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 1538 | exe.link_eh_frame_hdr = false; |
| 1539 | exe.linkLibC(); |
| 1540 | |
| 1541 | const check = exe.checkObject(); |
| 1542 | check.checkStart(); |
| 1543 | check.checkExact("section headers"); |
| 1544 | check.checkNotPresent("name .eh_frame_hdr"); |
| 1545 | test_step.dependOn(&check.step); |
| 1546 | |
| 1547 | return test_step; |
| 1548 | } |
| 1549 | |
| 1441 | 1550 | fn testPie(b: *Build, opts: Options) *Step { |
| 1442 | 1551 | const test_step = addTestStep(b, "hello-pie", opts); |
| 1443 | 1552 | |
| ... | ... | @@ -1469,6 +1578,70 @@ fn testPie(b: *Build, opts: Options) *Step { |
| 1469 | 1578 | return test_step; |
| 1470 | 1579 | } |
| 1471 | 1580 | |
| 1581 | fn testPltGot(b: *Build, opts: Options) *Step { |
| 1582 | const test_step = addTestStep(b, "plt-got", opts); |
| 1583 | |
| 1584 | const dso = addSharedLibrary(b, "a", opts); |
| 1585 | addCSourceBytes(dso, |
| 1586 | \\#include <stdio.h> |
| 1587 | \\void ignore(void *foo) {} |
| 1588 | \\void hello() { |
| 1589 | \\ printf("Hello world\n"); |
| 1590 | \\} |
| 1591 | , &.{}); |
| 1592 | dso.linkLibC(); |
| 1593 | |
| 1594 | const exe = addExecutable(b, "main", opts); |
| 1595 | addCSourceBytes(exe, |
| 1596 | \\void ignore(void *); |
| 1597 | \\int hello(); |
| 1598 | \\void foo() { ignore(hello); } |
| 1599 | \\int main() { hello(); } |
| 1600 | , &.{}); |
| 1601 | exe.linkLibrary(dso); |
| 1602 | exe.force_pic = true; |
| 1603 | exe.linkLibC(); |
| 1604 | |
| 1605 | const run = addRunArtifact(exe); |
| 1606 | run.expectStdOutEqual("Hello world\n"); |
| 1607 | test_step.dependOn(&run.step); |
| 1608 | |
| 1609 | return test_step; |
| 1610 | } |
| 1611 | |
| 1612 | fn testPreinitArray(b: *Build, opts: Options) *Step { |
| 1613 | const test_step = addTestStep(b, "preinit-array", opts); |
| 1614 | |
| 1615 | { |
| 1616 | const obj = addObject(b, "obj", opts); |
| 1617 | addCSourceBytes(obj, "void _start() {}", &.{}); |
| 1618 | |
| 1619 | const exe = addExecutable(b, "main1", opts); |
| 1620 | exe.addObject(obj); |
| 1621 | |
| 1622 | const check = exe.checkObject(); |
| 1623 | check.checkInDynamicSection(); |
| 1624 | check.checkNotPresent("PREINIT_ARRAY"); |
| 1625 | } |
| 1626 | |
| 1627 | { |
| 1628 | const exe = addExecutable(b, "main2", opts); |
| 1629 | addCSourceBytes(exe, |
| 1630 | \\void preinit_fn() {} |
| 1631 | \\int main() {} |
| 1632 | \\__attribute__((section(".preinit_array"))) |
| 1633 | \\void *preinit[] = { preinit_fn }; |
| 1634 | , &.{}); |
| 1635 | exe.linkLibC(); |
| 1636 | |
| 1637 | const check = exe.checkObject(); |
| 1638 | check.checkInDynamicSection(); |
| 1639 | check.checkContains("PREINIT_ARRAY"); |
| 1640 | } |
| 1641 | |
| 1642 | return test_step; |
| 1643 | } |
| 1644 | |
| 1472 | 1645 | fn testTlsStatic(b: *Build, opts: Options) *Step { |
| 1473 | 1646 | const test_step = addTestStep(b, "tls-static", opts); |
| 1474 | 1647 | |