authorgravatar for 51252236+xdBronch@users.noreply.github.comxdBronch <51252236+xdBronch@users.noreply.github.com> 2023-12-05 08:21:53-05:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-01-04 18:02:45+02:00
log15f7a477d04b0a4a20c9a4489ea819e95939315b
treebb5222d1d879a6c2321706214a2c09f6c3e8dace
parent6ebeb85abdca74c70d59b5f4f5ceea0acd77a108

fallback to zigs DynLib when static linking musl


1 files changed, 11 insertions(+), 8 deletions(-)

lib/std/dynamic_library.zig+11-8
......@@ -8,9 +8,12 @@ const windows = std.os.windows;
88const system = std.os.system;
99
1010pub const DynLib = switch (builtin.os.tag) {
11 .linux => if (builtin.link_libc) DlDynlib else ElfDynLib,
11 .linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .Static)
12 ElfDynLib
13 else
14 DlDynLib,
1215 .windows => WindowsDynLib,
13 .macos, .tvos, .watchos, .ios, .freebsd, .netbsd, .openbsd, .dragonfly, .solaris, .illumos => DlDynlib,
16 .macos, .tvos, .watchos, .ios, .freebsd, .netbsd, .openbsd, .dragonfly, .solaris, .illumos => DlDynLib,
1417 else => void,
1518};
1619
......@@ -352,30 +355,30 @@ pub const WindowsDynLib = struct {
352355 }
353356};
354357
355pub const DlDynlib = struct {
358pub const DlDynLib = struct {
356359 pub const Error = error{FileNotFound};
357360
358361 handle: *anyopaque,
359362
360 pub fn open(path: []const u8) !DlDynlib {
363 pub fn open(path: []const u8) !DlDynLib {
361364 const path_c = try os.toPosixPath(path);
362365 return openZ(&path_c);
363366 }
364367
365 pub fn openZ(path_c: [*:0]const u8) !DlDynlib {
366 return DlDynlib{
368 pub fn openZ(path_c: [*:0]const u8) !DlDynLib {
369 return DlDynLib{
367370 .handle = system.dlopen(path_c, system.RTLD.LAZY) orelse {
368371 return error.FileNotFound;
369372 },
370373 };
371374 }
372375
373 pub fn close(self: *DlDynlib) void {
376 pub fn close(self: *DlDynLib) void {
374377 _ = system.dlclose(self.handle);
375378 self.* = undefined;
376379 }
377380
378 pub fn lookup(self: *DlDynlib, comptime T: type, name: [:0]const u8) ?T {
381 pub fn lookup(self: *DlDynLib, comptime T: type, name: [:0]const u8) ?T {
379382 // dlsym (and other dl-functions) secretly take shadow parameter - return address on stack
380383 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826
381384 if (@call(.never_tail, system.dlsym, .{ self.handle, name.ptr })) |symbol| {