Skip to content

Commit

Permalink
posix,rtld: Make use of version in dlvsym
Browse files Browse the repository at this point in the history
  • Loading branch information
qookei committed Dec 27, 2024
1 parent 9ad4eea commit d72bf08
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 3 additions & 4 deletions options/posix/generic/dlfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct __dlapi_symbol {

extern "C" const char *__dlapi_error();
extern "C" void *__dlapi_open(const char *, int, void *);
extern "C" void *__dlapi_resolve(void *, const char *, void *);
extern "C" void *__dlapi_resolve(void *, const char *, void *, const char *);
extern "C" int __dlapi_reverse(const void *, __dlapi_symbol *);
extern "C" int __dlapi_close(void *);

Expand All @@ -36,14 +36,13 @@ void *dlopen(const char *file, int flags) {
[[gnu::noinline]]
void *dlsym(void *__restrict handle, const char *__restrict string) {
auto ra = __builtin_extract_return_addr(__builtin_return_address(0));
return __dlapi_resolve(handle, string, ra);
return __dlapi_resolve(handle, string, ra, NULL);
}

[[gnu::noinline]]
void *dlvsym(void *__restrict handle, const char *__restrict string, const char *__restrict version) {
mlibc::infoLogger() << "mlibc: dlvsym ignores version " << version << frg::endlog;
auto ra = __builtin_extract_return_addr(__builtin_return_address(0));
return __dlapi_resolve(handle, string, ra);
return __dlapi_resolve(handle, string, ra, version);
}

//gnu extensions
Expand Down
5 changes: 4 additions & 1 deletion options/rtld/generic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ void *__dlapi_open(const char *file, int flags, void *returnAddress) {
}

extern "C" [[ gnu::visibility("default") ]]
void *__dlapi_resolve(void *handle, const char *string, void *returnAddress) {
void *__dlapi_resolve(void *handle, const char *string, void *returnAddress, const char *version) {
if (logDlCalls) {
const char *name;
bool quote = false;
Expand All @@ -686,6 +686,9 @@ void *__dlapi_resolve(void *handle, const char *string, void *returnAddress) {
frg::optional<ObjectSymbol> target;
frg::optional<SymbolVersion> targetVersion = frg::null_opt;

if(version)
targetVersion = SymbolVersion{version};

if (handle == RTLD_DEFAULT) {
target = globalScope->resolveSymbol(string, 0, 0, targetVersion);
} else if (handle == RTLD_NEXT) {
Expand Down

0 comments on commit d72bf08

Please sign in to comment.