Skip to content

Commit

Permalink
Merge pull request #21686 from alexrp/glibc-fixes
Browse files Browse the repository at this point in the history
`glibc`: Emit some fill data for stub symbols, thus giving each a unique address.
  • Loading branch information
alexrp authored Oct 13, 2024
2 parents e131a2c + 87b1f14 commit 7185cca
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/glibc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
var ver_buf_i: u8 = 0;
while (ver_buf_i < versions_len) : (ver_buf_i += 1) {
// Example:
// .balign 4
// .globl _Exit_2_2_5
// .type _Exit_2_2_5, %function;
// .symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5
// _Exit_2_2_5:
// _Exit_2_2_5: .long 0
const ver_index = versions_buffer[ver_buf_i];
const ver = metadata.all_versions[ver_index];

Expand All @@ -957,12 +958,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
.{ sym_name, ver.major, ver.minor },
);
try stubs_asm.writer().print(
\\.balign {d}
\\.globl {s}
\\.type {s}, %function;
\\.symver {s}, {s}{s}GLIBC_{d}.{d}
\\{s}:
\\{s}: {s} 0
\\
, .{
target.ptrBitWidth() / 8,
sym_plus_ver,
sym_plus_ver,
sym_plus_ver,
Expand All @@ -971,6 +974,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
ver.major,
ver.minor,
sym_plus_ver,
wordDirective(target),
});
} else {
const sym_plus_ver = if (want_default)
Expand All @@ -982,12 +986,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
.{ sym_name, ver.major, ver.minor, ver.patch },
);
try stubs_asm.writer().print(
\\.balign {d}
\\.globl {s}
\\.type {s}, %function;
\\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}
\\{s}:
\\{s}: {s} 0
\\
, .{
target.ptrBitWidth() / 8,
sym_plus_ver,
sym_plus_ver,
sym_plus_ver,
Expand All @@ -997,6 +1003,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
ver.minor,
ver.patch,
sym_plus_ver,
wordDirective(target),
});
}
}
Expand Down Expand Up @@ -1024,10 +1031,14 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
// a strong reference.
if (std.mem.eql(u8, lib.name, "c")) {
try stubs_asm.writer().print(
\\.balign {d}
\\.globl _IO_stdin_used
\\{s} _IO_stdin_used
\\
, .{wordDirective(target)});
, .{
target.ptrBitWidth() / 8,
wordDirective(target),
});
}

const obj_inclusions_len = try inc_reader.readInt(u16, .little);
Expand Down Expand Up @@ -1099,11 +1110,12 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
var ver_buf_i: u8 = 0;
while (ver_buf_i < versions_len) : (ver_buf_i += 1) {
// Example:
// .balign 4
// .globl environ_2_2_5
// .type environ_2_2_5, %object;
// .size environ_2_2_5, 4;
// .symver environ_2_2_5, environ@@GLIBC_2.2.5
// environ_2_2_5:
// environ_2_2_5: .fill 4, 1, 0
const ver_index = versions_buffer[ver_buf_i];
const ver = metadata.all_versions[ver_index];

Expand All @@ -1122,13 +1134,15 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
.{ sym_name, ver.major, ver.minor },
);
try stubs_asm.writer().print(
\\.balign {d}
\\.globl {s}
\\.type {s}, %object;
\\.size {s}, {d};
\\.symver {s}, {s}{s}GLIBC_{d}.{d}
\\{s}:
\\{s}: .fill {d}, 1, 0
\\
, .{
target.ptrBitWidth() / 8,
sym_plus_ver,
sym_plus_ver,
sym_plus_ver,
Expand All @@ -1139,6 +1153,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
ver.major,
ver.minor,
sym_plus_ver,
size,
});
} else {
const sym_plus_ver = if (want_default)
Expand All @@ -1150,13 +1165,15 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
.{ sym_name, ver.major, ver.minor, ver.patch },
);
try stubs_asm.writer().print(
\\.balign {d}
\\.globl {s}
\\.type {s}, %object;
\\.size {s}, {d};
\\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}
\\{s}:
\\{s}: .fill {d}, 1, 0
\\
, .{
target.ptrBitWidth() / 8,
sym_plus_ver,
sym_plus_ver,
sym_plus_ver,
Expand All @@ -1168,6 +1185,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
ver.minor,
ver.patch,
sym_plus_ver,
size,
});
}
}
Expand Down

0 comments on commit 7185cca

Please sign in to comment.