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 16:44:04+02:00
log9070607c03f8cb652b84ba1c96c653232091df10
tree1d3dd6eb34f13a6ea4b1edc7cbfc1fed08da358e
parent7199cfc21fa8c278d568b268a129c2a4410fec78
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

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...@@ -864,8 +864,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
864 // Example:864 // Example:
865 // .balign 4865 // .balign 4
866 // .globl _Exit_2_2_5866 // .globl _Exit_2_2_5
867 // .type _Exit_2_2_5, %function;867 // .type _Exit_2_2_5, %function
868 // .symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5868 // .symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5, remove
869 // _Exit_2_2_5: .long 0869 // _Exit_2_2_5: .long 0
870 const ver_index = versions_buffer[ver_buf_i];870 const ver_index = versions_buffer[ver_buf_i];
871 const ver = metadata.all_versions[ver_index];871 const ver = metadata.all_versions[ver_index];
...@@ -876,19 +876,16 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -876,19 +876,16 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
876 const want_default = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;876 const want_default = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;
877 const at_sign_str: []const u8 = if (want_default) "@@" else "@";877 const at_sign_str: []const u8 = if (want_default) "@@" else "@";
878 if (ver.patch == 0) {878 if (ver.patch == 0) {
879 const sym_plus_ver = if (want_default)879 const sym_plus_ver = try std.fmt.allocPrint(
880 sym_name880 arena,
881 else881 "{s}_{d}_{d}",
882 try std.fmt.allocPrint(882 .{ sym_name, ver.major, ver.minor },
883 arena,883 );
884 "{s}_GLIBC_{d}_{d}",
885 .{ sym_name, ver.major, ver.minor },
886 );
887 try stubs_asm.writer().print(884 try stubs_asm.writer().print(
888 \\.balign {d}885 \\.balign {d}
889 \\.globl {s}886 \\.globl {s}
890 \\.type {s}, %function;887 \\.type {s}, %function
891 \\.symver {s}, {s}{s}GLIBC_{d}.{d}888 \\.symver {s}, {s}{s}GLIBC_{d}.{d}, remove
892 \\{s}: {s} 0889 \\{s}: {s} 0
893 \\890 \\
894 , .{891 , .{
...@@ -904,19 +901,16 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -904,19 +901,16 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
904 wordDirective(target),901 wordDirective(target),
905 });902 });
906 } else {903 } else {
907 const sym_plus_ver = if (want_default)904 const sym_plus_ver = try std.fmt.allocPrint(
908 sym_name905 arena,
909 else906 "{s}_{d}_{d}_{d}",
910 try std.fmt.allocPrint(907 .{ sym_name, ver.major, ver.minor, ver.patch },
911 arena,908 );
912 "{s}_GLIBC_{d}_{d}_{d}",
913 .{ sym_name, ver.major, ver.minor, ver.patch },
914 );
915 try stubs_asm.writer().print(909 try stubs_asm.writer().print(
916 \\.balign {d}910 \\.balign {d}
917 \\.globl {s}911 \\.globl {s}
918 \\.type {s}, %function;912 \\.type {s}, %function
919 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}913 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}, remove
920 \\{s}: {s} 0914 \\{s}: {s} 0
921 \\915 \\
922 , .{916 , .{
...@@ -1041,9 +1035,9 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -1041,9 +1035,9 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
1041 // Example:1035 // Example:
1042 // .balign 41036 // .balign 4
1043 // .globl environ_2_2_51037 // .globl environ_2_2_5
1044 // .type environ_2_2_5, %object;1038 // .type environ_2_2_5, %object
1045 // .size environ_2_2_5, 4;1039 // .size environ_2_2_5, 4
1046 // .symver environ_2_2_5, environ@@GLIBC_2.2.51040 // .symver environ_2_2_5, environ@@GLIBC_2.2.5, remove
1047 // environ_2_2_5: .fill 4, 1, 01041 // environ_2_2_5: .fill 4, 1, 0
1048 const ver_index = versions_buffer[ver_buf_i];1042 const ver_index = versions_buffer[ver_buf_i];
1049 const ver = metadata.all_versions[ver_index];1043 const ver = metadata.all_versions[ver_index];
...@@ -1054,20 +1048,17 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -1054,20 +1048,17 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
1054 const want_default = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;1048 const want_default = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;
1055 const at_sign_str: []const u8 = if (want_default) "@@" else "@";1049 const at_sign_str: []const u8 = if (want_default) "@@" else "@";
1056 if (ver.patch == 0) {1050 if (ver.patch == 0) {
1057 const sym_plus_ver = if (want_default)1051 const sym_plus_ver = try std.fmt.allocPrint(
1058 sym_name1052 arena,
1059 else1053 "{s}_{d}_{d}",
1060 try std.fmt.allocPrint(1054 .{ sym_name, ver.major, ver.minor },
1061 arena,1055 );
1062 "{s}_GLIBC_{d}_{d}",
1063 .{ sym_name, ver.major, ver.minor },
1064 );
1065 try stubs_asm.writer().print(1056 try stubs_asm.writer().print(
1066 \\.balign {d}1057 \\.balign {d}
1067 \\.globl {s}1058 \\.globl {s}
1068 \\.type {s}, %object;1059 \\.type {s}, %object
1069 \\.size {s}, {d};1060 \\.size {s}, {d}
1070 \\.symver {s}, {s}{s}GLIBC_{d}.{d}1061 \\.symver {s}, {s}{s}GLIBC_{d}.{d}, remove
1071 \\{s}: .fill {d}, 1, 01062 \\{s}: .fill {d}, 1, 0
1072 \\1063 \\
1073 , .{1064 , .{
...@@ -1085,20 +1076,17 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -1085,20 +1076,17 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
1085 size,1076 size,
1086 });1077 });
1087 } else {1078 } else {
1088 const sym_plus_ver = if (want_default)1079 const sym_plus_ver = try std.fmt.allocPrint(
1089 sym_name1080 arena,
1090 else1081 "{s}_{d}_{d}_{d}",
1091 try std.fmt.allocPrint(1082 .{ sym_name, ver.major, ver.minor, ver.patch },
1092 arena,1083 );
1093 "{s}_GLIBC_{d}_{d}_{d}",
1094 .{ sym_name, ver.major, ver.minor, ver.patch },
1095 );
1096 try stubs_asm.writer().print(1084 try stubs_asm.writer().print(
1097 \\.balign {d}1085 \\.balign {d}
1098 \\.globl {s}1086 \\.globl {s}
1099 \\.type {s}, %object;1087 \\.type {s}, %object
1100 \\.size {s}, {d};1088 \\.size {s}, {d}
1101 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}1089 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}, remove
1102 \\{s}: .fill {d}, 1, 01090 \\{s}: .fill {d}, 1, 0
1103 \\1091 \\
1104 , .{1092 , .{