xref: /Universal-ctags/Units/parser-ldscript.r/ld-hello.d/input.ld (revision 074f40fd3147e23c130ca14e24dbac7d8f8c08af)
1OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
2OUTPUT_ARCH(i386:x86-64)
3ENTRY(_start)
4
5SECTIONS
6{
7  . = 0x400000 + SIZEOF_HEADERS;
8  .text : {
9    _start = .;
10    /* The syscall calling convention for linux on x86_64. */
11    /* Set the following registers and call "syscall" instruction. */
12    /*   %rax: syscall number */
13    /*   %rdi: arg0 */
14    /*   %rsi: arg1 */
15    /*   %rdx: arg2 */
16    /*   %r10: arg3 */
17    /*   %r8:  arg4 */
18    /*   %r9:  arg5 */
19
20    /* set the syscall number of write(2) */
21    /* mov $0x1,%rax */
22    BYTE(0x48);
23    BYTE(0xc7);
24    BYTE(0xc0);
25    BYTE(0x01);
26    BYTE(0x00);
27    BYTE(0x00);
28    BYTE(0x00);
29
30    /* set arg0(== 1 == STDOUT_FILENO) of write(2) */
31    /* mov $0x1,%rdi */
32    BYTE(0x48);
33    BYTE(0xc7);
34    BYTE(0xc7);
35    BYTE(0x01);
36    BYTE(0x00);
37    BYTE(0x00);
38    BYTE(0x00);
39
40    /* set arg1 of write(2) */
41    /* mov $message,$rsi */
42    BYTE(0x48);
43    BYTE(0xc7);
44    BYTE(0xc6);
45    LONG(message);
46
47    /* set arg2 (length of message) of write(2) */
48    /* mov $0xe,%rdx */
49    BYTE(0x48);
50    BYTE(0xc7);
51    BYTE(0xc2);
52    BYTE(0x0e);
53    BYTE(0x00);
54    BYTE(0x00);
55    BYTE(0x00);
56
57    /* call write(2) */
58    /* syscall */
59    BYTE(0x0f);
60    BYTE(0x05);
61
62    /* set the syscall number of exit(2) */
63    /* mov $0x3c,%rax */
64    BYTE(0x48);
65    BYTE(0xc7);
66    BYTE(0xc0);
67    BYTE(0x3c);
68    BYTE(0x00);
69    BYTE(0x00);
70    BYTE(0x00);
71
72    /* set arg0 of exit(2) */
73    /* mov $9x9,%rdi */
74    BYTE(0x48);
75    BYTE(0xc7);
76    BYTE(0xc7);
77    BYTE(0x00);
78    BYTE(0x00);
79    BYTE(0x00);
80    BYTE(0x00);
81
82    /* call exit(2) */
83    /* syscall */
84    BYTE(0x0f);
85    BYTE(0x05);
86  }
87
88  .rodata : {
89    message = .;
90    /* "Hello, world!\n" */
91    BYTE(0x48)
92    BYTE(0x65)
93    BYTE(0x6c)
94    BYTE(0x6c)
95    BYTE(0x6f)
96    BYTE(0x2c)
97    BYTE(0x20)
98    BYTE(0x77)
99    BYTE(0x6f)
100    BYTE(0x72)
101    BYTE(0x6c)
102    BYTE(0x64)
103    BYTE(0x21)
104    BYTE(0x0a)
105  }
106}
107