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
signaturebadge-check 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
935935 var ver_buf_i: u8 = 0;
936936 while (ver_buf_i < versions_len) : (ver_buf_i += 1) {
937937 // Example:
938 // .balign 4
938939 // .globl _Exit_2_2_5
939940 // .type _Exit_2_2_5, %function;
940941 // .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
957958 .{ sym_name, ver.major, ver.minor },
958959 );
959960 try stubs_asm.writer().print(
961 \\.balign {d}
960962 \\.globl {s}
961963 \\.type {s}, %function;
962964 \\.symver {s}, {s}{s}GLIBC_{d}.{d}
963965 \\{s}: {s} 0
964966 \\
965967 , .{
968 target.ptrBitWidth() / 8,
966969 sym_plus_ver,
967970 sym_plus_ver,
968971 sym_plus_ver,
......@@ -983,12 +986,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
983986 .{ sym_name, ver.major, ver.minor, ver.patch },
984987 );
985988 try stubs_asm.writer().print(
989 \\.balign {d}
986990 \\.globl {s}
987991 \\.type {s}, %function;
988992 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}
989993 \\{s}: {s} 0
990994 \\
991995 , .{
996 target.ptrBitWidth() / 8,
992997 sym_plus_ver,
993998 sym_plus_ver,
994999 sym_plus_ver,
......@@ -1026,10 +1031,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
10261031 // a strong reference.
10271032 if (std.mem.eql(u8, lib.name, "c")) {
10281033 try stubs_asm.writer().print(
1034 \\.balign {d}
10291035 \\.globl _IO_stdin_used
10301036 \\{s} _IO_stdin_used
10311037 \\
1032 , .{wordDirective(target)});
1038 , .{
1039 target.ptrBitWidth() / 8,
1040 wordDirective(target),
1041 });
10331042 }
10341043
10351044 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
11011110 var ver_buf_i: u8 = 0;
11021111 while (ver_buf_i < versions_len) : (ver_buf_i += 1) {
11031112 // Example:
1113 // .balign 4
11041114 // .globl environ_2_2_5
11051115 // .type environ_2_2_5, %object;
11061116 // .size environ_2_2_5, 4;
......@@ -1124,6 +1134,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
11241134 .{ sym_name, ver.major, ver.minor },
11251135 );
11261136 try stubs_asm.writer().print(
1137 \\.balign {d}
11271138 \\.globl {s}
11281139 \\.type {s}, %object;
11291140 \\.size {s}, {d};
......@@ -1131,6 +1142,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
11311142 \\{s}: .fill {d}, 1, 0
11321143 \\
11331144 , .{
1145 target.ptrBitWidth() / 8,
11341146 sym_plus_ver,
11351147 sym_plus_ver,
11361148 sym_plus_ver,
......@@ -1153,6 +1165,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
11531165 .{ sym_name, ver.major, ver.minor, ver.patch },
11541166 );
11551167 try stubs_asm.writer().print(
1168 \\.balign {d}
11561169 \\.globl {s}
11571170 \\.type {s}, %object;
11581171 \\.size {s}, {d};
......@@ -1160,6 +1173,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
11601173 \\{s}: .fill {d}, 1, 0
11611174 \\
11621175 , .{
1176 target.ptrBitWidth() / 8,
11631177 sym_plus_ver,
11641178 sym_plus_ver,
11651179 sym_plus_ver,