start.s 839 字节
Newer Older
R
rofl0r 已提交
1 2 3
.text
.global _start
_start:
R
rofl0r 已提交
4 5
	mov (%rsp),%rdi  /* move argc into 1st argument slot */
	lea 4(%rsp),%rsi /* move argv into 2nd argument slot */
R
rofl0r 已提交
6
	call __dynlink
R
rofl0r 已提交
7 8 9 10 11 12 13
	/* in case the dynlinker was called directly, it sets the "consumed"
	   argv values to -1. so we must loop over the array as long as -1
	   is in the top argv slot, decrement argc, and then set the stackpointer
	   to the new argc as well as argc's new value.
	   as the x32 abi has longs in the argv array, we cannot use push/pop.*/
	movl (%rsp),%edi /* copy argc into edi */
	xor %rdx,%rdx /* we use rdx as an offset to the current argv member */
R
rofl0r 已提交
14
1:	dec %edi
R
rofl0r 已提交
15 16 17
	addl $4, %edx
	movl (%rsp, %rdx), %esi
	cmp $-1,%esi
R
rofl0r 已提交
18 19
	jz 1b
	inc %edi
R
rofl0r 已提交
20 21 22
	subl $4, %edx
	lea (%rsp, %rdx), %rsp /* set rsp to new argv[-1] */
	movl %edi, (%rsp)      /* write new argc there */
R
rofl0r 已提交
23 24
	xor %edx,%edx
	jmp *%rax