| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_ELFGEN_H_ | 5 #ifndef VM_ELFGEN_H_ |
| 6 #define VM_ELFGEN_H_ | 6 #define VM_ELFGEN_H_ |
| 7 | 7 |
| 8 #include "vm/thread.h" | 8 #include "vm/thread.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 kStrtab, // String table. | 113 kStrtab, // String table. |
| 114 kSymtab, // Symbol table. | 114 kSymtab, // Symbol table. |
| 115 kNumSections, // Num of section header entries in section header table. | 115 kNumSections, // Num of section header entries in section header table. |
| 116 | 116 |
| 117 // Various ELF constants. | 117 // Various ELF constants. |
| 118 kELFCLASS32 = 1, | 118 kELFCLASS32 = 1, |
| 119 kELFCLASS64 = 2, | 119 kELFCLASS64 = 2, |
| 120 kELFDATA2LSB = 1, | 120 kELFDATA2LSB = 1, |
| 121 kELFDATA2MSB = 2, | 121 kELFDATA2MSB = 2, |
| 122 kEM_386 = 3, | 122 kEM_386 = 3, |
| 123 kEM_MIPS = 8, |
| 123 kEM_ARM = 40, | 124 kEM_ARM = 40, |
| 124 kEM_X86_64 = 62, | 125 kEM_X86_64 = 62, |
| 125 kEV_CURRENT = 1, | 126 kEV_CURRENT = 1, |
| 126 kET_EXEC = 2, // not used | 127 kET_EXEC = 2, // not used |
| 127 kET_DYN = 3, | 128 kET_DYN = 3, |
| 128 kSHT_PROGBITS = 1, | 129 kSHT_PROGBITS = 1, |
| 129 kSHT_SYMTAB = 2, | 130 kSHT_SYMTAB = 2, |
| 130 kSHT_STRTAB = 3, | 131 kSHT_STRTAB = 3, |
| 131 kSHF_WRITE = 1, // not used | 132 kSHF_WRITE = 1, // not used |
| 132 kSHF_ALLOC = 2, | 133 kSHF_ALLOC = 2, |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 OS::SNPrint(end_name, sizeof(end_name), "%s_end", name); | 330 OS::SNPrint(end_name, sizeof(end_name), "%s_end", name); |
| 330 AddFunction(end_name, pc + size, 0); | 331 AddFunction(end_name, pc + size, 0); |
| 331 } | 332 } |
| 332 | 333 |
| 333 | 334 |
| 334 int ElfGen::AddFunction(const char* name, uword pc, intptr_t size) { | 335 int ElfGen::AddFunction(const char* name, uword pc, intptr_t size) { |
| 335 ASSERT(text_vma_ != 0); // code must have been added | 336 ASSERT(text_vma_ != 0); // code must have been added |
| 336 DebugInfo::ByteBuffer* symtab = §ion_buf_[kSymtab]; | 337 DebugInfo::ByteBuffer* symtab = §ion_buf_[kSymtab]; |
| 337 const int beg = symtab->size(); | 338 const int beg = symtab->size(); |
| 338 WriteInt(symtab, AddName(name)); // st_name | 339 WriteInt(symtab, AddName(name)); // st_name |
| 339 #if defined(TARGET_ARCH_X64) | 340 #if defined(ARCH_IS_64_BIT) |
| 340 WriteShort(symtab, (kSTB_LOCAL << 4) + kSTT_FUNC); // st_info + (st_other<<8) | 341 WriteShort(symtab, (kSTB_LOCAL << 4) + kSTT_FUNC); // st_info + (st_other<<8) |
| 341 WriteShort(symtab, kText); // st_shndx | 342 WriteShort(symtab, kText); // st_shndx |
| 342 #endif | 343 #endif |
| 343 WriteWord(symtab, pc); // st_value | 344 WriteWord(symtab, pc); // st_value |
| 344 WriteWord(symtab, size); // st_size | 345 WriteWord(symtab, size); // st_size |
| 345 #if defined(TARGET_ARCH_IA32) || \ | 346 #if defined(ARCH_IS_32_BIT) |
| 346 defined(TARGET_ARCH_ARM) || \ | |
| 347 defined(TARGET_ARCH_MIPS) | |
| 348 // st_info + (st_other<<8) | 347 // st_info + (st_other<<8) |
| 349 WriteShort(symtab, (kSTB_EXPORTED << 4) + kSTT_FUNC); | 348 WriteShort(symtab, (kSTB_EXPORTED << 4) + kSTT_FUNC); |
| 350 WriteShort(symtab, kText); // st_shndx | 349 WriteShort(symtab, kText); // st_shndx |
| 351 #endif | 350 #endif |
| 352 ASSERT(symtab->size() - beg == kSymbolSize); | 351 ASSERT(symtab->size() - beg == kSymbolSize); |
| 353 return beg / kSymbolSize; // symbol index in symtab | 352 return beg / kSymbolSize; // symbol index in symtab |
| 354 } | 353 } |
| 355 | 354 |
| 356 | 355 |
| 357 bool ElfGen::WriteToFile(File* handle) { | 356 bool ElfGen::WriteToFile(File* handle) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 378 | 377 |
| 379 | 378 |
| 380 int ElfGen::AddName(const char* str) { | 379 int ElfGen::AddName(const char* str) { |
| 381 return AddString(§ion_buf_[kStrtab], str); | 380 return AddString(§ion_buf_[kStrtab], str); |
| 382 } | 381 } |
| 383 | 382 |
| 384 | 383 |
| 385 void ElfGen::AddELFHeader(int shoff) { | 384 void ElfGen::AddELFHeader(int shoff) { |
| 386 ASSERT(text_vma_ != 0); // Code must have been added. | 385 ASSERT(text_vma_ != 0); // Code must have been added. |
| 387 Write(&header_, kEI_MAG0_MAG3, 4); // EI_MAG0..EI_MAG3 | 386 Write(&header_, kEI_MAG0_MAG3, 4); // EI_MAG0..EI_MAG3 |
| 388 #if defined(TARGET_ARCH_IA32) || \ | 387 #if defined(ARCH_IS_32_BIT) |
| 389 defined(TARGET_ARCH_ARM) || \ | |
| 390 defined(TARGET_ARCH_MIPS) | |
| 391 WriteByte(&header_, kELFCLASS32); // EI_CLASS | 388 WriteByte(&header_, kELFCLASS32); // EI_CLASS |
| 392 #elif defined(TARGET_ARCH_X64) | 389 #elif defined(ARCH_IS_64_BIT) |
| 393 WriteByte(&header_, kELFCLASS64); // EI_CLASS | 390 WriteByte(&header_, kELFCLASS64); // EI_CLASS |
| 391 #else |
| 392 #error Unknown architecture. |
| 394 #endif | 393 #endif |
| 395 WriteByte(&header_, kELFDATA2LSB); // EI_DATA | 394 WriteByte(&header_, kELFDATA2LSB); // EI_DATA |
| 396 WriteByte(&header_, kEV_CURRENT); // EI_VERSION | 395 WriteByte(&header_, kEV_CURRENT); // EI_VERSION |
| 397 WriteByte(&header_, 0); // EI_PAD | 396 WriteByte(&header_, 0); // EI_PAD |
| 398 WriteInt(&header_, 0); // EI_PAD | 397 WriteInt(&header_, 0); // EI_PAD |
| 399 WriteInt(&header_, 0); // EI_PAD | 398 WriteInt(&header_, 0); // EI_PAD |
| 400 WriteShort(&header_, kET_DYN); // e_type, fake a shared object. | 399 WriteShort(&header_, kET_DYN); // e_type, fake a shared object. |
| 401 #if defined(TARGET_ARCH_IA32) | 400 #if defined(TARGET_ARCH_IA32) |
| 402 WriteShort(&header_, kEM_386); // e_machine | 401 WriteShort(&header_, kEM_386); // e_machine |
| 403 #elif defined(TARGET_ARCH_X64) | 402 #elif defined(TARGET_ARCH_X64) |
| 404 WriteShort(&header_, kEM_X86_64); // e_machine | 403 WriteShort(&header_, kEM_X86_64); // e_machine |
| 405 #elif defined(TARGET_ARCH_ARM) | 404 #elif defined(TARGET_ARCH_ARM) |
| 406 WriteShort(&header_, kEM_ARM); // e_machine | 405 WriteShort(&header_, kEM_ARM); // e_machine |
| 406 #elif defined(TARGET_ARCH_MIPS) |
| 407 WriteShort(&header_, kEM_MIPS); // e_machine |
| 408 #else |
| 409 #error Unknown architecture. |
| 407 #endif | 410 #endif |
| 408 WriteInt(&header_, kEV_CURRENT); // e_version | 411 WriteInt(&header_, kEV_CURRENT); // e_version |
| 409 WriteWord(&header_, 0); // e_entry: none | 412 WriteWord(&header_, 0); // e_entry: none |
| 410 WriteWord(&header_, 0); // e_phoff: no program header table. | 413 WriteWord(&header_, 0); // e_phoff: no program header table. |
| 411 WriteWord(&header_, shoff); // e_shoff: section header table offset. | 414 WriteWord(&header_, shoff); // e_shoff: section header table offset. |
| 412 WriteInt(&header_, 0); // e_flags: no flags. | 415 WriteInt(&header_, 0); // e_flags: no flags. |
| 413 WriteShort(&header_, kELFHeaderSize); // e_ehsize: header size. | 416 WriteShort(&header_, kELFHeaderSize); // e_ehsize: header size. |
| 414 WriteShort(&header_, kProgramHeaderEntrySize); // e_phentsize | 417 WriteShort(&header_, kProgramHeaderEntrySize); // e_phentsize |
| 415 WriteShort(&header_, 0); // e_phnum: no entries program header table. | 418 WriteShort(&header_, 0); // e_phnum: no entries program header table. |
| 416 WriteShort(&header_, kSectionHeaderEntrySize); // e_shentsize | 419 WriteShort(&header_, kSectionHeaderEntrySize); // e_shentsize |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 ASSERT(offset == shoff); | 496 ASSERT(offset == shoff); |
| 494 offset += (*writer)(handle, sheaders_); | 497 offset += (*writer)(handle, sheaders_); |
| 495 ASSERT(offset == shoff + kNumSections * kSectionHeaderEntrySize); | 498 ASSERT(offset == shoff + kNumSections * kSectionHeaderEntrySize); |
| 496 | 499 |
| 497 return true; | 500 return true; |
| 498 } | 501 } |
| 499 | 502 |
| 500 } // namespace dart | 503 } // namespace dart |
| 501 | 504 |
| 502 #endif // VM_ELFGEN_H_ | 505 #endif // VM_ELFGEN_H_ |
| OLD | NEW |