Page MenuHomeFreeBSD

Add support for R_AARCH64_TLSDESC with a symbol, and R_AARCH64_TLS_TPREL64
ClosedPublic

Authored by andrew on Mar 31 2015, 5:03 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 18 2024, 9:53 AM
Unknown Object (File)
Feb 22 2024, 8:44 PM
Unknown Object (File)
Feb 15 2024, 4:31 PM
Unknown Object (File)
Jan 28 2024, 11:08 PM
Unknown Object (File)
Jan 8 2024, 10:03 PM
Unknown Object (File)
Jan 8 2024, 10:03 PM
Unknown Object (File)
Jan 8 2024, 10:03 PM
Unknown Object (File)
Jan 8 2024, 10:03 PM
Subscribers

Details

Summary

These are needed to allocate memory, and when accessing thread local data
across different ELF files.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

andrew retitled this revision from to Add support for R_AARCH64_TLSDESC with a symbol, and R_AARCH64_TLS_TPREL64.
andrew updated this object.
andrew edited the test plan for this revision. (Show Details)
andrew added reviewers: kib, emaste.
libexec/rtld-elf/aarch64/reloc.c
136

Use xmalloc() wrapper to avoid manuall testing the allocation failure and provide standard error message.

175

Please use _rtld_error().

177

Could you, please, clarify the rules for sharing the tls_data items between threads ? Is it thread-private, or could it be that two threads try to perform rtld_tlsdesc_handle() simultaneously on the same tlsdesc ?

I am mostly wondering about read-lock, is it enough or the case needs write-lock due to modifications to tlsdesc.

Note that it is possible that symbol lookup returns different results for separate invocations.

256

Hmm, I think you should pass lockstate down to tld_tlsdesc_handle() and then for find_symdef(), instead of recursively locking the bind lock. In fact,what you do could deadlock.

libexec/rtld-elf/aarch64/reloc.c
175

I think we want to print the message set by _rtld_error in find_symdef and exit, something like die, but that's a static function in rtld.c.

177

We need to look up the symbol to find it's offset from the thread pointer. The details are in [1], and in this case we are interested in TPREL(S+A) on page 23.

I will need to add the offset of the objects tls data. Currently it returns the offset within the objects data, but this will lead two objects pointing to the same data.

Two threads could call this if they both access the same thread local data concurrently. I'll change it to use a write lock to handle this case. Is the reloc_jmpslots case safe if I use the lock provided, or will I need to upgrade it to a write lock?

[1] http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056c/IHI0056C_beta_aaelf64.pdf

205

I think this will need to change to:
where[1] = obj->tlsindex + rela->r_addend;

256

Ok

libexec/rtld-elf/aarch64/reloc.c
175

I think I wanted something like die() in MIPS reloc.c too.

libexec/rtld-elf/aarch64/reloc.c
175

AFAIR, in MIPS case the use of die() is bogus.

Indeed, https://reviews.freebsd.org/D661

As usual, MIPS people do not care.

177

Re-using the provided lockstate should be fine. reloc_jmpslots() is called either by _rtld(), when the process is guaranteed to be single-threaded, or from the dlopen(). In the later case, rtld_bind_lock is write-locked.

What worries me somewhat, is the use of rtld_tlsdesc_handle() from rtld_tlsdesc_dynamic(). I suppose you would need one more wrapper.

libexec/rtld-elf/aarch64/reloc.c
175

Ah, indeed that is the change I was thinking about.

I have an update that should fix all the issues, but need to handle the symbol lookup failure case before pushing it here.

libexec/rtld-elf/aarch64/reloc.c
175

Is the above patch going in or do I need to do something similar here?

177

I have a fix for this, but an unable to push it as I need to decide how best to handle the case above where I need something like die().

libexec/rtld-elf/aarch64/reloc.c
175

I think you need to expose die(). Now, with the -fvisibility=hidden being used on x86, I am much less sensitive to making functions non-static.

You could consider setting hidden for aarch64.

libexec/rtld-elf/aarch64/reloc.c
175

I still think there's some value in renaming it _rtld_die too, from a grepability perspective. NetBSD's rtld for example calls it _rtld_die.

Update based on comments

I'm fine with this change but would like to have @kostikbel's sign-off.

No, please just expose die, probably as rtld_die(), without #ifdef hacks. If doing this, please make it a separate commit, which should be merged to stable/10 and 9.

That said, what I do not like right now is that dlopen() of somewhat incorrect dso would kill the process, instead of returning an error.

In D2183#16, @kostikbel wrote:

That said, what I do not like right now is that dlopen() of somewhat incorrect dso would kill the process, instead of returning an error.

How? We only look up the symbol when either we try to access it through _rtld_tlsdesc_dynamic, or when LD_BIND_NOW is set.

In D2183#17, @andrew wrote:
In D2183#16, @kostikbel wrote:

That said, what I do not like right now is that dlopen() of somewhat incorrect dso would kill the process, instead of returning an error.

How? We only look up the symbol when either we try to access it through _rtld_tlsdesc_dynamic, or when LD_BIND_NOW is set.

Never mind, I was confused.

andrew edited edge metadata.

Update for r281005

kib edited edge metadata.
This revision is now accepted and ready to land.Apr 2 2015, 10:06 PM
andrew updated this revision to Diff 4629.

Closed by commit rS281014 (authored by @andrew).