authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-12 22:54:05+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-12 23:01:05+02:00
log87b1f14015f12ab6cf7ad694d5318bf28138ff6c
tree7a8b3360f7f71b999130f5d74442c7d449afcced
parent7b376b1c54d79d9869ca85a992819df04a0786e9
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

glibc: Align stub symbols to the target word size.

Ideally we'd like to use whatever alignment glibc actually ends up using in the real libc.so.6. But we don't really have a way of getting at that information at the moment, and it's not present in the abilist files. I haven't yet seen a symbol that wasn't word-aligned, though, so I think this should be good enough for 99% of symbols, if not actually 100%.

1 files changed, 15 insertions(+), 1 deletions(-)

src/glibc.zig+15-1
...@@ -935,6 +935,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -935,6 +935,7 @@ 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
...@@ -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}: {s} 0965 \\{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,
...@@ -983,12 +986,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -983,12 +986,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
983 .{ sym_name, ver.major, ver.minor, ver.patch },986 .{ sym_name, ver.major, ver.minor, ver.patch },
984 );987 );
985 try stubs_asm.writer().print(988 try stubs_asm.writer().print(
989 \\.balign {d}
986 \\.globl {s}990 \\.globl {s}
987 \\.type {s}, %function;991 \\.type {s}, %function;
988 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}992 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}
989 \\{s}: {s} 0993 \\{s}: {s} 0
990 \\994 \\
991 , .{995 , .{
996 target.ptrBitWidth() / 8,
992 sym_plus_ver,997 sym_plus_ver,
993 sym_plus_ver,998 sym_plus_ver,
994 sym_plus_ver,999 sym_plus_ver,
...@@ -1026,10 +1031,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1026,10 +1031,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1026 // a strong reference.1031 // a strong reference.
1027 if (std.mem.eql(u8, lib.name, "c")) {1032 if (std.mem.eql(u8, lib.name, "c")) {
1028 try stubs_asm.writer().print(1033 try stubs_asm.writer().print(
1034 \\.balign {d}
1029 \\.globl _IO_stdin_used1035 \\.globl _IO_stdin_used
1030 \\{s} _IO_stdin_used1036 \\{s} _IO_stdin_used
1031 \\1037 \\
1032 , .{wordDirective(target)});1038 , .{
1039 target.ptrBitWidth() / 8,
1040 wordDirective(target),
1041 });
1033 }1042 }
10341043
1035 const obj_inclusions_len = try inc_reader.readInt(u16, .little);1044 const obj_inclusions_len = try inc_reader.readInt(u16, .little);
...@@ -1101,6 +1110,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1101,6 +1110,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1101 var ver_buf_i: u8 = 0;1110 var ver_buf_i: u8 = 0;
1102 while (ver_buf_i < versions_len) : (ver_buf_i += 1) {1111 while (ver_buf_i < versions_len) : (ver_buf_i += 1) {
1103 // Example:1112 // Example:
1113 // .balign 4
1104 // .globl environ_2_2_51114 // .globl environ_2_2_5
1105 // .type environ_2_2_5, %object;1115 // .type environ_2_2_5, %object;
1106 // .size environ_2_2_5, 4;1116 // .size environ_2_2_5, 4;
...@@ -1124,6 +1134,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1124,6 +1134,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1124 .{ sym_name, ver.major, ver.minor },1134 .{ sym_name, ver.major, ver.minor },
1125 );1135 );
1126 try stubs_asm.writer().print(1136 try stubs_asm.writer().print(
1137 \\.balign {d}
1127 \\.globl {s}1138 \\.globl {s}
1128 \\.type {s}, %object;1139 \\.type {s}, %object;
1129 \\.size {s}, {d};1140 \\.size {s}, {d};
...@@ -1131,6 +1142,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1131,6 +1142,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1131 \\{s}: .fill {d}, 1, 01142 \\{s}: .fill {d}, 1, 0
1132 \\1143 \\
1133 , .{1144 , .{
1145 target.ptrBitWidth() / 8,
1134 sym_plus_ver,1146 sym_plus_ver,
1135 sym_plus_ver,1147 sym_plus_ver,
1136 sym_plus_ver,1148 sym_plus_ver,
...@@ -1153,6 +1165,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1153,6 +1165,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1153 .{ sym_name, ver.major, ver.minor, ver.patch },1165 .{ sym_name, ver.major, ver.minor, ver.patch },
1154 );1166 );
1155 try stubs_asm.writer().print(1167 try stubs_asm.writer().print(
1168 \\.balign {d}
1156 \\.globl {s}1169 \\.globl {s}
1157 \\.type {s}, %object;1170 \\.type {s}, %object;
1158 \\.size {s}, {d};1171 \\.size {s}, {d};
...@@ -1160,6 +1173,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -1160,6 +1173,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
1160 \\{s}: .fill {d}, 1, 01173 \\{s}: .fill {d}, 1, 0
1161 \\1174 \\
1162 , .{1175 , .{
1176 target.ptrBitWidth() / 8,
1163 sym_plus_ver,1177 sym_plus_ver,
1164 sym_plus_ver,1178 sym_plus_ver,
1165 sym_plus_ver,1179 sym_plus_ver,