Skip to content

Commit

Permalink
options/rtdl: Fix alignment overhead computation for the TLS allocation
Browse files Browse the repository at this point in the history
The alignment overhead is used to properly align the TCB, which on x86_64
needs to be aligned to the max TLS block alignment so that accessing
blocks before it yields aligned addresses.

Fixes #960.
  • Loading branch information
qookei committed Dec 21, 2023
1 parent 5ea2031 commit b78244e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion options/rtdl/generic/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ Tcb *allocateTcb() {

// To make sure that both the TCB and TLS data are sufficiently aligned, allocate
// slightly more than necessary and adjust alignment afterwards.
size_t alignOverhead = frg::min(alignof(Tcb), tlsMaxAlignment);
size_t alignOverhead = frg::max(alignof(Tcb), tlsMaxAlignment);
size_t allocSize = tlsInitialSize + sizeof(Tcb) + alignOverhead;
auto allocation = reinterpret_cast<uintptr_t>(getAllocator().allocate(allocSize));
memset(reinterpret_cast<void *>(allocation), 0, allocSize);
Expand Down

0 comments on commit b78244e

Please sign in to comment.