authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-13 13:00:00+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-10-13 13:00:00+02:00
log7185ccad14068729cc805214aebd3bac62e99c73
tree20191ded416a4fcaa4696b0449cfef58022354d1
parente131a2c8e20de13256954cbb38ca3502cdfca07b
parent87b1f14015f12ab6cf7ad694d5318bf28138ff6c
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21686 from alexrp/glibc-fixes

`glibc`: Emit some fill data for stub symbols, thus giving each a unique address.

1 files changed, 25 insertions(+), 7 deletions(-)

src/glibc.zig+25-7
...@@ -935,10 +935,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -935,10 +935,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
935 var ver_buf_i: u8 = 0;935 var ver_buf_i: u8 = 0;
936 while (ver_buf_i < versions_len) : (ver_buf_i += 1) {936 while (ver_buf_i < versions_len) : (ver_buf_i += 1) {
937 // Example:937 // Example:
938 // .balign 4
938 // .globl _Exit_2_2_5939 // .globl _Exit_2_2_5
939 // .type _Exit_2_2_5, %function;940 // .type _Exit_2_2_5, %function;
940 // .symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5941 // .symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5
941 // _Exit_2_2_5:942 // _Exit_2_2_5: .long 0
942 const ver_index = versions_buffer[ver_buf_i];943 const ver_index = versions_buffer[ver_buf_i];
943 const ver = metadata.all_versions[ver_index];944 const ver = metadata.all_versions[ver_index];
944945
...@@ -957,12 +958,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -957,12 +958,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
957 .{ sym_name, ver.major, ver.minor },958 .{ sym_name, ver.major, ver.minor },
958 );959 );
959 try stubs_asm.writer().print(960 try stubs_asm.writer().print(
961 \\.balign {d}
960 \\.globl {s}962 \\.globl {s}
961 \\.type {s}, %function;963 \\.type {s}, %function;
962 \\.symver {s}, {s}{s}GLIBC_{d}.{d}964 \\.symver {s}, {s}{s}GLIBC_{d}.{d}
963 \\{s}:965 \\{s}: {s} 0
964 \\966 \\
965 , .{967 , .{
968 target.ptrBitWidth() / 8,
966 sym_plus_ver,969 sym_plus_ver,
967 sym_plus_ver,970 sym_plus_ver,
968 sym_plus_ver,971 sym_plus_ver,
...@@ -971,6 +974,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -971,6 +974,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
971 ver.major,974 ver.major,
972 ver.minor,975 ver.minor,
973 sym_plus_ver,976 sym_plus_ver,
977 wordDirective(target),
974 });978 });
975 } else {979 } else {
976 const sym_plus_ver = if (want_default)980 const sym_plus_ver = if (want_default)
...@@ -982,12 +986,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -982,12 +986,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
982 .{ sym_name, ver.major, ver.minor, ver.patch },986 .{ sym_name, ver.major, ver.minor, ver.patch },
983 );987 );
984 try stubs_asm.writer().print(988 try stubs_asm.writer().print(
989 \\.balign {d}
985 \\.globl {s}990 \\.globl {s}
986 \\.type {s}, %function;991 \\.type {s}, %function;
987 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}992 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}
988 \\{s}:993 \\{s}: {s} 0
989 \\994 \\
990 , .{995 , .{
996 target.ptrBitWidth() / 8,
991 sym_plus_ver,997 sym_plus_ver,
992 sym_plus_ver,998 sym_plus_ver,
993 sym_plus_ver,999 sym_plus_ver,
...@@ -997,6 +1003,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -997,6 +1003,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
997 ver.minor,1003 ver.minor,
998 ver.patch,1004 ver.patch,
999 sym_plus_ver,1005 sym_plus_ver,
1006 wordDirective(target),
1000 });1007 });
1001 }1008 }
1002 }1009 }
...@@ -1024,10 +1031,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1024,10 +1031,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1024 // a strong reference.1031 // a strong reference.
1025 if (std.mem.eql(u8, lib.name, "c")) {1032 if (std.mem.eql(u8, lib.name, "c")) {
1026 try stubs_asm.writer().print(1033 try stubs_asm.writer().print(
1034 \\.balign {d}
1027 \\.globl _IO_stdin_used1035 \\.globl _IO_stdin_used
1028 \\{s} _IO_stdin_used1036 \\{s} _IO_stdin_used
1029 \\1037 \\
1030 , .{wordDirective(target)});1038 , .{
1039 target.ptrBitWidth() / 8,
1040 wordDirective(target),
1041 });
1031 }1042 }
10321043
1033 const obj_inclusions_len = try inc_reader.readInt(u16, .little);1044 const obj_inclusions_len = try inc_reader.readInt(u16, .little);
...@@ -1099,11 +1110,12 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1099,11 +1110,12 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1099 var ver_buf_i: u8 = 0;1110 var ver_buf_i: u8 = 0;
1100 while (ver_buf_i < versions_len) : (ver_buf_i += 1) {1111 while (ver_buf_i < versions_len) : (ver_buf_i += 1) {
1101 // Example:1112 // Example:
1113 // .balign 4
1102 // .globl environ_2_2_51114 // .globl environ_2_2_5
1103 // .type environ_2_2_5, %object;1115 // .type environ_2_2_5, %object;
1104 // .size environ_2_2_5, 4;1116 // .size environ_2_2_5, 4;
1105 // .symver environ_2_2_5, environ@@GLIBC_2.2.51117 // .symver environ_2_2_5, environ@@GLIBC_2.2.5
1106 // environ_2_2_5:1118 // environ_2_2_5: .fill 4, 1, 0
1107 const ver_index = versions_buffer[ver_buf_i];1119 const ver_index = versions_buffer[ver_buf_i];
1108 const ver = metadata.all_versions[ver_index];1120 const ver = metadata.all_versions[ver_index];
11091121
...@@ -1122,13 +1134,15 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1122,13 +1134,15 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1122 .{ sym_name, ver.major, ver.minor },1134 .{ sym_name, ver.major, ver.minor },
1123 );1135 );
1124 try stubs_asm.writer().print(1136 try stubs_asm.writer().print(
1137 \\.balign {d}
1125 \\.globl {s}1138 \\.globl {s}
1126 \\.type {s}, %object;1139 \\.type {s}, %object;
1127 \\.size {s}, {d};1140 \\.size {s}, {d};
1128 \\.symver {s}, {s}{s}GLIBC_{d}.{d}1141 \\.symver {s}, {s}{s}GLIBC_{d}.{d}
1129 \\{s}:1142 \\{s}: .fill {d}, 1, 0
1130 \\1143 \\
1131 , .{1144 , .{
1145 target.ptrBitWidth() / 8,
1132 sym_plus_ver,1146 sym_plus_ver,
1133 sym_plus_ver,1147 sym_plus_ver,
1134 sym_plus_ver,1148 sym_plus_ver,
...@@ -1139,6 +1153,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1139,6 +1153,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1139 ver.major,1153 ver.major,
1140 ver.minor,1154 ver.minor,
1141 sym_plus_ver,1155 sym_plus_ver,
1156 size,
1142 });1157 });
1143 } else {1158 } else {
1144 const sym_plus_ver = if (want_default)1159 const sym_plus_ver = if (want_default)
...@@ -1150,13 +1165,15 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1150,13 +1165,15 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1150 .{ sym_name, ver.major, ver.minor, ver.patch },1165 .{ sym_name, ver.major, ver.minor, ver.patch },
1151 );1166 );
1152 try stubs_asm.writer().print(1167 try stubs_asm.writer().print(
1168 \\.balign {d}
1153 \\.globl {s}1169 \\.globl {s}
1154 \\.type {s}, %object;1170 \\.type {s}, %object;
1155 \\.size {s}, {d};1171 \\.size {s}, {d};
1156 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}1172 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}
1157 \\{s}:1173 \\{s}: .fill {d}, 1, 0
1158 \\1174 \\
1159 , .{1175 , .{
1176 target.ptrBitWidth() / 8,
1160 sym_plus_ver,1177 sym_plus_ver,
1161 sym_plus_ver,1178 sym_plus_ver,
1162 sym_plus_ver,1179 sym_plus_ver,
...@@ -1168,6 +1185,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1168,6 +1185,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1168 ver.minor,1185 ver.minor,
1169 ver.patch,1186 ver.patch,
1170 sym_plus_ver,1187 sym_plus_ver,
1188 size,
1171 });1189 });
1172 }1190 }
1173 }1191 }