Fix mips stub for ELF2 main program

modified:   p_lx_elf.cpp
	modified:   stub/Makefile
	modified:   stub/src/mips.r3000-expand.S
	modified:   stub/src/upxfd_linux.c
This commit is contained in:
John Reiser 2024-11-20 15:02:32 -08:00
parent 02b9ac9764
commit 76b0b4ce9c
4 changed files with 25 additions and 8 deletions

View File

@ -1533,6 +1533,9 @@ PackLinuxElf32::buildLinuxLoader(
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", len += snprintf(&sec[len], sizeof(sec) - len, ",%s",
(opt->o_unix.android_old ? "UMF_ANDROID" : "UMF_LINUX")); (opt->o_unix.android_old ? "UMF_ANDROID" : "UMF_LINUX"));
} }
else {
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "UMF_LINUX");
}
if (hasLoaderSection("SYSCALLS")) { if (hasLoaderSection("SYSCALLS")) {
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "SYSCALLS"); len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "SYSCALLS");
} }

View File

@ -1596,7 +1596,7 @@ tmp/mips.r3000-linux.upxfd_android.s: $(srcdir)/src/upxfd_android.c
$(call tc,gcc) -S -D__mips__ \ $(call tc,gcc) -S -D__mips__ \
-D_TARGET_LINUX_ -DNO_WANT_MMAP -O $< -o - \ -D_TARGET_LINUX_ -DNO_WANT_MMAP -O $< -o - \
| sed -e '/^\t\.file\t/d' \ | sed -e '/^\t\.file\t/d' \
-e 's/L[0-9]*/L8&/g' \ -e 's/L[0-9][0-9]*/L8&/g' \
-e $$(cat src/dollar-dollar.sed) \ -e $$(cat src/dollar-dollar.sed) \
-e 's/ j[ ][ ]*$$L/ b $$L/' \ -e 's/ j[ ][ ]*$$L/ b $$L/' \
-e 's/ jal[ ][ ]*\([^\$$]\)/ bal \1/' \ -e 's/ jal[ ][ ]*\([^\$$]\)/ bal \1/' \
@ -1607,7 +1607,7 @@ tmp/mips.r3000-linux.upxfd_linux.s: $(srcdir)/src/upxfd_linux.c
$(call tc,gcc) -S -D__mips__ \ $(call tc,gcc) -S -D__mips__ \
-D_TARGET_LINUX_ -DNO_WANT_MMAP -O $< -o - \ -D_TARGET_LINUX_ -DNO_WANT_MMAP -O $< -o - \
| sed -e '/^\t\.file\t/d' \ | sed -e '/^\t\.file\t/d' \
-e 's/L[0-9]*/L8&/g' \ -e 's/L[0-9][0-9]*/L9&/g' \
-e $$(cat src/dollar-dollar.sed) \ -e $$(cat src/dollar-dollar.sed) \
-e 's/ j[ ][ ]*$$L/ b $$L/' \ -e 's/ j[ ][ ]*$$L/ b $$L/' \
-e 's/ jal[ ][ ]*\([^\$$]\)/ bal \1/' \ -e 's/ jal[ ][ ]*\([^\$$]\)/ bal \1/' \
@ -1617,7 +1617,7 @@ tmp/mips.r3000-linux.elf-main2.s: $(srcdir)/src/$$T.c $(srcdir)/src/i386-linux.e
@echo; echo TARGET: $@; echo @echo; echo TARGET: $@; echo
$(call tc,gcc) -S -D__mips__ -D_TARGET_LINUX_ -O $< -o - \ $(call tc,gcc) -S -D__mips__ -D_TARGET_LINUX_ -O $< -o - \
| sed -e '/^\t\.file\t/d' \ | sed -e '/^\t\.file\t/d' \
-e 's/L[0-9]*/L7&/g' \ -e 's/L[0-9][0-9]*/L7&/g' \
-e $$(cat src/dollar-dollar.sed) \ -e $$(cat src/dollar-dollar.sed) \
-e 's/ j[ ][ ]*$$L/ b $$L/' \ -e 's/ j[ ][ ]*$$L/ b $$L/' \
-e 's/ jal[ ][ ]*\([^\$$]\)/ bal \1/' \ -e 's/ jal[ ][ ]*\([^\$$]\)/ bal \1/' \
@ -1724,8 +1724,10 @@ tmp/mipsel.r3000-linux.upxfd_linux.s: $(srcdir)/src/upxfd_linux.c
@echo; echo TARGET: $@; echo @echo; echo TARGET: $@; echo
$(call tc,gcc) -S -D__mipsel__ \ $(call tc,gcc) -S -D__mipsel__ \
-D_TARGET_LINUX_ -DNO_WANT_MMAP -O $< -o - \ -D_TARGET_LINUX_ -DNO_WANT_MMAP -O $< -o - \
| tee foo-mipsel.r3000-linux.upxfd_linux.s \
| sed -e '/^\t\.file\t/d' \ | sed -e '/^\t\.file\t/d' \
-e 's/L[0-9]*/L8&/g' \ -e '/^\t*\.text/s//.section UMF_LINUX/' \
-e 's/L[0-9][0-9]*/L9&/g' \
-e $$(cat src/dollar-dollar.sed) \ -e $$(cat src/dollar-dollar.sed) \
-e 's/ j[ ][ ]*$$L/ b $$L/' \ -e 's/ j[ ][ ]*$$L/ b $$L/' \
-e 's/ jal[ ][ ]*\([^\$$]\)/ bal \1/' \ -e 's/ jal[ ][ ]*\([^\$$]\)/ bal \1/' \

View File

@ -154,10 +154,6 @@ eof_n2b: .globl eof_n2b
go_decompr: go_decompr:
// sections NRV2B, etc, inserted here by addLoader() from ::buildLinuxLoader() // sections NRV2B, etc, inserted here by addLoader() from ::buildLinuxLoader()
.balign 4
upx_mmap_and_fd: .globl upx_mmap_and_fd
// UMF_ANDROID or UMF_LINUX must be loaded after EXP_TAIL
section EXP_TAIL section EXP_TAIL
#define M_NRV2B_LE32 2 #define M_NRV2B_LE32 2
#define M_NRV2B_8 3 #define M_NRV2B_8 3
@ -174,6 +170,10 @@ upx_mmap_and_fd: .globl upx_mmap_and_fd
unfilter: unfilter:
//#include "arch/mips/r3000/bxx.S" // unfilter code; args in registers, fall-through return //#include "arch/mips/r3000/bxx.S" // unfilter code; args in registers, fall-through return
.balign 4
upx_mmap_and_fd: .globl upx_mmap_and_fd
// UMF_ANDROID or UMF_LINUX must be loaded after EXP_TAIL
// FIXME: will need extra parameter for multi-method decompression // FIXME: will need extra parameter for multi-method decompression
#define NO_METHOD_CHECK 0 #define NO_METHOD_CHECK 0

View File

@ -6,6 +6,8 @@
All Rights Reserved. All Rights Reserved.
*/ */
extern void my_bkpt(void const *, ...);
#if defined(__i386__) //}{ #if defined(__i386__) //}{
#define ANDROID_FRIEND 1 #define ANDROID_FRIEND 1
#define addr_string(string) ({ \ #define addr_string(string) ({ \
@ -76,12 +78,22 @@
#define ANDROID_FRIEND 0 #define ANDROID_FRIEND 0
#error addr_string #error addr_string
#endif //} #endif //}
#ifdef __mips__ //{
#define NO_WANT_READ 1
#define NO_WANT_CLOSE 1
#define NO_WANT_MPROTECT 1
#endif //}
#include "include/linux.h" // syscall decls; i386 inlines via "int 0x80" #include "include/linux.h" // syscall decls; i386 inlines via "int 0x80"
#define MFD_EXEC 0x10 #define MFD_EXEC 0x10
//#define O_RDWR 2 //#define O_RDWR 2
#define O_DIRECTORY 0200000 /* 0x010000 asm-generic/fcntl.h */ #define O_DIRECTORY 0200000 /* 0x010000 asm-generic/fcntl.h */
#define O_TMPFILE 020000000 /* 0x400000 asm-generic/fcntl.h */ #define O_TMPFILE 020000000 /* 0x400000 asm-generic/fcntl.h */
#define EINVAL 22 /* asm-generic/errno-base.h */ #define EINVAL 22 /* asm-generic/errno-base.h */
extern int memfd_create(char const *, unsigned);
extern int ftruncate(int, size_t);
// Implementation for Linux-native, where memfd_create // Implementation for Linux-native, where memfd_create
// (or /dev/shm) works. Saves space in contrast to // (or /dev/shm) works. Saves space in contrast to
// upxfd_android (or Android emulator), which must // upxfd_android (or Android emulator), which must