Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In #929 I incorrectly added a field, 'Indirect' to DTV, copying the structure of TSDInfo. I had believed it was necessary at the time, but on closer examination it doesn't seem to every be the case that it is used - DTV is always accessed Indirectly.
During the review of open-telemetry#1226, the first actual use of the DTV, nsavoire correctly pointed this out.
I could not find a single case where it was actually directly in the TCB and I think even for esoteric libc's it would likely still be indirect, as you need to be able to update it if new libs get added.
To simplify the usage, the
Indirectmember is removed from the DTV struct.My apologies for missing this and submitting incorrect code in the first place, as I've been switching tasks it has been difficult to keep the context in my head.
Proof that DTV is always accessed indirectly
glibc — TCB Structure & DTV Access
File: sysdeps/x86_64/nptl/tls.h (https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/nptl/tls.h;h=836b2e22440c0fb437444b6fca2dc677aae98eab;hb=6abe432ec4aa1456151be8f9567c4d68f41d68f7#l46)
The dtv field is a pointer (dtv_t *dtv) at offset 8 in the TCB. It is not an inline array. So FS:0x8 reads a pointer to the DTV, not DTV data itself.
DTV access macro (same file):
DTV allocation in elf/dl-tls.c (https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/dl-tls.c;h=edf31383b22ada95103d4c4be0aeda84a5e5e3ef;hb=6abe432ec4aa1456151be8f9567c4d68f41d68f7#l466):
__tls_get_addr in elf/dl-tls.c (https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/dl-tls.c;h=edf31383b22ada95103d4c4be0aeda84a5e5e3ef;hb=6abe432ec4aa1456151be8f9567c4d68f41d68f7#l1091):
THREAD_DTV() macro (https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/nptl/tls.h;h=836b2e22440c0fb437444b6fca2dc677aae98eab;hb=6abe432ec4aa1456151be8f9567c4d68f41d68f7#l166):
This reads header.dtv from the thread struct — i.e., loads the pointer.
musl — pthread struct & DTV Access
File: src/internal/pthread_impl.h (https://git.musl-libc.org/cgit/musl/tree/src/internal/pthread_impl.h?id=9fa28ece75d8a2191de7c5bb53bed224c5947417#n23)
The dtv field is uintptr_t *dtv — a pointer to a separately-allocated array.
DTV allocation in src/env/__init_tls.c (https://git.musl-libc.org/cgit/musl/tree/src/env/__init_tls.c?id=9fa28ece75d8a2191de7c5bb53bed224c5947417#n39):
DTV updates in ldso/dynlink.c (https://git.musl-libc.org/cgit/musl/tree/ldso/dynlink.c?id=9fa28ece75d8a2191de7c5bb53bed224c5947417#n1647):