2424
2525//#define DYLINK_DEBUG
2626
27+ #ifdef DYLINK_DEBUG
28+ #define dbg (fmt , ...) _emscripten_errf("%p: " fmt, pthread_self(), ##__VA_ARGS__)
29+ #else
30+ #define dbg (fmt , ...)
31+ #endif
32+
2733struct async_data {
2834 em_dlopen_callback onsuccess ;
2935 em_arg_callback_func onerror ;
@@ -66,16 +72,13 @@ int __dl_invalid_handle(void* h) {
6672}
6773
6874static void load_library_done (struct dso * p ) {
69- #ifdef DYLINK_DEBUG
70- _emscripten_errf ("%p: load_library_done: dso=%p mem_addr=%p mem_size=%zu "
71- "table_addr=%p table_size=%zu" ,
72- pthread_self (),
73- p ,
74- p -> mem_addr ,
75- p -> mem_size ,
76- p -> table_addr ,
77- p -> table_size );
78- #endif
75+ dbg ("load_library_done: dso=%p mem_addr=%p mem_size=%zu "
76+ "table_addr=%p table_size=%zu" ,
77+ p ,
78+ p -> mem_addr ,
79+ p -> mem_size ,
80+ p -> table_addr ,
81+ p -> table_size );
7982
8083 // insert into linked list
8184 p -> prev = tail ;
@@ -106,23 +109,18 @@ static struct dso* load_library_start(const char* name, int flags) {
106109}
107110
108111static void dlopen_js_onsuccess (struct dso * dso , struct async_data * data ) {
109- #ifdef DYLINK_DEBUG
110- _emscripten_errf ("%p: dlopen_js_onsuccess: dso=%p mem_addr=%p mem_size=%zu" ,
111- pthread_self (),
112- dso ,
113- dso -> mem_addr ,
114- dso -> mem_size );
115- #endif
112+ dbg ("dlopen_js_onsuccess: dso=%p mem_addr=%p mem_size=%zu" ,
113+ dso ,
114+ dso -> mem_addr ,
115+ dso -> mem_size );
116116 load_library_done (dso );
117117 pthread_rwlock_unlock (& lock );
118118 data -> onsuccess (data -> user_data , dso );
119119 free (data );
120120}
121121
122122static void dlopen_js_onerror (struct dso * dso , struct async_data * data ) {
123- #ifdef DYLINK_DEBUG
124- _emscripten_errf ("%p: dlopen_js_onerror: dso=%p" , pthread_self (), dso );
125- #endif
123+ dbg ("dlopen_js_onerror: dso=%p" , dso );
126124 pthread_rwlock_unlock (& lock );
127125 data -> onerror (data -> user_data );
128126 free (dso );
@@ -153,9 +151,7 @@ void* dlopen(const char* file, int flags) {
153151 if (!file ) {
154152 return head ;
155153 }
156- #ifdef DYLINK_DEBUG
157- _emscripten_errf ("%p: dlopen: %s [%d]" , pthread_self (), file , flags );
158- #endif
154+ dbg ("dlopen: %s [%d]" , file , flags );
159155
160156 struct dso * p ;
161157 int cs ;
@@ -165,9 +161,7 @@ void* dlopen(const char* file, int flags) {
165161 /* Search for the name to see if it's already loaded */
166162 for (p = head ; p ; p = p -> next ) {
167163 if (!strcmp (p -> name , file )) {
168- #ifdef DYLINK_DEBUG
169- _emscripten_errf ("%p: dlopen: already opened: %p" , pthread_self (), p );
170- #endif
164+ dbg ("dlopen: already opened: %p" , p );
171165 goto end ;
172166 }
173167 }
@@ -178,16 +172,12 @@ void* dlopen(const char* file, int flags) {
178172 }
179173 void * success = _dlopen_js (p );
180174 if (!success ) {
181- #ifdef DYLINK_DEBUG
182- _emscripten_errf ("%p: dlopen_js: failed: %p" , pthread_self (), p );
183- #endif
175+ dbg ("dlopen_js: failed: %p" , p );
184176 free (p );
185177 p = NULL ;
186178 goto end ;
187179 }
188- #ifdef DYLINK_DEBUG
189- _emscripten_errf ("%p: dlopen_js: success: %p" , pthread_self (), p );
190- #endif
180+ dbg ("dlopen_js: success: %p" , p );
191181 load_library_done (p );
192182end :
193183 pthread_rwlock_unlock (& lock );
@@ -216,17 +206,13 @@ void emscripten_dlopen(const char* filename, int flags, void* user_data,
216206 d -> onsuccess = onsuccess ;
217207 d -> onerror = onerror ;
218208
219- #ifdef DYLINK_DEBUG
220- _emscripten_errf ("%p: calling emscripten_dlopen_js %p" , pthread_self (), p );
221- #endif
209+ dbg ("calling emscripten_dlopen_js %p" , p );
222210 // Unlock happens in dlopen_js_onsuccess/dlopen_js_onerror
223211 _emscripten_dlopen_js (p , dlopen_js_onsuccess , dlopen_js_onerror , d );
224212}
225213
226214void * __dlsym (void * restrict p , const char * restrict s , void * restrict ra ) {
227- #ifdef DYLINK_DEBUG
228- _emscripten_errf ("%p: __dlsym dso:%p sym:%s" , pthread_self (), p , s );
229- #endif
215+ dbg ("__dlsym dso:%p sym:%s" , p , s );
230216 if (p != RTLD_DEFAULT && p != RTLD_NEXT && __dl_invalid_handle (p )) {
231217 return 0 ;
232218 }
@@ -259,9 +245,7 @@ void _emscripten_thread_sync_code() {
259245 syncing = true;
260246 ensure_init ();
261247 if (thread_local_tail == tail ) {
262- #ifdef DYLINK_DEBUG
263- _emscripten_errf ("%p: emscripten_thread_sync_code: already in sync" , pthread_self ());
264- #endif
248+ dbg ("emscripten_thread_sync_code: already in sync" );
265249 goto done ;
266250 }
267251 pthread_rwlock_rdlock (& lock );
@@ -270,16 +254,13 @@ void _emscripten_thread_sync_code() {
270254 }
271255 while (thread_local_tail -> next ) {
272256 struct dso * p = thread_local_tail -> next ;
273- #ifdef DYLINK_DEBUG
274- _emscripten_errf ("%p: emscripten_thread_sync_code: %s mem_addr=%p "
275- "mem_size=%zu table_addr=%p table_size=%zu" ,
276- pthread_self (),
277- p -> name ,
278- p -> mem_addr ,
279- p -> mem_size ,
280- p -> table_addr ,
281- p -> table_size );
282- #endif
257+ dbg ("emscripten_thread_sync_code: %s mem_addr=%p "
258+ "mem_size=%zu table_addr=%p table_size=%zu" ,
259+ p -> name ,
260+ p -> mem_addr ,
261+ p -> mem_size ,
262+ p -> table_addr ,
263+ p -> table_size );
283264 void * success = _dlopen_js (p );
284265 if (!success ) {
285266 // If any on the libraries fails to load here then we give up.
@@ -292,9 +273,7 @@ void _emscripten_thread_sync_code() {
292273 thread_local_tail = p ;
293274 }
294275 pthread_rwlock_unlock (& lock );
295- #ifdef DYLINK_DEBUG
296- _emscripten_errf ("%p: emscripten_thread_sync_code done" , pthread_self ());
297- #endif
276+ dbg ("emscripten_thread_sync_code done" );
298277
299278done :
300279 syncing = false;
0 commit comments