Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart::bin::elf::LoadedElf Class Reference

Public Member Functions

 LoadedElf (std::unique_ptr< Mappable > mappable, uint64_t elf_data_offset)
 
 ~LoadedElf ()
 
bool Load ()
 
bool ResolveSymbols (const uint8_t **vm_data, const uint8_t **vm_instrs, const uint8_t **isolate_data, const uint8_t **isolate_instrs)
 
const char * error ()
 

Detailed Description

A loader for a subset of ELF which may be used to load objects produced by Dart_CreateAppAOTSnapshotAsElf.

Definition at line 167 of file elf_loader.cc.

Constructor & Destructor Documentation

◆ LoadedElf()

dart::bin::elf::LoadedElf::LoadedElf ( std::unique_ptr< Mappable mappable,
uint64_t  elf_data_offset 
)
inlineexplicit

Definition at line 169 of file elf_loader.cc.

171 : mappable_(std::move(mappable)), elf_data_offset_(elf_data_offset) {}

◆ ~LoadedElf()

dart::bin::elf::LoadedElf::~LoadedElf ( )

Definition at line 297 of file elf_loader.cc.

297 {
298#if defined(DART_HOST_OS_WINDOWS) && \
299 (defined(HOST_ARCH_X64) || defined(HOST_ARCH_ARM64))
300 for (intptr_t i = 0; i < dynamic_runtime_function_tables_.length(); i++) {
302 dynamic_runtime_function_tables_[i]);
303 }
304#endif
305
306 // Unmap the image.
307 base_.reset();
308
309 // Explicitly destroy all the mappings before closing the file.
310 program_table_mapping_.reset();
311 section_table_mapping_.reset();
312 section_string_table_mapping_.reset();
313}
static void UnregisterDynamicTable(void *p_dynamic_table)

Member Function Documentation

◆ error()

const char * dart::bin::elf::LoadedElf::error ( )
inline

Definition at line 197 of file elf_loader.cc.

197{ return error_; }

◆ Load()

bool dart::bin::elf::LoadedElf::Load ( )

Loads the ELF object into memory. Returns whether the load was successful. On failure, the error may be retrieved by 'error()'.

Definition at line 272 of file elf_loader.cc.

272 {
274
275 if (error_ != nullptr) {
276 return false;
277 }
278
279 CHECK_ERROR(Utils::IsAligned(elf_data_offset_, PageSize()),
280 "File offset must be page-aligned.");
281
282 ASSERT(mappable_ != nullptr);
283 CHECK_ERROR(mappable_->SetPosition(elf_data_offset_), "Invalid file offset.");
284
285 CHECK(ReadHeader());
286 CHECK(ReadProgramTable());
287 CHECK(LoadSegments());
288 CHECK(ReadSectionTable());
289 CHECK(ReadSectionStringTable());
290 CHECK(ReadSections());
291
292 mappable_.reset();
293
294 return true;
295}
static constexpr bool IsAligned(T x, uintptr_t alignment, uintptr_t offset=0)
Definition: utils.h:92
#define ASSERT(E)
#define CHECK_ERROR(value, message)
Definition: elf_loader.cc:266
#define CHECK(value)
Definition: elf_loader.cc:254

◆ ResolveSymbols()

bool dart::bin::elf::LoadedElf::ResolveSymbols ( const uint8_t **  vm_data,
const uint8_t **  vm_instrs,
const uint8_t **  isolate_data,
const uint8_t **  isolate_instrs 
)

Reads Dart-specific symbols from the loaded ELF.

Stores the address of the corresponding symbol in each non-null output parameter.

Fails if any output parameter is non-null but points to null and the corresponding symbol was not found, or if the dynamic symbol table could not be decoded.

Has the side effect of initializing the relocated addresses for the text sections corresponding to non-null output parameters in the BSS segment.

On failure, the error may be retrieved by 'error()'.

Definition at line 505 of file elf_loader.cc.

508 {
509 if (error_ != nullptr) {
510 return false;
511 }
512
513 // The first entry of the symbol table is reserved.
514 for (uword i = 1; i < dynamic_symbol_count_; ++i) {
515 const dart::elf::Symbol sym = dynamic_symbol_table_[i];
516 const char* name = dynamic_string_table_ + sym.name;
517 const uint8_t** output = nullptr;
518
519 if (strcmp(name, kVmSnapshotDataAsmSymbol) == 0) {
520 output = vm_data;
521 } else if (strcmp(name, kVmSnapshotInstructionsAsmSymbol) == 0) {
522 output = vm_instrs;
523 } else if (strcmp(name, kIsolateSnapshotDataAsmSymbol) == 0) {
524 output = isolate_data;
525 } else if (strcmp(name, kIsolateSnapshotInstructionsAsmSymbol) == 0) {
526 output = isolate_instrs;
527 }
528
529 if (output != nullptr) {
530 *output = reinterpret_cast<const uint8_t*>(base_->start() + sym.value);
531 }
532 }
533
534 CHECK_ERROR(isolate_data == nullptr || *isolate_data != nullptr,
535 "Could not find isolate snapshot data.");
536 CHECK_ERROR(isolate_instrs == nullptr || *isolate_instrs != nullptr,
537 "Could not find isolate instructions.");
538 return true;
539}
#define kIsolateSnapshotDataAsmSymbol
Definition: dart_api.h:3967
#define kIsolateSnapshotInstructionsAsmSymbol
Definition: dart_api.h:3968
#define kVmSnapshotDataAsmSymbol
Definition: dart_api.h:3964
#define kVmSnapshotInstructionsAsmSymbol
Definition: dart_api.h:3965
const char *const name
uintptr_t uword
Definition: globals.h:501

The documentation for this class was generated from the following file: