Repository navigation
Commit e554292
0.16.1 --- the thread-local image is placed where the linker measured it (#33)
0.16.0 added this implementation's own storage for the region a context stands
on, and that storage made a latent defect of `src/tls.h` visible. Nothing about
the region is wrong; what is repaired is where the program's thread-local image
is copied.
EVERY THREAD-LOCAL ADDRESS IS `tp + st_value - tls_size', where `tls_size' is
the block the LINKER laid out: `p_memsz' rounded up to the segment's alignment.
`describe_tls' clamped that alignment up to sixteen before recording it, and the
clamp therefore reached the SIZE, which must not have it. Measured 2026-10-03 on
a segment stating `p_align = 8, p_memsz = 56': the linker put the variables at
`tp - 56' and the region was built 64 bytes deep, so the image sat eight bytes
below the variables that name it.
WHAT THAT LOOKS LIKE FROM ABOVE. Two thread-local variables, each declared with
a different value, read each other's bytes. And a C++ program's `thread_local`
object --- whose guard byte lives in the same image --- can find that byte
non-zero and never run its constructor at all: openkal-llvm-runtime's own probe
reported exactly that, on the runner, as `a thread_local is constructed in a
spawned thread: FAIL`.
WHY IT SURFACED NOW, STATED RATHER THAN GLOSSED. The defect is as old as the
clamp, and this implementation's own thread-local storage had been one four-byte
variable, which sits at the very end of the segment and was copied correctly by
luck. A twenty-four-byte one moved the image far enough to be read by the wrong
variable. The specification package's own kit test therefore passed throughout,
and the test that now observes this --- `tests/conformance_task_tls.cpp`, with a
non-zero initialiser and a four-kilobyte block --- was added by 0.16.0 and did
not catch it either, because the alignment it happened to be compiled with was
sixteen.
THE CLAMP NOW APPLIES TO THE ALLOCATION, WHICH WANTS SIXTEEN, AND NOT TO THE
SIZE, WHICH IS THE LINKER'S. `describe_tls' keeps the segment's alignment as the
loader stated it; `make_tls' rounds the size by that and asks the allocator for
sixteen. Verified against a probe of two initialised thread-local variables, in
the context the program started on and in a started one --- both now read their
own values --- by the kit, by this package's tests, by the conformance suite, and
by openkal-llvm-runtime's `examples/cxx', which is where the defect was seen.
Co-authored-by: sunrisepeak <sunbreaks@163.com>1 parent d1b2850 commit e554292
3 files changed
Lines changed: 55 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
88 | 105 | | |
89 | 106 | | |
90 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
57 | 76 | | |
58 | 77 | | |
59 | 78 | | |
| |||
91 | 110 | | |
92 | 111 | | |
93 | 112 | | |
94 | | - | |
| 113 | + | |
| 114 | + | |
95 | 115 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
102 | 122 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
110 | 131 | | |
111 | 132 | | |
112 | 133 | | |
| |||
0 commit comments