-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathhello_world.ld
58 lines (47 loc) · 1.57 KB
/
hello_world.ld
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Small very explicit example.
Expected output: `hello world\n`
We could make this much much smaller by using default names,
but this contains the minimum ammount of detail
that you should know about to get started.
*/
/*
If start is not present, a series of defaults are used:
- the value of a target specific symbol, if it is defined. For many targets this is start.
- the address of the first byte of the `.text' section, if present
- addres 0
*/
ENTRY(_start);
/* Program headers, each of which specifies a segment. */
PHDRS
{
/*
If we don't set the flags here,
the permissions are the minimum possible for the sections inside this segment..
*/
mytext_segment PT_LOAD;
mydata_segment PT_LOAD;
}
SECTIONS
{
/*
Set where the text segment will be loaded into memory by Linux.
Linux segfaults us if the .text is too low.
If this were not present, it would be 0, and that is too low and segfaults. See also:
- http://stackoverflow.com/questions/2187484/why-is-the-elf-execution-entry-point-virtual-address-of-the-form-0x80xxxxx-and-n
- http://stackoverflow.com/questions/2966426/why-do-virtual-memory-addresses-for-linux-binaries-start-at-0x8048000?lq=1
*/
. = 0x400000;
/* Create an output section. */
.mytext_output_section :
{
/* Crump every `.mytext` section from every object file (`*`) into here. */
*(.mytext)
/* If we don't set a segment here, `.text` segment is the default. */
} :mytext_segment
. = 0x600000;
.mydata_output_section :
{
*(.mydata)
} :mydata_segment
}