Skip to content

Commit 4e95fbb

Browse files
authored
Improve test_dylink_tls. NFC (#14982)
Make TLS variables static which fixes a linker failure when building with `-g` (for example this test currently fails under wasm2g and wasm0g congigurations). Also, add two different TLS variables in each of the modules which helps with debugging since only one of them will be at TLS offset 0.
1 parent 5f55047 commit 4e95fbb

File tree

4 files changed

+41
-24
lines changed

4 files changed

+41
-24
lines changed

tests/core/test_dylink_tls.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdio.h>
2+
#include <threads.h>
3+
4+
static thread_local int foo = 10;
5+
static thread_local int bar = 11;
6+
7+
void sidey();
8+
9+
int get_foo() {
10+
return foo;
11+
}
12+
13+
int get_bar() {
14+
return bar;
15+
}
16+
17+
int main(int argc, char const *argv[]) {
18+
printf("main TLS: %d %d\n", get_foo(), get_bar());
19+
sidey();
20+
return 0;
21+
}

tests/core/test_dylink_tls.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main TLS: 10 11
2+
side TLS: 42 43

tests/core/test_dylink_tls_side.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
#include <threads.h>
3+
4+
static thread_local int baz = 42;
5+
static thread_local int wiz = 43;
6+
7+
int get_baz() {
8+
return baz;
9+
}
10+
11+
int get_wiz() {
12+
return wiz;
13+
}
14+
15+
void sidey() {
16+
printf("side TLS: %d %d\n", get_baz(), get_wiz());
17+
}

tests/test_core.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4592,31 +4592,8 @@ def test_dylink_tls(self):
45924592

45934593
# TODO(sbc): Add tests that depend on importing/exported TLS symbols
45944594
# once we figure out how to do that.
4595-
create_file('main.c', r'''
4596-
#include <stdio.h>
4597-
4598-
_Thread_local int foo = 10;
4599-
4600-
void sidey();
4601-
4602-
int main(int argc, char const *argv[]) {
4603-
printf("main TLS: %d\n", foo);
4604-
sidey();
4605-
return 0;
4606-
}
4607-
''')
4608-
create_file('side.c', r'''
4609-
#include <stdio.h>
4610-
4611-
_Thread_local int bar = 11;
4612-
4613-
void sidey() {
4614-
printf("side TLS: %d\n", bar);
4615-
}
4616-
''')
46174595
self.emcc_args.append('-Wno-experimental')
4618-
self.dylink_testf('main.c', 'side.c',
4619-
expected='main TLS: 10\nside TLS: 11\n',
4596+
self.dylink_testf(test_file('core/test_dylink_tls.c'), test_file('core/test_dylink_tls_side.c'),
46204597
need_reverse=False)
46214598

46224599
def test_random(self):

0 commit comments

Comments
 (0)