authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-08 15:50:34+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-09 13:16:35+02:00
log85a6b75e18248bad83437323cab14fe1973057ec
tree68f1db9646fd3a18492498828adfcda7d65b5ebd
parent787020b30b68d665cd08824d05ce5c7e459eccd1

glibc: Fix stub libraries containing unwanted symbols.

Closes #8096.

1 files changed, 35 insertions(+), 47 deletions(-)

src/glibc.zig+35-47
......@@ -864,8 +864,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
864864 // Example:
865865 // .balign 4
866866 // .globl _Exit_2_2_5
867 // .type _Exit_2_2_5, %function;
868 // .symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5
867 // .type _Exit_2_2_5, %function
868 // .symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5, remove
869869 // _Exit_2_2_5: .long 0
870870 const ver_index = versions_buffer[ver_buf_i];
871871 const ver = metadata.all_versions[ver_index];
......@@ -876,19 +876,16 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
876876 const want_default = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;
877877 const at_sign_str: []const u8 = if (want_default) "@@" else "@";
878878 if (ver.patch == 0) {
879 const sym_plus_ver = if (want_default)
880 sym_name
881 else
882 try std.fmt.allocPrint(
883 arena,
884 "{s}_GLIBC_{d}_{d}",
885 .{ sym_name, ver.major, ver.minor },
886 );
879 const sym_plus_ver = try std.fmt.allocPrint(
880 arena,
881 "{s}_{d}_{d}",
882 .{ sym_name, ver.major, ver.minor },
883 );
887884 try stubs_asm.writer().print(
888885 \\.balign {d}
889886 \\.globl {s}
890 \\.type {s}, %function;
891 \\.symver {s}, {s}{s}GLIBC_{d}.{d}
887 \\.type {s}, %function
888 \\.symver {s}, {s}{s}GLIBC_{d}.{d}, remove
892889 \\{s}: {s} 0
893890 \\
894891 , .{
......@@ -904,19 +901,16 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
904901 wordDirective(target),
905902 });
906903 } else {
907 const sym_plus_ver = if (want_default)
908 sym_name
909 else
910 try std.fmt.allocPrint(
911 arena,
912 "{s}_GLIBC_{d}_{d}_{d}",
913 .{ sym_name, ver.major, ver.minor, ver.patch },
914 );
904 const sym_plus_ver = try std.fmt.allocPrint(
905 arena,
906 "{s}_{d}_{d}_{d}",
907 .{ sym_name, ver.major, ver.minor, ver.patch },
908 );
915909 try stubs_asm.writer().print(
916910 \\.balign {d}
917911 \\.globl {s}
918 \\.type {s}, %function;
919 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}
912 \\.type {s}, %function
913 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}, remove
920914 \\{s}: {s} 0
921915 \\
922916 , .{
......@@ -1041,9 +1035,9 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
10411035 // Example:
10421036 // .balign 4
10431037 // .globl environ_2_2_5
1044 // .type environ_2_2_5, %object;
1045 // .size environ_2_2_5, 4;
1046 // .symver environ_2_2_5, environ@@GLIBC_2.2.5
1038 // .type environ_2_2_5, %object
1039 // .size environ_2_2_5, 4
1040 // .symver environ_2_2_5, environ@@GLIBC_2.2.5, remove
10471041 // environ_2_2_5: .fill 4, 1, 0
10481042 const ver_index = versions_buffer[ver_buf_i];
10491043 const ver = metadata.all_versions[ver_index];
......@@ -1054,20 +1048,17 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
10541048 const want_default = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;
10551049 const at_sign_str: []const u8 = if (want_default) "@@" else "@";
10561050 if (ver.patch == 0) {
1057 const sym_plus_ver = if (want_default)
1058 sym_name
1059 else
1060 try std.fmt.allocPrint(
1061 arena,
1062 "{s}_GLIBC_{d}_{d}",
1063 .{ sym_name, ver.major, ver.minor },
1064 );
1051 const sym_plus_ver = try std.fmt.allocPrint(
1052 arena,
1053 "{s}_{d}_{d}",
1054 .{ sym_name, ver.major, ver.minor },
1055 );
10651056 try stubs_asm.writer().print(
10661057 \\.balign {d}
10671058 \\.globl {s}
1068 \\.type {s}, %object;
1069 \\.size {s}, {d};
1070 \\.symver {s}, {s}{s}GLIBC_{d}.{d}
1059 \\.type {s}, %object
1060 \\.size {s}, {d}
1061 \\.symver {s}, {s}{s}GLIBC_{d}.{d}, remove
10711062 \\{s}: .fill {d}, 1, 0
10721063 \\
10731064 , .{
......@@ -1085,20 +1076,17 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
10851076 size,
10861077 });
10871078 } else {
1088 const sym_plus_ver = if (want_default)
1089 sym_name
1090 else
1091 try std.fmt.allocPrint(
1092 arena,
1093 "{s}_GLIBC_{d}_{d}_{d}",
1094 .{ sym_name, ver.major, ver.minor, ver.patch },
1095 );
1079 const sym_plus_ver = try std.fmt.allocPrint(
1080 arena,
1081 "{s}_{d}_{d}_{d}",
1082 .{ sym_name, ver.major, ver.minor, ver.patch },
1083 );
10961084 try stubs_asm.writer().print(
10971085 \\.balign {d}
10981086 \\.globl {s}
1099 \\.type {s}, %object;
1100 \\.size {s}, {d};
1101 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}
1087 \\.type {s}, %object
1088 \\.size {s}, {d}
1089 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}, remove
11021090 \\{s}: .fill {d}, 1, 0
11031091 \\
11041092 , .{