OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "l.h" | 5 #include "l.h" |
6 #include "lib.h" | 6 #include "lib.h" |
7 #include "../ld/elf.h" | 7 #include "../ld/elf.h" |
8 | 8 |
9 /* | 9 /* |
10 * We use the 64-bit data structures on both 32- and 64-bit machines | 10 * We use the 64-bit data structures on both 32- and 64-bit machines |
11 * in order to write the code just once. The 64-bit data structure is | 11 * in order to write the code just once. The 64-bit data structure is |
12 * written in the 32-bit format on the 32-bit machines. | 12 * written in the 32-bit format on the 32-bit machines. |
13 */ | 13 */ |
14 #define NSECT 32 | 14 #define NSECT 32 |
15 | 15 |
| 16 int iself; |
| 17 |
16 static int elf64; | 18 static int elf64; |
17 static ElfEhdr hdr; | 19 static ElfEhdr hdr; |
18 static ElfPhdr *phdr[NSECT]; | 20 static ElfPhdr *phdr[NSECT]; |
19 static ElfShdr *shdr[NSECT]; | 21 static ElfShdr *shdr[NSECT]; |
20 static char *interp; | 22 static char *interp; |
21 | 23 |
22 /* | 24 /* |
23 Initialize the global variable that describes the ELF header. It will be update
d as | 25 Initialize the global variable that describes the ELF header. It will be update
d as |
24 we write section and prog headers. | 26 we write section and prog headers. |
25 */ | 27 */ |
26 void | 28 void |
27 elfinit(void) | 29 elfinit(void) |
28 { | 30 { |
| 31 iself = 1; |
| 32 |
29 switch(thechar) { | 33 switch(thechar) { |
30 // 64-bit architectures | 34 // 64-bit architectures |
31 case '6': | 35 case '6': |
32 elf64 = 1; | 36 elf64 = 1; |
33 hdr.phoff = ELF64HDRSIZE; /* Must be be ELF64HDRSIZE: firs
t PHdr must follow ELF header */ | 37 hdr.phoff = ELF64HDRSIZE; /* Must be be ELF64HDRSIZE: firs
t PHdr must follow ELF header */ |
34 hdr.shoff = ELF64HDRSIZE; /* Will move as we add PHeaders
*/ | 38 hdr.shoff = ELF64HDRSIZE; /* Will move as we add PHeaders
*/ |
35 hdr.ehsize = ELF64HDRSIZE; /* Must be ELF64HDRSIZE */ | 39 hdr.ehsize = ELF64HDRSIZE; /* Must be ELF64HDRSIZE */ |
36 hdr.phentsize = ELF64PHDRSIZE; /* Must be ELF64PHDRSIZE */ | 40 hdr.phentsize = ELF64PHDRSIZE; /* Must be ELF64PHDRSIZE */ |
37 hdr.shentsize = ELF64SHDRSIZE; /* Must be ELF64SHDRSIZE */ | 41 hdr.shentsize = ELF64SHDRSIZE; /* Must be ELF64SHDRSIZE */ |
38 break; | 42 break; |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 elfinterp(ElfShdr *sh, uint64 startva, char *p) | 302 elfinterp(ElfShdr *sh, uint64 startva, char *p) |
299 { | 303 { |
300 int n; | 304 int n; |
301 ········ | 305 ········ |
302 interp = p; | 306 interp = p; |
303 n = strlen(interp)+1; | 307 n = strlen(interp)+1; |
304 sh->addr = startva + ELFRESERVE - n; | 308 sh->addr = startva + ELFRESERVE - n; |
305 sh->off = ELFRESERVE - n; | 309 sh->off = ELFRESERVE - n; |
306 sh->size = n; | 310 sh->size = n; |
307 } | 311 } |
OLD | NEW |