File: file2.c

package info (click to toggle)
linksem 0.8%2Bdfsg3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,376 kB
  • sloc: asm: 9,188; ansic: 5,856; ml: 2,918; yacc: 1,310; lex: 721; sh: 119; makefile: 63
file content (33 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <elf.h>

int ifunc(void);

/* We have to write our own libc-like initialization code,
 * and also invoke it ourselves before we do anything else. */
extern Elf64_Rela __rela_iplt_start;
extern Elf64_Rela __rela_iplt_end;
static void init(void)
{
	Elf64_Rela *p_r;
	for (p_r = &__rela_iplt_start; p_r != &__rela_iplt_end; ++p_r)
	{
		if (ELF64_R_TYPE(p_r->r_info) == R_X86_64_IRELATIVE)
		{
			void **site = (void**) p_r->r_offset;
			void *(*resolver)(void) = (void*) p_r->r_addend;
			*site = resolver();
		}
	}
}

int _start(void) __attribute__((noreturn));
int _start(void)
{
	__asm__ volatile ("callq init\n\
                   callq ifunc\n\
                   movq %%rax, %%rdi \n\
                   movq $60, %%rax          # exit \n\
                   syscall"
    : : : "%rax", "%rdi" );
	__builtin_unreachable();
}