| ... | ... | @@ -539,6 +539,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 539 | 539 | |
| 540 | 540 | const fn_inclusions_len = try inc_reader.readInt(u16, .little); |
| 541 | 541 | |
| 542 | // Pick the default symbol version: |
| 543 | // - If there are no versions, don't emit it |
| 544 | // - Take the greatest one <= than the target one |
| 545 | // - If none of them is <= than the |
| 546 | // specified one don't pick any default version |
| 547 | var chosen_def_ver_index: usize = 255; |
| 548 | var chosen_unversioned_ver_index: usize = 255; |
| 549 | |
| 542 | 550 | while (sym_i < fn_inclusions_len) : (sym_i += 1) { |
| 543 | 551 | const sym_name = opt_symbol_name orelse n: { |
| 544 | 552 | sym_name_buf.clearRetainingCapacity(); |
| ... | ... | @@ -547,17 +555,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 547 | 555 | opt_symbol_name = sym_name_buf.items; |
| 548 | 556 | versions.unsetAll(); |
| 549 | 557 | weak_linkages.unsetAll(); |
| 558 | chosen_def_ver_index = 255; |
| 559 | chosen_unversioned_ver_index = 255; |
| 550 | 560 | |
| 551 | 561 | break :n sym_name_buf.items; |
| 552 | 562 | }; |
| 553 | | |
| 554 | | // Pick the default symbol version: |
| 555 | | // - If there are no versions, don't emit it |
| 556 | | // - Take the greatest one <= than the target one |
| 557 | | // - If none of them is <= than the |
| 558 | | // specified one don't pick any default version |
| 559 | | var chosen_def_ver_index: usize = 255; |
| 560 | | var chosen_unversioned_ver_index: usize = 255; |
| 561 | 563 | { |
| 562 | 564 | const targets = try std.leb.readUleb128(u64, inc_reader); |
| 563 | 565 | var lib_index = try inc_reader.readByte(); |
| ... | ... | @@ -578,14 +580,19 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 578 | 580 | const last = (byte & 0b1000_0000) != 0; |
| 579 | 581 | const ver_i = @as(u7, @truncate(byte)); |
| 580 | 582 | if (ok_lib_and_target and ver_i <= target_ver_index) { |
| 581 | | versions.set(ver_i); |
| 582 | | if (chosen_def_ver_index == 255 or ver_i > chosen_def_ver_index) { |
| 583 | | chosen_def_ver_index = ver_i; |
| 583 | if (is_unversioned) { |
| 584 | if (chosen_unversioned_ver_index == 255 or ver_i > chosen_unversioned_ver_index) { |
| 585 | chosen_unversioned_ver_index = ver_i; |
| 586 | } |
| 587 | } else { |
| 588 | if (chosen_def_ver_index == 255 or ver_i > chosen_def_ver_index) { |
| 589 | chosen_def_ver_index = ver_i; |
| 590 | } |
| 591 | |
| 592 | versions.set(ver_i); |
| 584 | 593 | } |
| 585 | | if (is_unversioned and (chosen_unversioned_ver_index == 255 or ver_i > chosen_unversioned_ver_index)) { |
| 586 | | chosen_unversioned_ver_index = ver_i; |
| 587 | | } |
| 588 | | if (is_weak) weak_linkages.set(ver_i); |
| 594 | |
| 595 | weak_linkages.setValue(ver_i, is_weak); |
| 589 | 596 | } |
| 590 | 597 | if (last) break; |
| 591 | 598 | } |
| ... | ... | @@ -595,31 +602,31 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 595 | 602 | } else continue; |
| 596 | 603 | } |
| 597 | 604 | |
| 605 | if (chosen_unversioned_ver_index != 255) { |
| 606 | // Example: |
| 607 | // .balign 4 |
| 608 | // .globl _Exit |
| 609 | // .type _Exit, %function |
| 610 | // _Exit: .long 0 |
| 611 | try stubs_writer.print( |
| 612 | \\.balign {d} |
| 613 | \\.{s} {s} |
| 614 | \\.type {s}, %function |
| 615 | \\{s}: {s} 0 |
| 616 | \\ |
| 617 | , .{ |
| 618 | target.ptrBitWidth() / 8, |
| 619 | if (weak_linkages.isSet(chosen_unversioned_ver_index)) "weak" else "globl", |
| 620 | sym_name, |
| 621 | sym_name, |
| 622 | sym_name, |
| 623 | wordDirective(target), |
| 624 | }); |
| 625 | } |
| 626 | |
| 598 | 627 | { |
| 599 | 628 | var versions_iter = versions.iterator(.{}); |
| 600 | 629 | while (versions_iter.next()) |ver_index| { |
| 601 | | if (chosen_unversioned_ver_index != 255 and ver_index == chosen_unversioned_ver_index) { |
| 602 | | // Example: |
| 603 | | // .balign 4 |
| 604 | | // .globl _Exit |
| 605 | | // .type _Exit, %function |
| 606 | | // _Exit: .long 0 |
| 607 | | try stubs_writer.print( |
| 608 | | \\.balign {d} |
| 609 | | \\.{s} {s} |
| 610 | | \\.type {s}, %function |
| 611 | | \\{s}: {s} 0 |
| 612 | | \\ |
| 613 | | , .{ |
| 614 | | target.ptrBitWidth() / 8, |
| 615 | | if (weak_linkages.isSet(ver_index)) "weak" else "globl", |
| 616 | | sym_name, |
| 617 | | sym_name, |
| 618 | | sym_name, |
| 619 | | wordDirective(target), |
| 620 | | }); |
| 621 | | } |
| 622 | | |
| 623 | 630 | // Example: |
| 624 | 631 | // .balign 4 |
| 625 | 632 | // .globl _Exit_1_0 |
| ... | ... | @@ -627,10 +634,6 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 627 | 634 | // .symver _Exit_1_0, _Exit@@FBSD_1.0, remove |
| 628 | 635 | // _Exit_1_0: .long 0 |
| 629 | 636 | const ver = metadata.all_versions[ver_index]; |
| 630 | | |
| 631 | | // Default symbol version definition vs normal symbol version definition |
| 632 | | const want_default = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index; |
| 633 | | const at_sign_str: []const u8 = if (want_default) "@@" else "@"; |
| 634 | 637 | const sym_plus_ver = try std.fmt.allocPrint( |
| 635 | 638 | arena, |
| 636 | 639 | "{s}_FBSD_{d}_{d}", |
| ... | ... | @@ -651,7 +654,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 651 | 654 | sym_plus_ver, |
| 652 | 655 | sym_plus_ver, |
| 653 | 656 | sym_name, |
| 654 | | at_sign_str, |
| 657 | // Default symbol version definition vs normal symbol version definition |
| 658 | if (chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index) "@@" else "@", |
| 655 | 659 | ver.major, |
| 656 | 660 | ver.minor, |
| 657 | 661 | sym_plus_ver, |
| ... | ... | @@ -688,6 +692,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 688 | 692 | |
| 689 | 693 | sym_i = 0; |
| 690 | 694 | opt_symbol_name = null; |
| 695 | |
| 691 | 696 | while (sym_i < obj_inclusions_len) : (sym_i += 1) { |
| 692 | 697 | const sym_name = opt_symbol_name orelse n: { |
| 693 | 698 | sym_name_buf.clearRetainingCapacity(); |
| ... | ... | @@ -696,17 +701,12 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 696 | 701 | opt_symbol_name = sym_name_buf.items; |
| 697 | 702 | versions.unsetAll(); |
| 698 | 703 | weak_linkages.unsetAll(); |
| 704 | chosen_def_ver_index = 255; |
| 705 | chosen_unversioned_ver_index = 255; |
| 699 | 706 | |
| 700 | 707 | break :n sym_name_buf.items; |
| 701 | 708 | }; |
| 702 | 709 | |
| 703 | | // Pick the default symbol version: |
| 704 | | // - If there are no versions, don't emit it |
| 705 | | // - Take the greatest one <= than the target one |
| 706 | | // - If none of them is <= than the |
| 707 | | // specified one don't pick any default version |
| 708 | | var chosen_def_ver_index: usize = 255; |
| 709 | | var chosen_unversioned_ver_index: usize = 255; |
| 710 | 710 | { |
| 711 | 711 | const targets = try std.leb.readUleb128(u64, inc_reader); |
| 712 | 712 | const size = try std.leb.readUleb128(u16, inc_reader); |
| ... | ... | @@ -728,15 +728,20 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 728 | 728 | const last = (byte & 0b1000_0000) != 0; |
| 729 | 729 | const ver_i = @as(u7, @truncate(byte)); |
| 730 | 730 | if (ok_lib_and_target and ver_i <= target_ver_index) { |
| 731 | | versions.set(ver_i); |
| 732 | | if (chosen_def_ver_index == 255 or ver_i > chosen_def_ver_index) { |
| 733 | | chosen_def_ver_index = ver_i; |
| 734 | | } |
| 735 | | if (is_unversioned and (chosen_unversioned_ver_index == 255 or ver_i > chosen_unversioned_ver_index)) { |
| 736 | | chosen_unversioned_ver_index = ver_i; |
| 731 | if (is_unversioned) { |
| 732 | if (chosen_unversioned_ver_index == 255 or ver_i > chosen_unversioned_ver_index) { |
| 733 | chosen_unversioned_ver_index = ver_i; |
| 734 | } |
| 735 | } else { |
| 736 | if (chosen_def_ver_index == 255 or ver_i > chosen_def_ver_index) { |
| 737 | chosen_def_ver_index = ver_i; |
| 738 | } |
| 739 | |
| 740 | versions.set(ver_i); |
| 737 | 741 | } |
| 742 | |
| 738 | 743 | sizes[ver_i] = size; |
| 739 | | if (is_weak) weak_linkages.set(ver_i); |
| 744 | weak_linkages.setValue(ver_i, is_weak); |
| 740 | 745 | } |
| 741 | 746 | if (last) break; |
| 742 | 747 | } |
| ... | ... | @@ -746,35 +751,35 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 746 | 751 | } else continue; |
| 747 | 752 | } |
| 748 | 753 | |
| 754 | if (chosen_unversioned_ver_index != 255) { |
| 755 | // Example: |
| 756 | // .balign 4 |
| 757 | // .globl malloc_conf |
| 758 | // .type malloc_conf, %object |
| 759 | // .size malloc_conf, 4 |
| 760 | // malloc_conf: .fill 4, 1, 0 |
| 761 | try stubs_writer.print( |
| 762 | \\.balign {d} |
| 763 | \\.{s} {s} |
| 764 | \\.type {s}, %object |
| 765 | \\.size {s}, {d} |
| 766 | \\{s}: {s} 0 |
| 767 | \\ |
| 768 | , .{ |
| 769 | target.ptrBitWidth() / 8, |
| 770 | if (weak_linkages.isSet(chosen_unversioned_ver_index)) "weak" else "globl", |
| 771 | sym_name, |
| 772 | sym_name, |
| 773 | sym_name, |
| 774 | sizes[chosen_unversioned_ver_index], |
| 775 | sym_name, |
| 776 | wordDirective(target), |
| 777 | }); |
| 778 | } |
| 779 | |
| 749 | 780 | { |
| 750 | 781 | var versions_iter = versions.iterator(.{}); |
| 751 | 782 | while (versions_iter.next()) |ver_index| { |
| 752 | | if (chosen_unversioned_ver_index != 255 and ver_index == chosen_unversioned_ver_index) { |
| 753 | | // Example: |
| 754 | | // .balign 4 |
| 755 | | // .globl malloc_conf |
| 756 | | // .type malloc_conf, %object |
| 757 | | // .size malloc_conf, 4 |
| 758 | | // malloc_conf: .fill 4, 1, 0 |
| 759 | | try stubs_writer.print( |
| 760 | | \\.balign {d} |
| 761 | | \\.{s} {s} |
| 762 | | \\.type {s}, %object |
| 763 | | \\.size {s}, {d} |
| 764 | | \\{s}: {s} 0 |
| 765 | | \\ |
| 766 | | , .{ |
| 767 | | target.ptrBitWidth() / 8, |
| 768 | | if (weak_linkages.isSet(ver_index)) "weak" else "globl", |
| 769 | | sym_name, |
| 770 | | sym_name, |
| 771 | | sym_name, |
| 772 | | sizes[ver_index], |
| 773 | | sym_name, |
| 774 | | wordDirective(target), |
| 775 | | }); |
| 776 | | } |
| 777 | | |
| 778 | 783 | // Example: |
| 779 | 784 | // .balign 4 |
| 780 | 785 | // .globl malloc_conf_1_3 |
| ... | ... | @@ -783,10 +788,6 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 783 | 788 | // .symver malloc_conf_1_3, malloc_conf@@FBSD_1.3 |
| 784 | 789 | // malloc_conf_1_3: .fill 4, 1, 0 |
| 785 | 790 | const ver = metadata.all_versions[ver_index]; |
| 786 | | |
| 787 | | // Default symbol version definition vs normal symbol version definition |
| 788 | | const want_default = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index; |
| 789 | | const at_sign_str: []const u8 = if (want_default) "@@" else "@"; |
| 790 | 791 | const sym_plus_ver = try std.fmt.allocPrint( |
| 791 | 792 | arena, |
| 792 | 793 | "{s}_FBSD_{d}_{d}", |
| ... | ... | @@ -810,7 +811,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 810 | 811 | sizes[ver_index], |
| 811 | 812 | sym_plus_ver, |
| 812 | 813 | sym_name, |
| 813 | | at_sign_str, |
| 814 | // Default symbol version definition vs normal symbol version definition |
| 815 | if (chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index) "@@" else "@", |
| 814 | 816 | ver.major, |
| 815 | 817 | ver.minor, |
| 816 | 818 | sym_plus_ver, |
| ... | ... | @@ -826,6 +828,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 826 | 828 | |
| 827 | 829 | sym_i = 0; |
| 828 | 830 | opt_symbol_name = null; |
| 831 | |
| 829 | 832 | while (sym_i < tls_inclusions_len) : (sym_i += 1) { |
| 830 | 833 | const sym_name = opt_symbol_name orelse n: { |
| 831 | 834 | sym_name_buf.clearRetainingCapacity(); |
| ... | ... | @@ -834,17 +837,12 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 834 | 837 | opt_symbol_name = sym_name_buf.items; |
| 835 | 838 | versions.unsetAll(); |
| 836 | 839 | weak_linkages.unsetAll(); |
| 840 | chosen_def_ver_index = 255; |
| 841 | chosen_unversioned_ver_index = 255; |
| 837 | 842 | |
| 838 | 843 | break :n sym_name_buf.items; |
| 839 | 844 | }; |
| 840 | 845 | |
| 841 | | // Pick the default symbol version: |
| 842 | | // - If there are no versions, don't emit it |
| 843 | | // - Take the greatest one <= than the target one |
| 844 | | // - If none of them is <= than the |
| 845 | | // specified one don't pick any default version |
| 846 | | var chosen_def_ver_index: usize = 255; |
| 847 | | var chosen_unversioned_ver_index: usize = 255; |
| 848 | 846 | { |
| 849 | 847 | const targets = try std.leb.readUleb128(u64, inc_reader); |
| 850 | 848 | const size = try std.leb.readUleb128(u16, inc_reader); |
| ... | ... | @@ -866,15 +864,20 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 866 | 864 | const last = (byte & 0b1000_0000) != 0; |
| 867 | 865 | const ver_i = @as(u7, @truncate(byte)); |
| 868 | 866 | if (ok_lib_and_target and ver_i <= target_ver_index) { |
| 869 | | versions.set(ver_i); |
| 870 | | if (chosen_def_ver_index == 255 or ver_i > chosen_def_ver_index) { |
| 871 | | chosen_def_ver_index = ver_i; |
| 872 | | } |
| 873 | | if (is_unversioned and (chosen_unversioned_ver_index == 255 or ver_i > chosen_unversioned_ver_index)) { |
| 874 | | chosen_unversioned_ver_index = ver_i; |
| 867 | if (is_unversioned) { |
| 868 | if (chosen_unversioned_ver_index == 255 or ver_i > chosen_unversioned_ver_index) { |
| 869 | chosen_unversioned_ver_index = ver_i; |
| 870 | } |
| 871 | } else { |
| 872 | if (chosen_def_ver_index == 255 or ver_i > chosen_def_ver_index) { |
| 873 | chosen_def_ver_index = ver_i; |
| 874 | } |
| 875 | |
| 876 | versions.set(ver_i); |
| 875 | 877 | } |
| 878 | |
| 876 | 879 | sizes[ver_i] = size; |
| 877 | | if (is_weak) weak_linkages.set(ver_i); |
| 880 | weak_linkages.setValue(ver_i, is_weak); |
| 878 | 881 | } |
| 879 | 882 | if (last) break; |
| 880 | 883 | } |
| ... | ... | @@ -884,35 +887,35 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 884 | 887 | } else continue; |
| 885 | 888 | } |
| 886 | 889 | |
| 890 | if (chosen_unversioned_ver_index != 255) { |
| 891 | // Example: |
| 892 | // .balign 4 |
| 893 | // .globl _ThreadRuneLocale |
| 894 | // .type _ThreadRuneLocale, %object |
| 895 | // .size _ThreadRuneLocale, 4 |
| 896 | // _ThreadRuneLocale: .fill 4, 1, 0 |
| 897 | try stubs_writer.print( |
| 898 | \\.balign {d} |
| 899 | \\.{s} {s} |
| 900 | \\.type {s}, %tls_object |
| 901 | \\.size {s}, {d} |
| 902 | \\{s}: {s} 0 |
| 903 | \\ |
| 904 | , .{ |
| 905 | target.ptrBitWidth() / 8, |
| 906 | if (weak_linkages.isSet(chosen_unversioned_ver_index)) "weak" else "globl", |
| 907 | sym_name, |
| 908 | sym_name, |
| 909 | sym_name, |
| 910 | sizes[chosen_unversioned_ver_index], |
| 911 | sym_name, |
| 912 | wordDirective(target), |
| 913 | }); |
| 914 | } |
| 915 | |
| 887 | 916 | { |
| 888 | 917 | var versions_iter = versions.iterator(.{}); |
| 889 | 918 | while (versions_iter.next()) |ver_index| { |
| 890 | | if (chosen_unversioned_ver_index != 255 and ver_index == chosen_unversioned_ver_index) { |
| 891 | | // Example: |
| 892 | | // .balign 4 |
| 893 | | // .globl _ThreadRuneLocale |
| 894 | | // .type _ThreadRuneLocale, %object |
| 895 | | // .size _ThreadRuneLocale, 4 |
| 896 | | // _ThreadRuneLocale: .fill 4, 1, 0 |
| 897 | | try stubs_writer.print( |
| 898 | | \\.balign {d} |
| 899 | | \\.{s} {s} |
| 900 | | \\.type {s}, %tls_object |
| 901 | | \\.size {s}, {d} |
| 902 | | \\{s}: {s} 0 |
| 903 | | \\ |
| 904 | | , .{ |
| 905 | | target.ptrBitWidth() / 8, |
| 906 | | if (weak_linkages.isSet(ver_index)) "weak" else "globl", |
| 907 | | sym_name, |
| 908 | | sym_name, |
| 909 | | sym_name, |
| 910 | | sizes[ver_index], |
| 911 | | sym_name, |
| 912 | | wordDirective(target), |
| 913 | | }); |
| 914 | | } |
| 915 | | |
| 916 | 919 | // Example: |
| 917 | 920 | // .balign 4 |
| 918 | 921 | // .globl _ThreadRuneLocale_1_3 |
| ... | ... | @@ -921,10 +924,6 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 921 | 924 | // .symver _ThreadRuneLocale_1_3, _ThreadRuneLocale@@FBSD_1.3 |
| 922 | 925 | // _ThreadRuneLocale_1_3: .fill 4, 1, 0 |
| 923 | 926 | const ver = metadata.all_versions[ver_index]; |
| 924 | | |
| 925 | | // Default symbol version definition vs normal symbol version definition |
| 926 | | const want_default = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index; |
| 927 | | const at_sign_str: []const u8 = if (want_default) "@@" else "@"; |
| 928 | 927 | const sym_plus_ver = try std.fmt.allocPrint( |
| 929 | 928 | arena, |
| 930 | 929 | "{s}_FBSD_{d}_{d}", |
| ... | ... | @@ -948,7 +947,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 948 | 947 | sizes[ver_index], |
| 949 | 948 | sym_plus_ver, |
| 950 | 949 | sym_name, |
| 951 | | at_sign_str, |
| 950 | // Default symbol version definition vs normal symbol version definition |
| 951 | if (chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index) "@@" else "@", |
| 952 | 952 | ver.major, |
| 953 | 953 | ver.minor, |
| 954 | 954 | sym_plus_ver, |