Skip to content

Commit 9928b1d

Browse files
authored
Add dylink test to show weakly defined function issue. NFC (#13774)
Currently we don't support weakly defined functions that exist in both the main and the side module. See #13773
1 parent 02160f7 commit 9928b1d

4 files changed

+34
-0
lines changed

tests/core/test_dylink_weak_main.c

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <stdio.h>
2+
3+
void side();
4+
5+
__attribute__((weak)) int foo() {
6+
return 42;
7+
}
8+
9+
int main(int argc, char const *argv[]) {
10+
printf("main foo() -> %d\n", foo());
11+
side();
12+
return 0;
13+
}

tests/core/test_dylink_weak_main.out

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main foo() -> 42
2+
side foo() -> 42

tests/core/test_dylink_weak_side.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
3+
extern int foo();
4+
5+
__attribute__((weak)) int foo() {
6+
return 99;
7+
}
8+
9+
void side() {
10+
printf("side foo() -> %d\n", foo());
11+
}

tests/test_core.py

+8
Original file line numberDiff line numberDiff line change
@@ -4602,6 +4602,14 @@ def test_dylink_argv_argc(self):
46024602
expected='3 hello world!',
46034603
need_reverse=False)
46044604

4605+
@disabled('https://github.com/emscripten-core/emscripten/issues/13773')
4606+
def test_dylink_weak(self):
4607+
# Verify that weakly symbols can be defined in both side module and main
4608+
# module
4609+
main = test_file('core', 'test_dylink_weak_main.c')
4610+
side = test_file('core', 'test_dylink_weak_side.c')
4611+
self.dylink_testf(main, side, force_c=True, need_reverse=False)
4612+
46054613
def test_random(self):
46064614
src = r'''#include <stdlib.h>
46074615
#include <stdio.h>

0 commit comments

Comments
 (0)