Skip to content

Commit 75c7902

Browse files
authored
Use musl's stub implementation of dladdr. NFC (#19319)
1 parent 9119428 commit 75c7902

File tree

7 files changed

+11
-28
lines changed

7 files changed

+11
-28
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.38 (in development)
2222
-----------------------
23+
- The `dladdr` function will now always return an error rather than filling in
24+
dummy values. (#19319)
2325
- The restriction preventing the use of dynamic linking in combination with
2426
`-sDYNAMIC_EXECUTION=0` was removed. This restriction was being enforced
2527
unnecessarily since dynamic linking has not depended on `eval()` for a while

src/library_dylink.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ var LibraryDylink = {
281281
dlopen__deps: [function() { error(dlopenMissingError); }],
282282
emscripten_dlopen__deps: [function() { error(dlopenMissingError); }],
283283
__dlsym__deps: [function() { error(dlopenMissingError); }],
284-
dladdr__deps: [function() { error(dlopenMissingError); }],
285284
#else
286285
$dlopenMissingError: `= ${dlopenMissingError}`,
287286
_dlopen_js__deps: ['$dlopenMissingError'],
@@ -291,7 +290,6 @@ var LibraryDylink = {
291290
dlopen__deps: ['$dlopenMissingError'],
292291
emscripten_dlopen__deps: ['$dlopenMissingError'],
293292
__dlsym__deps: ['$dlopenMissingError'],
294-
dladdr__deps: ['$dlopenMissingError'],
295293
#endif
296294
_dlopen_js: function(handle) {
297295
abort(dlopenMissingError);
@@ -314,9 +312,6 @@ var LibraryDylink = {
314312
__dlsym: function(handle, symbol) {
315313
abort(dlopenMissingError);
316314
},
317-
dladdr: function() {
318-
abort(dlopenMissingError);
319-
},
320315
#else // MAIN_MODULE != 0
321316
// dynamic linker/loader (a-la ld.so on ELF systems)
322317
$LDSO__deps: ['$newDSO'],

src/library_sigs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ sigs = {
461461
boxRGBA__sig: 'ipiiiiiiii',
462462
clock_res_get__sig: 'iip',
463463
clock_time_get__sig: 'iijp',
464-
dladdr__sig: 'ipp',
465464
dlopen__sig: 'ppi',
466465
eglBindAPI__sig: 'ii',
467466
eglChooseConfig__sig: 'ipppip',

system/lib/libc/dynlink.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,13 +584,3 @@ void* __dlsym(void* restrict p, const char* restrict s, void* restrict ra) {
584584
do_write_unlock();
585585
return res;
586586
}
587-
588-
int dladdr(const void* addr, Dl_info* info) {
589-
// report all function pointers as coming from this program itself XXX not
590-
// really correct in any way
591-
info->dli_fname = "unknown";
592-
info->dli_fbase = NULL;
593-
info->dli_sname = NULL;
594-
info->dli_saddr = NULL;
595-
return 1;
596-
}

test/test_core.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3671,17 +3671,12 @@ def test_dlfcn_info(self):
36713671
/* Verify that we don't corrupt func_ptr when calling dladdr. */
36723672
Dl_info info;
36733673
memset(&info, 0, sizeof(info));
3674-
dladdr(func_ptr, &info);
3674+
int rtn = dladdr(func_ptr, &info);
3675+
assert(rtn == 0);
36753676
36763677
assert(func_ptr != NULL);
36773678
assert(func_ptr(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) == 13);
36783679
3679-
/* Verify something useful lives in info. */
3680-
assert(info.dli_fname != NULL);
3681-
assert(info.dli_fbase == NULL);
3682-
assert(info.dli_sname == NULL);
3683-
assert(info.dli_saddr == NULL);
3684-
36853680
puts("success");
36863681
36873682
return 0;

test/test_other.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12227,17 +12227,19 @@ def test_unimplemented_syscalls_dlopen(self):
1222712227

1222812228
def test_unimplemented_syscalls_dladdr(self):
1222912229
create_file('main.c', '''
12230+
#include <assert.h>
1223012231
#include <dlfcn.h>
1223112232

1223212233
int main() {
12233-
dladdr(0, 0);
12234+
Dl_info info;
12235+
int rtn = dladdr(&main, &info);
12236+
assert(rtn == 0);
1223412237
return 0;
1223512238
}
1223612239
''')
1223712240

12238-
self.run_process([EMCC, 'main.c'])
12239-
err = self.run_js('a.out.js', assert_returncode=NON_ZERO)
12240-
self.assertContained('Aborted(To use dlopen, you need enable dynamic linking, see https://emscripten.org/docs/compiling/Dynamic-Linking.html)', err)
12241+
self.do_runf('main.c')
12242+
self.do_runf('main.c', emcc_args=['-sMAIN_MODULE=2'])
1224112243

1224212244
@requires_v8
1224312245
def test_missing_shell_support(self):

tools/system_libs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ def get_files(self):
11731173

11741174
libc_files += files_in_path(
11751175
path='system/lib/libc/musl/src/ldso',
1176-
filenames=['dlerror.c', 'dlsym.c', 'dlclose.c'])
1176+
filenames=['dladdr.c', 'dlerror.c', 'dlsym.c', 'dlclose.c'])
11771177

11781178
libc_files += files_in_path(
11791179
path='system/lib/libc/musl/src/signal',

0 commit comments

Comments
 (0)