clock() doesn’t use the syspage.
This turns out to be because our libc initilization
is ‘special’, probably because we assume it’s always
present.
I’ve opened PR 22978 to at least start a discussion
internally as to whether the libc init should
be done via a normal elf DT_INIT section which
would be caught by dlopen().
The fix I gave below is really just a workaround
for time(). You may run into other issues with
other funcs due to the lack of full initilization.
A better solution for now is probably something
like tim = time for any symbol in libc since as
stated it’s always present on QNX.
Regards,
-seanb
Armin Steinhoff <a-steinhoff@web.de> wrote:
Sean,
thanks for your reply.
Is the initialization of the _syspage_ptr only neccessary if I’m using
the libc?
Why is the clock() example working?
Regards
Armin
Sean Boudreau wrote:
Armin Steinhoff <> a-steinhoff@web.de> > wrote:
Garry Turcotte wrote:
I would dlopen(NULL) since you’ll always have libc loaded.
I have to use routines from different shared libraries … one of them
is the libc. What means dlopen(NULL) ?
The code below is working!
#include <stdio.h
#include <time.h
#include <dlfcn.h
typedef clock_t (timefunc)( void );
timefunc tim;
void handle;
clock_t x;
int main(void)
{
/* Open a shared library. */
handle = dlopen( “/lib/libc.so”, RTLD_NOW );
/* Find the address of a function */
tim = (timefunc)dlsym( handle, “clock” );
/* Invoke the function */
x = (*tim)();
exit(0);
}
I believe the time() call uses a syspage pointer that
hasn’t been initialized.
And who is responsible for that?
Regards
Armin
You can do it if you like:
#include <stdio.h
#include <time.h
#include <dlfcn.h
#include <sys/syspage.h
typedef time_t (*timefunc)( time_t );
timefunc tim;
void* handle;
time_t x;
int main(int argc, char **argv)
{
struct syspage_entry **syspage_ptrp;
/* Open a shared library. */
handle = dlopen( “/lib/libc.so”, RTLD_NOW);
syspage_ptrp = dlsym( handle, “_syspage_ptr” );
*syspage_ptrp = _syspage_ptr;
/* Find the address of the time function */
tim = (timefunc)dlsym( handle, “time” );
/* Invoke the time function */
x = (*tim)( NULL );
exit(0);
}