Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 12 Jan 2016 17:24:02 +0100
From: Markus Wichmann <nullplan@....net>
To: musl@...ts.openwall.com
Subject: Re: dynamic linker command line invocation

On Mon, Jan 11, 2016 at 12:03:37PM -0500, N Jain wrote:
> Hi Marcus,
> 
> Thanks. I am able to get this part working.
> I am facing one more issue during dynamic linking and need some help to
> understand how to resolve it.
> 
> In below code part of __dls3 function I found that TPIDRURO register is
> being used to read the threadId.
> I would like to understand how kernel should set this value ?
> 

It shouldn't. musl calls __set_thread_area() (in __init_tp()), and that
has to set this register.

The kernel is only involved, if musl has to do a syscall there.

> As per my understanding kernel should allocate memory and set this register
> for current task.

Generally, no. The allocation is up to the application. But on some
architectures, the kernel has to add a bit of stuff to the list of
things to be swapped on task switch (e.g. on i386 the TLS segment
descriptors in the GDT). For more information, ask your architecture's
system programming manual.

> But when i do this in my kernel the values doesn't match up as MUSL is
> using some "builtin_tls" ?
> 
> /* Temporarily set the tls size to the full size of
> * builtin_tls so that __copy_tls will use the same layout
> * as it did for before. Then check, just to be safe. */
> libc.tls_size = sizeof builtin_tls;
> if (__copy_tls((void*)builtin_tls) != self) a_crash();
> 

If you get there, __init_tp() was already called, so the thread pointer
should be set to builtin_tls. (Or rather, should be set such that
__copy_tls() will return the current thread pointer). If that isn't the
case then something has already gone wrong. Check __init_tp()!

Ciao,
Markus

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.