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

Symbol versioning support #1209

Merged
merged 9 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions options/elf/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ typedef struct {
Elf64_Word vda_next; /* Offset in bytes to next verdaux entry */
} Elf64_Verdaux;

typedef struct {
Elf32_Half vn_version;
Elf32_Half vn_cnt;
Elf32_Word vn_file;
Elf32_Word vn_aux;
Elf32_Word vn_next;
} Elf32_Verneed;

typedef struct {
Elf64_Half vn_version;
Elf64_Half vn_cnt;
Expand All @@ -119,6 +127,14 @@ typedef struct {
Elf64_Word vn_next;
} Elf64_Verneed;

typedef struct {
Elf32_Word vna_hash;
Elf32_Half vna_flags;
Elf32_Half vna_other;
Elf32_Word vna_name;
Elf32_Word vna_next;
} Elf32_Vernaux;

typedef struct {
Elf64_Word vna_hash;
Elf64_Half vna_flags;
Expand Down Expand Up @@ -670,6 +686,10 @@ typedef struct {
#define AT_GID 13
#define AT_EGID 14

/* Values for Elfxx_Verdef::vd_flags and Elfxx_Vernaux::vna_flags */
#define VER_FLG_BASE 1 /* Version definition of the file itself */
#define VER_FLG_WEAK 2 /* Weak version identifier */

/* rtld requires presence of some a_type (AT_*) values that are not standardized in the ELF spec */
#if !defined(AT_EXECFN) || !defined(AT_RANDOM) || !defined(AT_SECURE)
#error "sysdeps' auxv.h is missing some defines that are required for rtld operation"
Expand Down
4 changes: 2 additions & 2 deletions options/internal/aarch64-include/mlibc/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace mlibc {
inline Tcb *get_current_tcb() {
// On AArch64, TPIDR_EL0 points to 0x10 bytes before the first TLS block.
uintptr_t ptr;
asm ("mrs %0, tpidr_el0" : "=r"(ptr));
asm volatile ("mrs %0, tpidr_el0" : "=r"(ptr));
return reinterpret_cast<Tcb *>(ptr + 0x10 - sizeof(Tcb));
}

inline uintptr_t get_sp() {
uintptr_t sp;
asm ("mov %0, sp" : "=r"(sp));
asm volatile ("mov %0, sp" : "=r"(sp));
return sp;
}

Expand Down
2 changes: 1 addition & 1 deletion options/internal/m68k-include/mlibc/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ inline Tcb *get_current_tcb() {

inline uintptr_t get_sp() {
uintptr_t sp;
asm ("move.l %%sp, %0" : "=r"(sp));
asm volatile ("move.l %%sp, %0" : "=r"(sp));
return sp;
}

Expand Down
2 changes: 1 addition & 1 deletion options/internal/riscv64-include/mlibc/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ inline Tcb *get_current_tcb() {

inline uintptr_t get_sp() {
uintptr_t sp;
asm ("mv %0, sp" : "=r"(sp));
asm volatile ("mv %0, sp" : "=r"(sp));
return sp;
}

Expand Down
4 changes: 2 additions & 2 deletions options/internal/x86-include/mlibc/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace mlibc {

inline Tcb *get_current_tcb() {
uintptr_t ptr;
asm ("movl %%gs:0, %0" : "=r"(ptr));
asm volatile ("movl %%gs:0, %0" : "=r"(ptr));
return reinterpret_cast<Tcb *>(ptr);
}

inline uintptr_t get_sp() {
uintptr_t esp;
asm ("mov %%esp, %0" : "=r"(esp));
asm volatile ("mov %%esp, %0" : "=r"(esp));
return esp;
}

Expand Down
4 changes: 2 additions & 2 deletions options/internal/x86_64-include/mlibc/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace mlibc {

inline Tcb *get_current_tcb() {
uintptr_t ptr;
asm ("movq %%fs:0, %0" : "=r"(ptr));
asm volatile ("movq %%fs:0, %0" : "=r"(ptr));
return reinterpret_cast<Tcb *>(ptr);
}

inline uintptr_t get_sp() {
uintptr_t rsp;
asm ("mov %%rsp, %0" : "=r"(rsp));
asm volatile ("mov %%rsp, %0" : "=r"(rsp));
return rsp;
}

Expand Down
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
6 changes: 6 additions & 0 deletions options/rtld/aarch64/elf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ using elf_addr = Elf64_Addr;
using elf_info = Elf64_Xword;
using elf_addend = Elf64_Sxword;

using elf_version = Elf64_Half;
using elf_verdef = Elf64_Verdef;
using elf_verdaux = Elf64_Verdaux;
using elf_verneed = Elf64_Verneed;
using elf_vernaux = Elf64_Vernaux;

#define ELF_R_SYM ELF64_R_SYM
#define ELF_R_TYPE ELF64_R_TYPE
#define ELF_ST_BIND ELF64_ST_BIND
Expand Down
Loading
Loading