Thread (5 messages) flat view 5 messages, 3 authors, 2019-06-14

Re: [PATCH 1/5] glibc: Perform rseq(2) registration at C startup and thread creation (v10)

From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Date: 2019-06-14 13:39:14
Also in: lkml

----- On Jun 14, 2019, at 3:29 PM, David Laight David.Laight@ACULAB.COM wrote:
From: Mathieu Desnoyers
quoted
Sent: 14 June 2019 14:02
...
quoted
But my original issue remains: if I define a variable called __rseq_handled
within either the main executable or the preloaded library, it overshadows
the libc one:
1) That is the was elf symbol resolution is required to work.
  Otherwise variables like 'errno' (non-thread safe form) wouldn't work.

2) Don't do it then :-)
  Names starting with __ will be reserved (probably 'for the implementation').

The real 'fun' starts because, under some circumstances, looking up a symbol as:
foo = dlsym(lib_handle, "foo");
Can find the data item instead of the function!
Usually it works (even when foo is global data) because 'lib_handle' refers
to a different symbol table.
But it can go horribly wrong.
I was setting __rseq_handled too soon, before re-relocation of the dynamic linker.
I moved the initialization after re-relocation and it works fine now.

The purpose of __rseq_handled is to allow early adopter libraries and applications
to define their own global instance of the symbol, and check whether the libc
they are linked against handle rseq registration or not.

libc specifies the layout of that variable (an integer). The dynamic linker
chooses one of those instances so it's used in the global symbol table of the
program. The important thing is that all libraries agree on that global symbol.
Of course this is not compatible with libraries compiled with forced "hidden"
symbols only.

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help