Skip to content

Commit 980fb4f

Browse files
committed
Add test for TypeIDs diverging between shared library and executable
When the shared library is built with symbol visibility hidden as the default, the type infos for any type is not available to anything that links to the library, and the library or executable will have its own copy of the type info, which is not merged. The results in emscripten::internal::TypeID having different TYPEID values depending on which module does the lookup, which causes trouble for embind's type registry as that's indexed on the TYPEIDs. Context: #16711
1 parent febd44b commit 980fb4f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/test_core.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5227,6 +5227,40 @@ def test_dylink_tls_export(self):
52275227
self.dylink_testf(test_file('core/test_dylink_tls_export.c'),
52285228
need_reverse=False)
52295229

5230+
@needs_dylink
5231+
@disabled('TypeID does not currently handle this')
5232+
def test_dylink_typeid(self):
5233+
# When the default visibility of the library's symbols is hidden,
5234+
# the type info is not merged, and we end up with different type
5235+
# ids in the shared library and the executable.
5236+
self.emcc_args.append('-fvisibility=hidden')
5237+
self.dylink_test(header=r'''
5238+
#include <emscripten/wire.h>
5239+
5240+
using namespace emscripten::internal;
5241+
struct SomeType {};
5242+
__attribute__((visibility("default"))) TYPEID getSomeTypeId();
5243+
''', main=r'''
5244+
#include "header.h"
5245+
#include <stdio.h>
5246+
5247+
int main() {
5248+
if (getSomeTypeId() != TypeID<SomeType>::get()) {
5249+
puts("type ids are not the same");
5250+
return 1;
5251+
}
5252+
puts("success");
5253+
return 0;
5254+
}
5255+
''', side=r'''
5256+
#include "header.h"
5257+
#include <stdio.h>
5258+
5259+
TYPEID getSomeTypeId() {
5260+
return TypeID<SomeType>::get();
5261+
}
5262+
''', expected=['success'], need_reverse=False, main_module=1)
5263+
52305264
def test_random(self):
52315265
src = r'''#include <stdlib.h>
52325266
#include <stdio.h>

0 commit comments

Comments
 (0)