Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add stubs for dlopen, dlsym, etc. #443

Merged
merged 5 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ LIBC_TOP_HALF_MUSL_SOURCES = \
misc/a64l.c \
misc/basename.c \
misc/dirname.c \
misc/dl.c \
misc/ffs.c \
misc/ffsl.c \
misc/ffsll.c \
Expand Down Expand Up @@ -445,7 +446,6 @@ MUSL_OMIT_HEADERS += \
"netdb.h" \
"resolv.h" \
"pty.h" \
"dlfcn.h" \
"setjmp.h" \
"ulimit.h" \
"sys/xattr.h" \
Expand Down
4 changes: 4 additions & 0 deletions expected/wasm32-wasi-threads/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ difftime
dirfd
dirname
div
dlclose
dlerror
dlopen
dlsym
dprintf
drand48
drem
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasi-threads/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include <crypt.h>
#include <ctype.h>
#include <dirent.h>
#include <dlfcn.h>
#include <endian.h>
#include <err.h>
#include <errno.h>
Expand Down
10 changes: 10 additions & 0 deletions expected/wasm32-wasi-threads/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,15 @@
#define RRFIXEDSZ NS_RRFIXEDSZ
#define RRQ 01
#define RS_HIPRI 0x01
#define RTLD_DEFAULT ((void *)0)
#define RTLD_DI_LINKMAP 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this make sense w/o dlinfo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dicej ping

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't know why this is defined unconditionally in dlfcn.h. We could move it into the #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) block in that file if desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed an update to address this.

#define RTLD_GLOBAL 256
#define RTLD_LAZY 1
#define RTLD_LOCAL 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it straightforward to use a non-zero value?
an implementation can still choose to ignore it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dicej ping

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't notice these comments earlier. The values in these files come straight from libc-top-half/musl/include/dlfcn.h, which appears to remain unchanged since it was imported from musl libc. glibc seems to use the same values for these constants also. I'm not necessarily opposed to changing the values, but sticking with the musl values seems like a safe default here.

Copy link
Contributor Author

@dicej dicej Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today I learned that RTLD_GLOBAL is the default on MacOS, but RTLD_LOCAL is the default on Linux (which I guess is why RTLD_LOCAL is zero on musl and glibc but nonzero on MacOS). I guess we ought to decide that the default should be for wasi-libc if we ever ship more than a stub implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless you want to decide the default right now, we can postpone the decision by making it a non-zero value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed an update changing it to a non-zero value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand how we can make both of these non-zero. This is a binary choice between global or local symbol binding, its not possible to choose neither. The question is what the default should be when neither is specified and the answer has to be one or the other.

I suggest we go with that musl's defaults for now given that we are largely a port of musl here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, I understand now. Please ignore my last comment. Having RTLD_LOCAL and RTLD_GLOBAL both be non-zero allows the implementation to detect the default case and choose one or the other at runtime. SGTM

#define RTLD_NEXT ((void *)-1)
#define RTLD_NODELETE 4096
#define RTLD_NOLOAD 4
#define RTLD_NOW 2
#define RUSAGE_CHILDREN 2
#define RUSAGE_SELF 1
#define R_OK (4)
Expand Down Expand Up @@ -2044,6 +2053,7 @@
#define _Complex_I (0.0f+1.0fi)
#define _DIRENT_H
#define _DIRENT_HAVE_D_TYPE
#define _DLFCN_H
#define _ENDIAN_H
#define _ERRNO_H
#define _ERR_H
Expand Down
4 changes: 4 additions & 0 deletions expected/wasm32-wasi/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ difftime
dirfd
dirname
div
dlclose
dlerror
dlopen
dlsym
dprintf
drand48
drem
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasi/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include <crypt.h>
#include <ctype.h>
#include <dirent.h>
#include <dlfcn.h>
#include <endian.h>
#include <err.h>
#include <errno.h>
Expand Down
10 changes: 10 additions & 0 deletions expected/wasm32-wasi/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,15 @@
#define RRFIXEDSZ NS_RRFIXEDSZ
#define RRQ 01
#define RS_HIPRI 0x01
#define RTLD_DEFAULT ((void *)0)
#define RTLD_DI_LINKMAP 2
#define RTLD_GLOBAL 256
#define RTLD_LAZY 1
#define RTLD_LOCAL 0
#define RTLD_NEXT ((void *)-1)
#define RTLD_NODELETE 4096
#define RTLD_NOLOAD 4
#define RTLD_NOW 2
#define RUSAGE_CHILDREN 2
#define RUSAGE_SELF 1
#define R_OK (4)
Expand Down Expand Up @@ -2010,6 +2019,7 @@
#define _Complex_I (0.0f+1.0fi)
#define _DIRENT_H
#define _DIRENT_HAVE_D_TYPE
#define _DLFCN_H
#define _ENDIAN_H
#define _ERRNO_H
#define _ERR_H
Expand Down
31 changes: 31 additions & 0 deletions libc-top-half/musl/src/misc/dl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdint.h>
dicej marked this conversation as resolved.
Show resolved Hide resolved
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>

#define EXPORT __attribute__((visibility("default"))) __attribute__((used))
dicej marked this conversation as resolved.
Show resolved Hide resolved
#define WEAK __attribute__((__weak__))
dicej marked this conversation as resolved.
Show resolved Hide resolved

static const char *error = 0;
dicej marked this conversation as resolved.
Show resolved Hide resolved

EXPORT WEAK int dlclose(void *library) {
error = "dlclose not implemented";
dicej marked this conversation as resolved.
Show resolved Hide resolved
return -1;
}

EXPORT WEAK char *dlerror(void) {
const char *var = error;
error = 0;
return (char*) var;
}

EXPORT WEAK void *dlopen(const char *name, int flags) {
error = "dlopen not implemented";
return 0;
}

EXPORT WEAK void *dlsym(void *library, const char *name) {
error = "dlsym not implemented";
return 0;
}