| 1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef FLUTTER_TESTING_ELF_LOADER_H_ |
| 6 | #define FLUTTER_TESTING_ELF_LOADER_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include "flutter/common/settings.h" |
| 11 | #include "flutter/fml/macros.h" |
| 12 | #include "third_party/dart/runtime/bin/elf_loader.h" |
| 13 | |
| 14 | namespace flutter { |
| 15 | namespace testing { |
| 16 | |
| 17 | inline constexpr const char* kDefaultAOTAppELFFileName = "app_elf_snapshot.so" ; |
| 18 | |
| 19 | // This file name is what gen_snapshot defaults to. It is based off of the |
| 20 | // name of the base file, with the `2` indicating that this split corresponds |
| 21 | // to loading unit id of 2. The base module id is 1 and is omitted as it is not |
| 22 | // considered a split. If dart changes the naming convention, this should be |
| 23 | // changed to match, however, this is considered unlikely to happen. |
| 24 | inline constexpr const char* kDefaultAOTAppELFSplitFileName = |
| 25 | "app_elf_snapshot.so-2.part.so" ; |
| 26 | |
| 27 | struct LoadedELFDeleter { |
| 28 | void operator()(Dart_LoadedElf* elf) { ::Dart_UnloadELF(loaded: elf); } |
| 29 | }; |
| 30 | |
| 31 | using UniqueLoadedELF = std::unique_ptr<Dart_LoadedElf, LoadedELFDeleter>; |
| 32 | |
| 33 | struct ELFAOTSymbols { |
| 34 | UniqueLoadedELF loaded_elf; |
| 35 | const uint8_t* vm_snapshot_data = nullptr; |
| 36 | const uint8_t* vm_snapshot_instrs = nullptr; |
| 37 | const uint8_t* vm_isolate_data = nullptr; |
| 38 | const uint8_t* vm_isolate_instrs = nullptr; |
| 39 | }; |
| 40 | |
| 41 | //------------------------------------------------------------------------------ |
| 42 | /// @brief Attempts to resolve AOT symbols from the portable ELF loader. |
| 43 | /// This location is automatically resolved from the fixtures |
| 44 | /// generator. This only returns valid symbols when the VM is |
| 45 | /// configured for AOT. |
| 46 | /// |
| 47 | /// @param[in] elf_filename The AOT ELF filename from the fixtures generator. |
| 48 | /// |
| 49 | /// @return The loaded ELF symbols. |
| 50 | /// |
| 51 | ELFAOTSymbols LoadELFSymbolFromFixturesIfNeccessary(std::string elf_filename); |
| 52 | |
| 53 | //------------------------------------------------------------------------------ |
| 54 | /// @brief Attempts to resolve split loading unit AOT symbols from the |
| 55 | /// portable ELF loader. If the dart code does not make use of |
| 56 | /// deferred libraries, then there will be no split .so to load. |
| 57 | /// This only returns valid symbols when the VM is configured for |
| 58 | /// AOT. |
| 59 | /// |
| 60 | /// @param[in] elf_split_filename The split AOT ELF filename from the fixtures |
| 61 | /// generator. |
| 62 | /// |
| 63 | /// @return The loaded ELF symbols. |
| 64 | /// |
| 65 | ELFAOTSymbols LoadELFSplitSymbolFromFixturesIfNeccessary( |
| 66 | std::string elf_split_filename); |
| 67 | |
| 68 | //------------------------------------------------------------------------------ |
| 69 | /// @brief Prepare the settings objects various AOT mappings resolvers with |
| 70 | /// the symbols already loaded. This method does nothing in non-AOT |
| 71 | /// runtime modes. |
| 72 | /// |
| 73 | /// @warning The symbols must not be collected till all shell instantiations |
| 74 | /// made using the settings object are collected. |
| 75 | /// |
| 76 | /// @param[in/out] settings The settings whose AOT resolvers to populate. |
| 77 | /// @param[in] symbols The symbols used to populate the settings object. |
| 78 | /// |
| 79 | /// @return If the settings object was correctly updated. |
| 80 | /// |
| 81 | bool PrepareSettingsForAOTWithSymbols(Settings& settings, |
| 82 | const ELFAOTSymbols& symbols); |
| 83 | |
| 84 | } // namespace testing |
| 85 | } // namespace flutter |
| 86 | |
| 87 | #endif // FLUTTER_TESTING_ELF_LOADER_H_ |
| 88 | |