Skip to content

Commit

Permalink
Merge pull request #1049 from mintsuki/sysdeps-dlapi-enter
Browse files Browse the repository at this point in the history
sysdeps: Lyre/Ironclad: call __dlapi_enter() on entry
  • Loading branch information
mintsuki authored Apr 2, 2024
2 parents 8a02b79 + e1de211 commit 0c28bd8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 2 additions & 3 deletions sysdeps/ironclad/crt-x86_64/crt0.S
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

.section .text
.global _start
_start:
mov $main, %rdi
mov %rsp, %rdi
lea main(%rip), %rsi
call __mlibc_entry

.section .note.GNU-stack,"",%progbits

6 changes: 4 additions & 2 deletions sysdeps/ironclad/generic/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
void __mlibc_initLocale();

extern "C" uintptr_t *__dlapi_entrystack();
extern "C" void __dlapi_enter(uintptr_t *);

extern char **environ;
static mlibc::exec_stack_data __mlibc_stack_data;
Expand All @@ -27,8 +28,9 @@ LibraryGuard::LibraryGuard() {
__mlibc_stack_data.envp);
}

extern "C" void __mlibc_entry(int (*main_fn)(int argc, char *argv[], char *env[])) {
// TODO: call __dlapi_enter, otherwise static builds will break (see Linux sysdeps)
extern "C" void __mlibc_entry(uintptr_t *entry_stack, int (*main_fn)(int argc, char *argv[], char *env[])) {
__dlapi_enter(entry_stack);

auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ);
exit(result);
}
Expand Down
6 changes: 4 additions & 2 deletions sysdeps/lyre/generic/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
void __mlibc_initLocale();

extern "C" uintptr_t *__dlapi_entrystack();
extern "C" void __dlapi_enter(uintptr_t *);

extern char **environ;
static mlibc::exec_stack_data __mlibc_stack_data;
Expand Down Expand Up @@ -110,10 +111,11 @@ static void __mlibc_sigentry(int which, siginfo_t *siginfo,
__builtin_unreachable();
}

extern "C" void __mlibc_entry(int (*main_fn)(int argc, char *argv[], char *env[])) {
extern "C" void __mlibc_entry(uintptr_t *entry_stack, int (*main_fn)(int argc, char *argv[], char *env[])) {
__dlapi_enter(entry_stack);

//mlibc::sys_sigentry((void *)__mlibc_sigentry);

// TODO: call __dlapi_enter, otherwise static builds will break (see Linux sysdeps)
auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ);
exit(result);
}
Expand Down
3 changes: 2 additions & 1 deletion sysdeps/lyre/x86_64/crt-src/crt0.S
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.section .text
.global _start
_start:
mov $main, %rdi
mov %rsp, %rdi
lea main(%rip), %rsi
call __mlibc_entry
.section .note.GNU-stack,"",%progbits

0 comments on commit 0c28bd8

Please sign in to comment.