From 5459a1ece813abea5f6cef4d6deeee2d0ca4abba Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Sun, 28 Jun 2026 21:43:05 +0300 Subject: [PATCH 1/3] plt: fix regression of b714db721 [fixes #70] Remove leftover code that was forgotten... It was somehow "copied" into resolve_upl(), rather than being moved. Almost a year old regression, and so serious. Partially fixes ELFLOAD. --- src/libc/dj64/plt.S | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libc/dj64/plt.S b/src/libc/dj64/plt.S index 2c54b2d7..2bff2af3 100644 --- a/src/libc/dj64/plt.S +++ b/src/libc/dj64/plt.S @@ -312,12 +312,6 @@ plt_init: /* resolve upl */ movl %fs:STUBINFO_ELFLOAD_ARG, %eax call resolve_upl - // failure is not fatal, just no upl - jc 555f - // eax has uentry - movl $AUX_USER, %ebx - call uplt_init -555: movl $1, elfload jmp 11b 222: From b8cb3341fd679b0746122006ebbaaafc9b7f314a Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Sun, 28 Jun 2026 22:39:11 +0300 Subject: [PATCH 2/3] stubinfo: add SIFLG_ELFEXEC flag Clients can now check if they were loaded with ELFEXEC, or by mistake when executing self. --- include/libc/stubinfo.h | 2 ++ src/djdev64/stub/stub.c | 1 + 2 files changed, 3 insertions(+) diff --git a/include/libc/stubinfo.h b/include/libc/stubinfo.h index 79257341..f4f22293 100644 --- a/include/libc/stubinfo.h +++ b/include/libc/stubinfo.h @@ -74,4 +74,6 @@ _Static_assert(sizeof(_GO32_StubInfo) == STUBINFO_END, "size mismatch"); #endif #endif +#define SIFLG_ELFEXEC (1 << 16) + #endif /* __dj_include_stub_h__ */ diff --git a/src/djdev64/stub/stub.c b/src/djdev64/stub/stub.c index efefce7e..7ee6850c 100644 --- a/src/djdev64/stub/stub.c +++ b/src/djdev64/stub/stub.c @@ -321,6 +321,7 @@ int djstub_main(int argc, char *argv[], char *envp[], } if (el || ee) { done = 1; + stubinfo.flags |= SIFLG_ELFEXEC; break; } } From 1d93ae041ee1ff7f34f4316aea121396373dbdf3 Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Sun, 28 Jun 2026 23:00:30 +0300 Subject: [PATCH 3/3] stub: remove BARE_STUB() [#70] Not sure why it was needed. Instead just always set pl32 for stubless ELFs. --- src/djdev64/stub/stub.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/djdev64/stub/stub.c b/src/djdev64/stub/stub.c index 7ee6850c..11129c2c 100644 --- a/src/djdev64/stub/stub.c +++ b/src/djdev64/stub/stub.c @@ -227,7 +227,6 @@ int djstub_main(int argc, char *argv[], char *envp[], int dj32 = 0; struct dos_ops *ioops = dosops; uint8_t stub_ver = 0; -#define BARE_STUB() (stub_ver == 0) if (ver == 0) { /* backward-compat code */ @@ -267,6 +266,9 @@ int djstub_main(int argc, char *argv[], char *envp[], OPEN_DYN(); stubinfo.elfload_arg = atoi(envp[i] + l); dyn = 1; + /* Not setting emb_ov flags: pfile closed, no payload, + * second loader will re-check everything anyway. + * But we set pl32 below to reserve space for upl. */ } else { /* 32bit elf */ dj32 = 1; @@ -311,6 +313,7 @@ int djstub_main(int argc, char *argv[], char *envp[], dyn = 1; emb_ov = 1; + /* calling second ldr */ stubinfo.flags = ((STFLG2_EMBOV) << 8); stubinfo.flags |= SHM_FLAGS; nsize = dosops->_dos_seek(ifile, 0, SEEK_END); @@ -320,6 +323,7 @@ int djstub_main(int argc, char *argv[], char *envp[], } } if (el || ee) { + pl32 = 1; // even for ELFLOAD we reserve space for pl32 done = 1; stubinfo.flags |= SIFLG_ELFEXEC; break; @@ -409,11 +413,6 @@ int djstub_main(int argc, char *argv[], char *envp[], strncpy(stubinfo.payload2_name, &buf[0x2e], 12); stubinfo.payload2_name[12] = '\0'; strcat(stubinfo.payload2_name, ".dbg"); - } else if (BARE_STUB()) { - done = 1; - ops = &elf_ops; - assert(dyn && pl32); - pl32 = 0; } else { error("unsupported stub version %i\n", stub_ver); return -1; @@ -447,6 +446,7 @@ int djstub_main(int argc, char *argv[], char *envp[], pfile = ifile; ops = &elf_ops; } + pl32 = 1; } else if (is_64) { error("djstub: 64bit ELF at position %lx\n", coffset); return -1; @@ -523,7 +523,7 @@ int djstub_main(int argc, char *argv[], char *envp[], if (!dj32 && va_size > MB) exit(EXIT_FAILURE); /* if we load 2 payloads, use larger estimate */ - if ((dyn && pl32) || BARE_STUB() || compact_va) { + if ((dyn && pl32) || compact_va) { stubinfo.initial_size = VA_SZ; stubinfo.upl_base = va; stubinfo.upl_size = VA_SZ;