@@ -4102,29 +4102,46 @@ def test_dlfcn_asyncify(self):
4102
4102
4103
4103
@needs_dylink
4104
4104
def test_dlfcn_rtld_local (self ):
4105
+ # Create two shared libraries that both depend on a third.
4106
+ # liba.so -> libsub.so
4107
+ # libb.so -> libsub.so
4105
4108
create_file ('liba.c' , r'''
4106
4109
#include <stdio.h>
4107
4110
4108
- void func_b ();
4111
+ void func_sub ();
4109
4112
4110
4113
void func_a() {
4111
4114
printf("func_a\n");
4112
4115
// Call a function from a dependent DSO. This symbol should
4113
4116
// be available here even though liba itself is loaded with RTLD_LOCAL.
4114
- func_b ();
4117
+ func_sub ();
4115
4118
}
4116
4119
''' )
4117
4120
4118
4121
create_file ('libb.c' , r'''
4119
4122
#include <stdio.h>
4120
4123
4124
+ void func_sub();
4125
+
4121
4126
void func_b() {
4122
4127
printf("func_b\n");
4128
+ // Call a function from a dependent DSO. This symbol should
4129
+ // be available here even though liba itself is loaded with RTLD_LOCAL.
4130
+ func_sub();
4131
+ }
4132
+ ''' )
4133
+
4134
+ create_file ('libsub.c' , r'''
4135
+ #include <stdio.h>
4136
+
4137
+ void func_sub() {
4138
+ printf("func_sub\n");
4123
4139
}
4124
4140
''' )
4125
4141
4126
- self .build_dlfcn_lib ('libb.c' , outfile = 'libb.so' )
4127
- self .build_dlfcn_lib ('liba.c' , outfile = 'liba.so' , emcc_args = ['libb.so' ])
4142
+ self .build_dlfcn_lib ('libsub.c' , outfile = 'libsub.so' )
4143
+ self .build_dlfcn_lib ('libb.c' , outfile = 'libb.so' , emcc_args = ['libsub.so' ])
4144
+ self .build_dlfcn_lib ('liba.c' , outfile = 'liba.so' , emcc_args = ['libsub.so' ])
4128
4145
4129
4146
self .prep_dlfcn_main (['liba.so' , 'libb.so' , '-L.' ])
4130
4147
create_file ('main.c' , r'''
@@ -4133,28 +4150,41 @@ def test_dlfcn_rtld_local(self):
4133
4150
#include <stdio.h>
4134
4151
4135
4152
int main() {
4153
+ void* handle;
4154
+ void (*f)();
4155
+
4136
4156
printf("main\n");
4137
- void* handle = dlopen("liba.so", RTLD_NOW|RTLD_LOCAL);
4157
+ // Call a function from libb
4158
+ handle = dlopen("liba.so", RTLD_NOW|RTLD_LOCAL);
4138
4159
assert(handle);
4139
4160
4140
- void (*f)();
4141
4161
f = dlsym(handle, "func_a");
4142
4162
assert(f);
4143
4163
f();
4144
4164
4145
- // Verify that symbols from liba.so and libb.so are not globally
4165
+ // Same for libb
4166
+ handle = dlopen("libb.so", RTLD_NOW|RTLD_LOCAL);
4167
+ assert(handle);
4168
+
4169
+ f = dlsym(handle, "func_b");
4170
+ assert(f);
4171
+ f();
4172
+
4173
+ // Verify that symbols from all three libraries are not globally
4146
4174
// visible.
4147
- void* func_a = dlsym(RTLD_DEFAULT, "func_a");
4148
- assert(func_a == NULL);
4149
- void* func_b = dlsym(RTLD_DEFAULT, "func_b");
4150
- assert(func_b == NULL);
4175
+ f = dlsym(RTLD_DEFAULT, "func_a");
4176
+ assert(f == NULL);
4177
+ f = dlsym(RTLD_DEFAULT, "func_b");
4178
+ assert(f == NULL);
4179
+ f = dlsym(RTLD_DEFAULT, "func_sub");
4180
+ assert(f == NULL);
4151
4181
4152
4182
printf("done\n");
4153
4183
return 0;
4154
4184
}
4155
4185
''' )
4156
4186
4157
- self .do_runf ('main.c' , 'main\n func_a\n func_b\n done\n ' )
4187
+ self .do_runf ('main.c' , 'main\n func_a\n func_sub \ n func_b\n func_sub \n done\n ' )
4158
4188
4159
4189
def dylink_test (self , main , side , expected = None , header = None , force_c = False ,
4160
4190
main_module = 2 , ** kwargs ):
0 commit comments