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 |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 if(sh == nil) | 506 if(sh == nil) |
507 return 0; | 507 return 0; |
508 | 508 |
509 cwrite(ELF_NOTE_BUILDINFO_NAME, ELF_NOTE_BUILDINFO_NAMESZ); | 509 cwrite(ELF_NOTE_BUILDINFO_NAME, ELF_NOTE_BUILDINFO_NAMESZ); |
510 cwrite(buildinfo, buildinfolen); | 510 cwrite(buildinfo, buildinfolen); |
511 cwrite("\0\0\0", rnd(buildinfolen, 4) - buildinfolen); | 511 cwrite("\0\0\0", rnd(buildinfolen, 4) - buildinfolen); |
512 | 512 |
513 return sh->size; | 513 return sh->size; |
514 } | 514 } |
515 | 515 |
| 516 // contents for .ARM.attributes section. |
| 517 // see section 4.3.6 (Build Attributes) of "ELF for the ARM Architecture" (ARM I
HI 0044E). |
| 518 static const char arm_attributes[] = { |
| 519 /* 00 */ 'A', // format-version |
| 520 /* 01 */ 0x14, 0x00, 0x00, 0x00, // section-length (little endian) |
| 521 /* 05 */ 'a', 'e', 'a', 'b', 'i', 0, // "vendor-name" |
| 522 /* 0b */ 0x01, // Tag_File |
| 523 /* 0c */ 0x04, 0x00, 0x00, 0x00, // ULEB128 encoded byte size |
| 524 /* 10 */ 27, 0x3, // Tag_ABI_HardFP_use, both SP and SP |
| 525 /* 12 */ 10, 0x4, // Tag_FP_arch, v3 FP ISA permitted, but only D0-D15,
S0-S31· |
| 526 }; |
| 527 ········ |
| 528 static int |
| 529 elfarmattributes(uint64 resoff) |
| 530 { |
| 531 int n; |
| 532 ElfShdr *sh; |
| 533 |
| 534 n = nelem(arm_attributes); |
| 535 n += rnd(n, 4); |
| 536 |
| 537 sh = elfshname(".ARM.attributes"); |
| 538 sh->off = resoff - n; |
| 539 sh->size = n; |
| 540 |
| 541 return n; |
| 542 } |
| 543 |
| 544 static int |
| 545 elfwritearmattributes(void) |
| 546 { |
| 547 ElfShdr *sh; |
| 548 sh = elfshname(".ARM.attributes"); |
| 549 cseek(sh->off); |
| 550 cwrite((char *)arm_attributes, sh->size); |
| 551 return sh->size; |
| 552 } |
| 553 |
516 extern int nelfsym; | 554 extern int nelfsym; |
517 int elfverneed; | 555 int elfverneed; |
518 | 556 |
519 typedef struct Elfaux Elfaux; | 557 typedef struct Elfaux Elfaux; |
520 typedef struct Elflib Elflib; | 558 typedef struct Elflib Elflib; |
521 | 559 |
522 struct Elflib | 560 struct Elflib |
523 { | 561 { |
524 Elflib *next; | 562 Elflib *next; |
525 Elfaux *aux; | 563 Elfaux *aux; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 | 1101 |
1064 if(flag_shared) { | 1102 if(flag_shared) { |
1065 Sym *init_sym = lookup(LIBINITENTRY, 0); | 1103 Sym *init_sym = lookup(LIBINITENTRY, 0); |
1066 if(init_sym->type != STEXT) | 1104 if(init_sym->type != STEXT) |
1067 diag("entry not text: %s", init_sym->name); | 1105 diag("entry not text: %s", init_sym->name); |
1068 elfwritedynentsym(s, DT_INIT, init_sym); | 1106 elfwritedynentsym(s, DT_INIT, init_sym); |
1069 } | 1107 } |
1070 | 1108 |
1071 // Do not write DT_NULL. elfdynhash will finish it. | 1109 // Do not write DT_NULL. elfdynhash will finish it. |
1072 } | 1110 } |
| 1111 |
| 1112 // ARM Attributes section |
| 1113 if(thechar == '5') { |
| 1114 addstring(shstrtab, ".ARM.attributes"); |
| 1115 } |
1073 } | 1116 } |
1074 | 1117 |
1075 void | 1118 void |
1076 shsym(ElfShdr *sh, Sym *s) | 1119 shsym(ElfShdr *sh, Sym *s) |
1077 { | 1120 { |
1078 vlong addr; | 1121 vlong addr; |
1079 addr = symaddr(s); | 1122 addr = symaddr(s); |
1080 if(sh->flags&SHF_ALLOC) | 1123 if(sh->flags&SHF_ALLOC) |
1081 sh->addr = addr; | 1124 sh->addr = addr; |
1082 sh->off = datoff(addr); | 1125 sh->off = datoff(addr); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 resoff -= elfbuildinfo(sh, startva, resoff); | 1263 resoff -= elfbuildinfo(sh, startva, resoff); |
1221 | 1264 |
1222 if(pnote == nil) { | 1265 if(pnote == nil) { |
1223 pnote = newElfPhdr(); | 1266 pnote = newElfPhdr(); |
1224 pnote->type = PT_NOTE; | 1267 pnote->type = PT_NOTE; |
1225 pnote->flags = PF_R; | 1268 pnote->flags = PF_R; |
1226 } | 1269 } |
1227 phsh(pnote, sh); | 1270 phsh(pnote, sh); |
1228 } | 1271 } |
1229 | 1272 |
| 1273 if(thechar == '5') { |
| 1274 resoff -= elfarmattributes(resoff); |
| 1275 } |
| 1276 |
1230 // Additions to the reserved area must be above this line. | 1277 // Additions to the reserved area must be above this line. |
1231 USED(resoff); | 1278 USED(resoff); |
1232 | 1279 |
1233 elfphload(&segtext); | 1280 elfphload(&segtext); |
1234 elfphload(&segdata); | 1281 elfphload(&segdata); |
1235 | 1282 |
1236 /* Dynamic linking sections */ | 1283 /* Dynamic linking sections */ |
1237 if(!debug['d']) { /* -d suppresses dynamic loader format */ | 1284 if(!debug['d']) { /* -d suppresses dynamic loader format */ |
1238 sh = elfshname(".dynsym"); | 1285 sh = elfshname(".dynsym"); |
1239 sh->type = SHT_DYNSYM; | 1286 sh->type = SHT_DYNSYM; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1433 | 1480 |
1434 sh = elfshname(".strtab"); | 1481 sh = elfshname(".strtab"); |
1435 sh->type = SHT_STRTAB; | 1482 sh->type = SHT_STRTAB; |
1436 sh->off = symo+symsize; | 1483 sh->off = symo+symsize; |
1437 sh->size = elfstrsize; | 1484 sh->size = elfstrsize; |
1438 sh->addralign = 1; | 1485 sh->addralign = 1; |
1439 | 1486 |
1440 dwarfaddelfheaders(); | 1487 dwarfaddelfheaders(); |
1441 } | 1488 } |
1442 | 1489 |
| 1490 // ARM Attributes section |
| 1491 if(thechar == '5') { |
| 1492 sh = elfshname(".ARM.attributes"); |
| 1493 sh->type = SHT_ARM_ATTRIBUTES; |
| 1494 sh->flags = 0; |
| 1495 } |
| 1496 |
1443 /* Main header */ | 1497 /* Main header */ |
1444 eh->ident[EI_MAG0] = '\177'; | 1498 eh->ident[EI_MAG0] = '\177'; |
1445 eh->ident[EI_MAG1] = 'E'; | 1499 eh->ident[EI_MAG1] = 'E'; |
1446 eh->ident[EI_MAG2] = 'L'; | 1500 eh->ident[EI_MAG2] = 'L'; |
1447 eh->ident[EI_MAG3] = 'F'; | 1501 eh->ident[EI_MAG3] = 'F'; |
1448 if(HEADTYPE == Hfreebsd) | 1502 if(HEADTYPE == Hfreebsd) |
1449 eh->ident[EI_OSABI] = ELFOSABI_FREEBSD; | 1503 eh->ident[EI_OSABI] = ELFOSABI_FREEBSD; |
1450 else if(HEADTYPE == Hnetbsd) | 1504 else if(HEADTYPE == Hnetbsd) |
1451 eh->ident[EI_OSABI] = ELFOSABI_NETBSD; | 1505 eh->ident[EI_OSABI] = ELFOSABI_NETBSD; |
1452 else if(HEADTYPE == Hopenbsd) | 1506 else if(HEADTYPE == Hopenbsd) |
(...skipping 30 matching lines...) Expand all Loading... |
1483 if(!debug['d']) | 1537 if(!debug['d']) |
1484 a += elfwriteinterp(); | 1538 a += elfwriteinterp(); |
1485 if(linkmode != LinkExternal) { | 1539 if(linkmode != LinkExternal) { |
1486 if(HEADTYPE == Hnetbsd) | 1540 if(HEADTYPE == Hnetbsd) |
1487 a += elfwritenetbsdsig(); | 1541 a += elfwritenetbsdsig(); |
1488 if(HEADTYPE == Hopenbsd) | 1542 if(HEADTYPE == Hopenbsd) |
1489 a += elfwriteopenbsdsig(); | 1543 a += elfwriteopenbsdsig(); |
1490 if(buildinfolen > 0) | 1544 if(buildinfolen > 0) |
1491 a += elfwritebuildinfo(); | 1545 a += elfwritebuildinfo(); |
1492 } | 1546 } |
| 1547 if(thechar == '5') |
| 1548 a += elfwritearmattributes(); |
1493 if(a > ELFRESERVE)······ | 1549 if(a > ELFRESERVE)······ |
1494 diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE); | 1550 diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE); |
1495 } | 1551 } |
OLD | NEW |