From 279ffeeefaffa3dab2f022cf8992874bf3fef97a Mon Sep 17 00:00:00 2001 From: John Reiser Date: Wed, 17 Nov 2010 14:32:24 -0800 Subject: [PATCH] unify DEBUG STR_* into i386-linux.elf-main.c from *.elf-fold.S --- src/stub/src/arm-darwin.macho-fold.S | 56 ------------------- src/stub/src/arm-linux.elf-fold.S | 55 +------------------ src/stub/src/i386-bsd.elf-fold.S | 50 ----------------- src/stub/src/i386-linux.elf-fold.S | 51 ----------------- src/stub/src/i386-linux.elf-main.c | 52 ++++++++++++++---- src/stub/src/mipsel.r3000-linux.elf-fold.S | 61 --------------------- src/stub/tmp/i386-netbsd.elf-fold.bin | Bin 1801 -> 1801 bytes 7 files changed, 43 insertions(+), 282 deletions(-) diff --git a/src/stub/src/arm-darwin.macho-fold.S b/src/stub/src/arm-darwin.macho-fold.S index 2179738f..ec11bb57 100644 --- a/src/stub/src/arm-darwin.macho-fold.S +++ b/src/stub/src/arm-darwin.macho-fold.S @@ -226,61 +226,5 @@ bswap9: bge bswap0 ret -#if 0 /*{ "gcc-3.4 -fPIC" botches string constants when code moves! */ - .globl STR_0x -STR_0x: - mov r0,pc; mov pc,lr - .asciz "0x" - .balign 4 - - .globl STR_hex -STR_hex: - mov r0,pc; mov pc,lr - .asciz "0123456789abcdef" - .balign 4 - - .globl STR_xread -STR_xread: - mov r0,pc; mov pc,lr - .asciz "xread %p(%x %p) %p %x\n" - .balign 4 - - .globl STR_unpackExtent -STR_unpackExtent: - mov r0,pc; mov pc,lr - .asciz "unpackExtent in=%p(%x %p) out=%p(%x %p) %p %p\n" - .balign 4 - - .globl STR_make_hatch_arm -STR_make_hatch_arm: - mov r0,pc; mov pc,lr - .asciz "make_hatch_arm %p %x\n" - .balign 4 - - .globl STR_auxv_up -STR_auxv_up: - mov r0,pc; mov pc,lr - .asciz "auxv_up %p %x %x\n" - .balign 4 - - .globl STR_xfind_pages -STR_xfind_pages: - mov r0,pc; mov pc,lr - .asciz "xfind_pages %x %p %d %p\n" - .balign 4 - - .globl STR_do_xmap -STR_do_xmap: - mov r0,pc; mov pc,lr - .asciz "do_xmap fdi=%x ehdr=%p xi=%p(%x %p) av=%p p_reloc=%p f_unf=%p\n" - .balign 4 - - .globl STR_upx_main -STR_upx_main: - mov r0,pc; mov pc,lr - .asciz "upx_main av=%p szc=%x f_dec=%p f_unf=%p xo=%p(%x %p) xi=%p(%x %p) dynbase=%x\n", - .balign 4 -#endif /*}*/ - // vi:ts=8:et:nowrap diff --git a/src/stub/src/arm-linux.elf-fold.S b/src/stub/src/arm-linux.elf-fold.S index 7ca8c235..660f21c1 100644 --- a/src/stub/src/arm-linux.elf-fold.S +++ b/src/stub/src/arm-linux.elf-fold.S @@ -200,7 +200,7 @@ mmap: #define DEBUG 0 #endif /*}*/ -#if DEBUG /*{ "gcc-3.4 -fPIC" botches string constants when code moves! */ +#if DEBUG /*{*/ div10: .globl div10 mov ip,r0 @ extra copy used at end @@ -233,59 +233,6 @@ div10: .globl div10 adc r0,r1,#0 @ * 0x0.1999999a ret - .globl STR_0x -STR_0x: - mov r0,pc; ret - .asciz "0x" - .balign 4 - - .globl STR_hex -STR_hex: - mov r0,pc; ret - .asciz "0123456789abcdef" - .balign 4 - - .globl STR_xread -STR_xread: - mov r0,pc; ret - .asciz "xread %p(%x %p) %p %x\n" - .balign 4 - - .globl STR_unpackExtent -STR_unpackExtent: - mov r0,pc; ret - .asciz "unpackExtent in=%p(%x %p) out=%p(%x %p) %p %p\n" - .balign 4 - - .globl STR_make_hatch_arm -STR_make_hatch_arm: - mov r0,pc; ret - .asciz "make_hatch_arm %p %x\n" - .balign 4 - - .globl STR_auxv_up -STR_auxv_up: - mov r0,pc; ret - .asciz "auxv_up %p %x %x\n" - .balign 4 - - .globl STR_xfind_pages -STR_xfind_pages: - mov r0,pc; ret - .asciz "xfind_pages %x %p %d %p\n" - .balign 4 - - .globl STR_do_xmap -STR_do_xmap: - mov r0,pc; ret - .asciz "do_xmap fdi=%x ehdr=%p xi=%p(%x %p) av=%p p_reloc=%p f_unf=%p\n" - .balign 4 - - .globl STR_upx_main -STR_upx_main: - mov r0,pc; ret - .asciz "upx_main av=%p szc=%x f_dec=%p f_unf=%p xo=%p(%x %p) xi=%p(%x %p) dynbase=%x\n", - .balign 4 #endif /*}*/ @ vi:ts=8:et:nowrap diff --git a/src/stub/src/i386-bsd.elf-fold.S b/src/stub/src/i386-bsd.elf-fold.S index 5c111d49..56bfcd6f 100644 --- a/src/stub/src/i386-bsd.elf-fold.S +++ b/src/stub/src/i386-bsd.elf-fold.S @@ -202,55 +202,5 @@ L32: pop edi // &auxtab ret -#ifndef DEBUG /*{*/ -#define DEBUG 0 -#endif /*}*/ - -#if DEBUG /*{ truly-PIC string constants for debugging */ - .globl STR_0x -STR_0x: - call 0f; .asciz "0x"; 0: - pop eax; ret - - .globl STR_hex -STR_hex: - call 0f; .asciz "0123456789abcdef"; 0: - pop eax; ret - - .globl STR_xread -STR_xread: - call 0f; .asciz "xread %p(%x %p) %p %x\n"; 0: - pop eax; ret - - .globl STR_unpackExtent -STR_unpackExtent: - call 0f; .asciz "unpackExtent in=%p(%x %p) out=%p(%x %p) %p %p\n"; 0: - pop eax; ret - - .globl STR_make_hatch_arm -STR_make_hatch_arm: - call 0f; .asciz "make_hatch_arm %p %x\n"; 0: - pop eax; ret - - .globl STR_auxv_up -STR_auxv_up: - call 0f; .asciz "auxv_up %p %x %x\n"; 0: - pop eax; ret - - .globl STR_xfind_pages -STR_xfind_pages: - call 0f; .asciz "xfind_pages %x %p %d %p\n"; 0: - pop eax; ret - - .globl STR_do_xmap -STR_do_xmap: - call 0f; .asciz "do_xmap fdi=%x ehdr=%p xi=%p(%x %p) av=%p p_reloc=%p f_unf=%p\n"; 0: - pop eax; ret - - .globl STR_upx_main -STR_upx_main: - call 0f; .asciz "upx_main av=%p szc=%x f_dec=%p f_unf=%p xo=%p(%x %p) xi=%p(%x %p) dynbase=%x\n"; 0: - pop eax; ret -#endif /*}*/ // vi:ts=8:et:nowrap diff --git a/src/stub/src/i386-linux.elf-fold.S b/src/stub/src/i386-linux.elf-fold.S index 117841ea..76b73b8f 100644 --- a/src/stub/src/i386-linux.elf-fold.S +++ b/src/stub/src/i386-linux.elf-fold.S @@ -238,56 +238,5 @@ mmap: .globl mmap pop ebx ret -#ifndef DEBUG /*{*/ -#define DEBUG 0 -#endif /*}*/ - -#if DEBUG /*{ truly-PIC string constants for debugging */ - .globl STR_0x -STR_0x: - call 0f; .asciz "0x"; 0: - pop eax; ret - - .globl STR_hex -STR_hex: - call 0f; .asciz "0123456789abcdef"; 0: - pop eax; ret - - .globl STR_xread -STR_xread: - call 0f; .asciz "xread %p(%x %p) %p %x\n"; 0: - pop eax; ret - - .globl STR_unpackExtent -STR_unpackExtent: - call 0f; .asciz "unpackExtent in=%p(%x %p) out=%p(%x %p) %p %p\n"; 0: - pop eax; ret - - .globl STR_make_hatch_arm -STR_make_hatch_arm: - call 0f; .asciz "make_hatch_arm %p %x\n"; 0: - pop eax; ret - - .globl STR_auxv_up -STR_auxv_up: - call 0f; .asciz "auxv_up %p %x %x\n"; 0: - pop eax; ret - - .globl STR_xfind_pages -STR_xfind_pages: - call 0f; .asciz "xfind_pages %x %p %d %p\n"; 0: - pop eax; ret - - .globl STR_do_xmap -STR_do_xmap: - call 0f; .asciz "do_xmap fdi=%x ehdr=%p xi=%p(%x %p) av=%p p_reloc=%p f_unf=%p\n"; 0: - pop eax; ret - - .globl STR_upx_main -STR_upx_main: - call 0f; .asciz "upx_main av=%p szc=%x f_dec=%p f_unf=%p xo=%p(%x %p) xi=%p(%x %p) dynbase=%x\n"; 0: - pop eax; ret -#endif /*}*/ - // vi:ts=8:et:nowrap diff --git a/src/stub/src/i386-linux.elf-main.c b/src/stub/src/i386-linux.elf-main.c index c082ec5b..0b64634f 100644 --- a/src/stub/src/i386-linux.elf-main.c +++ b/src/stub/src/i386-linux.elf-main.c @@ -59,6 +59,46 @@ ssize_t write(int, void const *, size_t); #define va_start __builtin_va_start #endif +#if defined(__i386__) /*{*/ +#define PIC_STRING(value, var) \ + __asm__ __volatile__ ( \ + "call 0f; .asciz \"" value "\"; \ + 0: pop %0;" : "=a"(var) : \ + ) +#elif defined(__arm__) /*}{*/ + __asm__ __volatile__ ( \ + "mov r0,pc; ret; \ + .asciz \"" value "\"; .balign 4" : "=a"(var) : \ + ) +#elif defined(__mips__) /*}{*/ + __asm__ __volatile__ ( \ + "mov at,ra; bal 0f; move v0,ra; \ + .asciz \"" value "\"; .balign 4; \ + 0: jr at; nop" : "=a"(var) : \ + ) +#endif /*}*/ + + +#define DEBUG_STRCON(name, value) \ + static char const *name(void) \ + { \ + char *rv; PIC_STRING(value, rv); \ + return rv; \ + } + +DEBUG_STRCON(STR_hex, "0123456789abcdef"); +DEBUG_STRCON(STR_xread, "xread %%p(%%x %%p) %%p %%x\\n") +DEBUG_STRCON(STR_unpackExtent, + "unpackExtent in=%%p(%%x %%p) out=%%p(%%x %%p) %%p %%p\\n"); +DEBUG_STRCON(STR_make_hatch, "make_hatch %%p %%x\\n"); +DEBUG_STRCON(STR_auxv_up, "auxv_up %%p %%x %%x\\n"); +DEBUG_STRCON(STR_xfind_pages, "xfind_pages %%x %%p %%d %%p\\n"); +DEBUG_STRCON(STR_do_xmap, + "do_xmap fdi=%%x ehdr=%%p xi=%%p(%%x %%p) av=%%p p_reloc=%%p f_unf=%%p\\n") +DEBUG_STRCON(STR_upx_main, + "upx_main av=%%p szc=%%x f_dec=%%p f_unf=%%p " + " xo=%%p(%%x %%p) xi=%%p(%%x %%p) dynbase=%%x\\n") + #ifdef __arm__ /*{*/ extern unsigned div10(unsigned); #else /*}{*/ @@ -106,15 +146,6 @@ heximal(unsigned x, char *ptr, int n) #define DPRINTF(a) dprintf a -extern char const *STR_0x(void); -extern char const *STR_xread(void); -extern char const *STR_unpackExtent(void); -extern char const *STR_make_hatch_arm(void); -extern char const *STR_auxv_up(void); -extern char const *STR_xfind_pages(void); -extern char const *STR_do_xmap(void); -extern char const *STR_upx_main(void); - static int dprintf(char const *fmt, ...) @@ -290,6 +321,7 @@ static void * make_hatch_x86(Elf32_Phdr const *const phdr, unsigned const reloc) { unsigned *hatch = 0; + DPRINTF((STR_make_hatch(),phdr,reloc)); if (phdr->p_type==PT_LOAD && phdr->p_flags & PF_X) { // The format of the 'if' is // if ( ( (hatch = loc1), test_loc1 ) @@ -328,7 +360,7 @@ make_hatch_arm( ) { unsigned *hatch = 0; - DPRINTF((STR_make_hatch_arm(),phdr,reloc)); + DPRINTF((STR_make_hatch(),phdr,reloc)); if (phdr->p_type==PT_LOAD && phdr->p_flags & PF_X) { // The format of the 'if' is // if ( ( (hatch = loc1), test_loc1 ) diff --git a/src/stub/src/mipsel.r3000-linux.elf-fold.S b/src/stub/src/mipsel.r3000-linux.elf-fold.S index e24f808e..97d9db61 100644 --- a/src/stub/src/mipsel.r3000-linux.elf-fold.S +++ b/src/stub/src/mipsel.r3000-linux.elf-fold.S @@ -207,65 +207,4 @@ mmap: .globl mmap addiu sp,sp, sp_frame #endif /*}*/ -#if 0 /*{ truly-PIC string constants for debugging */ -/* UNFORTUNATELY THIS DOES NOT WORK because gcc uses 'jal' instead of 'bal' */ - - .globl STR_0x -ret_at: - jr at - nop -STR_0x: - move at,ra; bal ret_at; move v0,ra - .asciz "0x" - .balign 4 - - .globl STR_hex -STR_hex: - move at,ra; bal ret_at; move v0,ra - .asciz "0123456789abcdef" - .balign 4 - - .globl STR_xread -STR_xread: - move at,ra; bal ret_at; move v0,ra - .asciz "xread %p(%x %p) %p %x\n" - .balign 4 - - .globl STR_unpackExtent -STR_unpackExtent: - move at,ra; bal ret_at; move v0,ra - .asciz "unpackExtent in=%p(%x %p) out=%p(%x %p) %p %p\n" - .balign 4 - - .globl STR_make_hatch_arm -STR_make_hatch_arm: - move at,ra; bal ret_at; move v0,ra - .asciz "make_hatch_arm %p %x\n" - .balign 4 - - .globl STR_auxv_up -STR_auxv_up: - move at,ra; bal ret_at; move v0,ra - .asciz "auxv_up %p %x %x\n" - .balign 4 - - .globl STR_xfind_pages -STR_xfind_pages: - move at,ra; bal ret_at; move v0,ra - .asciz "xfind_pages %x %p %d %p\n" - .balign 4 - - .globl STR_do_xmap -STR_do_xmap: - move at,ra; bal ret_at; move v0,ra - .asciz "do_xmap fdi=%x ehdr=%p xi=%p(%x %p) av=%p p_reloc=%p f_unf=%p\n" - .balign 4 - - .globl STR_upx_main -STR_upx_main: - move at,ra; bal ret_at; move v0,ra - .asciz "upx_main av=%p szc=%x f_dec=%p f_unf=%p xo=%p(%x %p) xi=%p(%x %p) dynbase=%x\n", - .balign 4 -#endif /*}*/ - # vi:ts=8:et:nowrap diff --git a/src/stub/tmp/i386-netbsd.elf-fold.bin b/src/stub/tmp/i386-netbsd.elf-fold.bin index 39a0ddd76571ad913bf975ce961425c32488b692..7ca6f56d489e14a6f5d2112dff4ca12348cc4b13 100644 GIT binary patch delta 17 YcmeC=>*V98clB{&WMpL8$ic`C03@0NQvd(} delta 17 YcmeC=>*V98clB{&WMt&o$ic`C03^%t<8