From 6fef8cafbd0f6f185897bc87feb1ff66e2e204e1 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 14 Oct 2015 17:08:34 -0400 Subject: [PATCH] remove hand-written crt1.s and Scrt1.s files for all archs since commit c5e34dabbb47d8e97a4deccbb421e0cd93c0094b, crt1.c has provided a "mostly-C" implementation of the crt1 start file that avoids the need for arch-specific symbol referencing, PIC/PIE-specific code variants, etc. but for archs that had existing hand-written versions, the new code was initially unused, and later only used as the dynamic linker entry point. this commit switches all archs to using the new code. the code being removed was a recurring source of subtle errors, and was still broken at least on arm, where it failed to properly align the stack pointer before calling into C code. --- crt/arm/Scrt1.s | 30 ------------------------------ crt/arm/crt1.s | 17 ----------------- crt/i386/Scrt1.s | 24 ------------------------ crt/i386/crt1.s | 19 ------------------- crt/microblaze/crt1.s | 16 ---------------- crt/mips/crt1.s | 28 ---------------------------- crt/powerpc/crt1.s | 26 -------------------------- crt/x86_64/Scrt1.s | 16 ---------------- crt/x86_64/crt1.s | 16 ---------------- 9 files changed, 192 deletions(-) delete mode 100644 crt/arm/Scrt1.s delete mode 100644 crt/arm/crt1.s delete mode 100644 crt/i386/Scrt1.s delete mode 100644 crt/i386/crt1.s delete mode 100644 crt/microblaze/crt1.s delete mode 100644 crt/mips/crt1.s delete mode 100644 crt/powerpc/crt1.s delete mode 100644 crt/x86_64/Scrt1.s delete mode 100644 crt/x86_64/crt1.s diff --git a/crt/arm/Scrt1.s b/crt/arm/Scrt1.s deleted file mode 100644 index a54859aa..00000000 --- a/crt/arm/Scrt1.s +++ /dev/null @@ -1,30 +0,0 @@ -.weak _init -.weak _fini -.global _start -_start: - mov fp,#0 - mov lr,#0 - - ldr a2,[sp],#4 - mov a3,sp - str fp,[sp,#-4]! - str a1,[sp,#-4]! - - adr ip,2f - ldr a4,2f+4 - add a4,a4,ip - str a4,[sp,#-4]! - ldr a4,2f+8 - add a4,a4,ip - - ldr a1,2f - add ip,ip,a1 - ldr a1,2f+12 - ldr a1,[ip,a1] - - bl __libc_start_main(PLT) -1: b 1b -2: .word _GLOBAL_OFFSET_TABLE_-2b - .word _fini-2b - .word _init-2b - .word main(GOT) diff --git a/crt/arm/crt1.s b/crt/arm/crt1.s deleted file mode 100644 index 90ef59f3..00000000 --- a/crt/arm/crt1.s +++ /dev/null @@ -1,17 +0,0 @@ -.weak _init -.weak _fini -.global _start -.type _start,%function -_start: - mov fp,#0 - mov lr,#0 - ldr a2,[sp],#4 - mov a3,sp - ldr a4,=_fini - str fp,[sp,#-4]! - str a1,[sp,#-4]! - str a4,[sp,#-4]! - ldr a4,=_init - ldr a1,=main - bl __libc_start_main -1: b 1b diff --git a/crt/i386/Scrt1.s b/crt/i386/Scrt1.s deleted file mode 100644 index 161ee8e8..00000000 --- a/crt/i386/Scrt1.s +++ /dev/null @@ -1,24 +0,0 @@ -.weak _init -.weak _fini -.text -.global _start -_start: - xor %ebp,%ebp - pop %ecx - mov %esp,%eax - and $-16,%esp - push %esp - push %esp - push %edx - call 1f -1: addl $_GLOBAL_OFFSET_TABLE_,(%esp) - pop %ebx - call 1f -1: addl $[_fini-.],(%esp) - call 1f -1: addl $[_init-.],(%esp) - push %eax - push %ecx - push main@GOT(%ebx) - call __libc_start_main@plt -1: jmp 1b diff --git a/crt/i386/crt1.s b/crt/i386/crt1.s deleted file mode 100644 index f5b4f4fd..00000000 --- a/crt/i386/crt1.s +++ /dev/null @@ -1,19 +0,0 @@ -.weak _init -.weak _fini -.text -.global _start -_start: - xor %ebp,%ebp - pop %ecx - mov %esp,%eax - and $-16,%esp - push %esp - push %esp - push %edx - push $_fini - push $_init - push %eax - push %ecx - push $main - call __libc_start_main -1: jmp 1b diff --git a/crt/microblaze/crt1.s b/crt/microblaze/crt1.s deleted file mode 100644 index 33090bba..00000000 --- a/crt/microblaze/crt1.s +++ /dev/null @@ -1,16 +0,0 @@ -.weak _init -.weak _fini -.global _start -.align 2 -_start: - add r19, r0, r0 # Zero the frame pointer. - ori r5, r0, main # Get main() ... - lw r6, r0, r1 # Get argc... - addi r7, r1, 4 # ... and argv ... - ori r8, r0, _init # and _init() ... - ori r9, r0, _fini # and _fini() ... - add r10, r0, r0 # ldso_fini == NULL - andi r1, r1, -8 # align stack - addik r1, r1, -4*6 # Leave space for the args. - bri __libc_start_main # Let's go! - nop # Never gets here. diff --git a/crt/mips/crt1.s b/crt/mips/crt1.s deleted file mode 100644 index 794b6f71..00000000 --- a/crt/mips/crt1.s +++ /dev/null @@ -1,28 +0,0 @@ -.set noreorder - -.weak _init -.weak _fini -.global __start -.global _start -.type __start,@function -.type _start,@function -__start: -_start: - subu $fp, $fp, $fp # Zero the frame pointer. - lui $gp, %hi(_gp) - addi $gp, %lo(_gp) - #la $gp, _gp - lw $4, %call16(main)($gp) # Get main() ... - lw $5, ($sp) # Get argc... - addu $6, $sp, 4 # and argv ... - lw $7, %call16(_init)($gp) # and _init() ... - and $sp, $sp, -8 # Align the stack pointer to 8 bytes - addi $sp, $sp, -4*6 # Leave space for arguments 0..3, arg4, and arg5. - lw $12, %call16(_fini)($gp) # and _fini() ... - sw $12, 4*4($sp) # Save arg4. - sw $0, 4*5($sp) # ldso_fini == NULL - lw $25, %call16(__libc_start_main)($gp) - jalr $25 # Let's go! - nop - b . # Never gets here. - nop diff --git a/crt/powerpc/crt1.s b/crt/powerpc/crt1.s deleted file mode 100644 index 7025430c..00000000 --- a/crt/powerpc/crt1.s +++ /dev/null @@ -1,26 +0,0 @@ - .weak _init - .weak _fini - .global _start - .type _start, %function -_start: - mr 9, 1 # Save the original stack pointer. - clrrwi 1, 1, 4 # Align the stack to 16 bytes. - lis 13, _SDA_BASE_@ha # r13 points to the small data area. - addi 13, 13, _SDA_BASE_@l - li 0, 0 # Zero the frame pointer. - stwu 1, -16(1) # The initial stack frame. - mtlr 0 # Clear the link register. - stw 0, 0(1) # And save it. - lis 3, main@ha # Get main() ... - addi 3, 3, main@l - lwz 4, 0(9) # and argc... - addi 5, 9, 4 # and argv ... - lis 6, _init@ha # and _init() ... - addi 6, 6, _init@l - lis 7, _fini@ha # and _fini() ... - addi 7, 7, _fini@l - li 8, 0 # ldso_fini == NULL - bl __libc_start_main # Let's go! - b . # Never gets here. - .end _start - .size _start, .-_start diff --git a/crt/x86_64/Scrt1.s b/crt/x86_64/Scrt1.s deleted file mode 100644 index ba34e95e..00000000 --- a/crt/x86_64/Scrt1.s +++ /dev/null @@ -1,16 +0,0 @@ -/* Written 2011 Nicholas J. Kain, released as Public Domain */ -.weak _init -.weak _fini -.text -.global _start -_start: - xor %rbp,%rbp /* rbp:undefined -> mark as zero 0 (ABI) */ - mov %rdx,%r9 /* 6th arg: ptr to register with atexit() */ - pop %rsi /* 2nd arg: argc */ - mov %rsp,%rdx /* 3rd arg: argv */ - andq $-16,%rsp /* align stack pointer */ - lea _fini(%rip),%r8 /* 5th arg: fini/dtors function */ - lea _init(%rip),%rcx /* 4th arg: init/ctors function */ - mov main@GOTPCREL(%rip),%rdi /* 1st arg: application entry ip */ - call __libc_start_main@PLT /* musl init will run the program */ -1: jmp 1b diff --git a/crt/x86_64/crt1.s b/crt/x86_64/crt1.s deleted file mode 100644 index 40de3bed..00000000 --- a/crt/x86_64/crt1.s +++ /dev/null @@ -1,16 +0,0 @@ -/* Written 2011 Nicholas J. Kain, released as Public Domain */ -.weak _init -.weak _fini -.text -.global _start -_start: - xor %rbp,%rbp /* rbp:undefined -> mark as zero 0 (ABI) */ - mov %rdx,%r9 /* 6th arg: ptr to register with atexit() */ - pop %rsi /* 2nd arg: argc */ - mov %rsp,%rdx /* 3rd arg: argv */ - andq $-16,%rsp /* align stack pointer */ - mov $_fini,%r8 /* 5th arg: fini/dtors function */ - mov $_init,%rcx /* 4th arg: init/ctors function */ - mov $main,%rdi /* 1st arg: application entry ip */ - call __libc_start_main /* musl init will run the program */ -1: jmp 1b