From 1a833ebd30ad9481d2acf6d5296f76086713f880 Mon Sep 17 00:00:00 2001
From: Norman Feske <norman.feske@genode-labs.com>
Date: Wed, 22 Feb 2012 11:08:34 +0100
Subject: [PATCH] Allow for overriding time-related libc functions

If using the libc for Noux programs, the default implementation of these
functions cannot be used because they rely on a dedicated
timeout-scheduler thread. Noux programs, however, are expected to
contain only the main thread. By turning the functions into weak
symbols, the noux libc-plugin can provide custom implementations.
---
 libports/src/lib/libc/clock_gettime.cc | 3 ++-
 libports/src/lib/libc/gettimeofday.cc  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libports/src/lib/libc/clock_gettime.cc b/libports/src/lib/libc/clock_gettime.cc
index 3c60f4273e..11d7b78a46 100644
--- a/libports/src/lib/libc/clock_gettime.cc
+++ b/libports/src/lib/libc/clock_gettime.cc
@@ -16,7 +16,8 @@
 
 #include <sys/time.h>
 
-extern "C" int clock_gettime(clockid_t clk_id, struct timespec *tp)
+extern "C" __attribute__((weak))
+int clock_gettime(clockid_t clk_id, struct timespec *tp)
 {
 	if (clk_id != CLOCK_MONOTONIC)
 		PWRN("Unsupported clk_id, using CLOCK_MONOTONIC instead.");
diff --git a/libports/src/lib/libc/gettimeofday.cc b/libports/src/lib/libc/gettimeofday.cc
index 3e509b960e..2316f6e167 100644
--- a/libports/src/lib/libc/gettimeofday.cc
+++ b/libports/src/lib/libc/gettimeofday.cc
@@ -15,7 +15,8 @@
 
 #include <sys/time.h>
 
-extern "C" int gettimeofday(struct timeval *tv, struct timezone *tz)
+extern "C" __attribute__((weak))
+int gettimeofday(struct timeval *tv, struct timezone *tz)
 {
 	Genode::Alarm::Time time = Genode::Timeout_thread::alarm_timer()->time();