Browse Source

Fixed link warnings

Hardlink libc functions to the correct version on NetBSD 10 since we do not use the micro-magic from C.
Andreas T Jonsson 1 year ago
parent
commit
2055f2b933
3 changed files with 22 additions and 16 deletions
  1. 3 3
      core/os/os_netbsd.odin
  2. 5 6
      core/sys/unix/signal_netbsd.odin
  3. 14 7
      core/sys/unix/time_unix.odin

+ 3 - 3
core/os/os_netbsd.odin

@@ -281,7 +281,7 @@ W_OK :: 2 // Test for write permission
 R_OK :: 4 // Test for read permission
 
 foreign libc {
-	@(link_name="__errno")		__errno_location :: proc() -> ^c.int ---
+	@(link_name="__errno")          __errno_location    :: proc() -> ^c.int ---
 
 	@(link_name="open")             _unix_open          :: proc(path: cstring, flags: c.int, mode: c.int) -> Handle ---
 	@(link_name="close")            _unix_close         :: proc(fd: Handle) -> c.int ---
@@ -290,8 +290,8 @@ foreign libc {
 	@(link_name="lseek")            _unix_seek          :: proc(fd: Handle, offset: i64, whence: c.int) -> i64 ---
 	@(link_name="getpagesize")      _unix_getpagesize   :: proc() -> c.int ---
 	@(link_name="stat")             _unix_stat          :: proc(path: cstring, stat: ^OS_Stat) -> c.int ---
-	@(link_name="lstat")            _unix_lstat         :: proc(path: cstring, sb: ^OS_Stat) -> c.int ---
-	@(link_name="fstat")            _unix_fstat         :: proc(fd: Handle, stat: ^OS_Stat) -> c.int ---
+	@(link_name="__lstat50")        _unix_lstat         :: proc(path: cstring, sb: ^OS_Stat) -> c.int ---
+	@(link_name="__fstat50")        _unix_fstat         :: proc(fd: Handle, stat: ^OS_Stat) -> c.int ---
 	@(link_name="readlink")         _unix_readlink      :: proc(path: cstring, buf: ^byte, bufsiz: c.size_t) -> c.ssize_t ---
 	@(link_name="access")           _unix_access        :: proc(path: cstring, mask: c.int) -> c.int ---
 	@(link_name="getcwd")           _unix_getcwd        :: proc(buf: cstring, len: c.size_t) -> cstring ---

+ 5 - 6
core/sys/unix/signal_netbsd.odin

@@ -14,14 +14,13 @@ SIG_UNBLOCK :: 2
 SIG_SETMASK :: 3
 
 siginfo_t :: struct { si_pad: [128]c.char }
-sigset_t :: struct { bits: [4]c.uint }
+sigset_t :: struct { bits: [4]u32 }
 
 foreign libc {
-	sigemptyset  :: proc(set: ^sigset_t) -> c.int ---
-	sigaddset    :: proc(set: ^sigset_t, _signal: c.int) -> c.int ---
-
-	sigtimedwait :: proc(set: ^sigset_t, info: ^siginfo_t, timeout: ^timespec) -> c.int ---
-	sigwait      :: proc(set: ^sigset_t, _signal: ^c.int) -> c.int ---
+	@(link_name="__sigemptyset14")  sigemptyset  :: proc(set: ^sigset_t) -> c.int ---
+	@(link_name="__sigaddset14")    sigaddset    :: proc(set: ^sigset_t, _signal: c.int) -> c.int ---
+	@(link_name="__sigtimedwait50") sigtimedwait :: proc(set: ^sigset_t, info: ^siginfo_t, timeout: ^timespec) -> c.int ---
+	@(link_name="sigwait")          sigwait      :: proc(set: ^sigset_t, _signal: ^c.int) -> c.int ---
 
 	@(private="file", link_name="__errno") get_error_location :: proc() -> ^c.int ---
 }

+ 14 - 7
core/sys/unix/time_unix.odin

@@ -9,11 +9,20 @@ when ODIN_OS == .Darwin {
 
 import "core:c"
 
-@(default_calling_convention="c")
-foreign libc {
-	clock_gettime :: proc(clock_id: u64, timespec: ^timespec) -> c.int ---
-	sleep         :: proc(seconds: c.uint) -> c.int ---
-	nanosleep     :: proc(requested, remaining: ^timespec) -> c.int ---
+when ODIN_OS == .NetBSD {
+	@(default_calling_convention="c")
+		foreign libc {
+			@(link_name="__clock_gettime50") clock_gettime :: proc(clock_id: u64, timespec: ^timespec) -> c.int ---
+			@(link_name="__nanosleep50")     nanosleep     :: proc(requested, remaining: ^timespec) -> c.int ---
+			@(link_name="sleep")             sleep         :: proc(seconds: c.uint) -> c.int ---
+	}
+} else {
+	@(default_calling_convention="c")
+	foreign libc {
+		clock_gettime :: proc(clock_id: u64, timespec: ^timespec) -> c.int ---
+		sleep         :: proc(seconds: c.uint) -> c.int ---
+		nanosleep     :: proc(requested, remaining: ^timespec) -> c.int ---
+	}
 }
 
 timespec :: struct {
@@ -65,8 +74,6 @@ seconds_since_boot :: proc "c" () -> f64 {
 	return f64(ts_boottime.tv_sec) + f64(ts_boottime.tv_nsec) / 1e9
 }
 
-// TODO(phix): 'nanosleep' here might refere to the wrong version on NetBSD. Need to investigate this further.
-// Normally this is solved by just including 'time.h'. So I need to understand the macro-magic going on in there.
 inline_nanosleep :: proc "c" (nanoseconds: i64) -> (remaining: timespec, res: i32) {
 	s, ns := nanoseconds / 1e9, nanoseconds % 1e9
 	requested := timespec{tv_sec=s, tv_nsec=ns}