upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/pe_loader.cpp
diff options
context:
space:
mode:
authorIAmNotSiob <273832158+IAmNotSiob@users.noreply.github.com>2026-11-21 21:07:23 +0100
committerIAmNotSiob <273832158+IAmNotSiob@users.noreply.github.com>2026-11-21 21:07:23 +0100
commitda499ab9113015ba91c2218895abc51f0aa4baf3 (patch)
tree1554b8c0ce47c41a1a1c8dd2f747b0cb8e06f23b /runtime/src/pe_loader.cpp
parent4c75ce537add406b426d0a1dc84d9a01fb4c86c9 (diff)
Loader: initialise dependencies before their importers
map_image pushes a module into order_ before bind_imports maps the modules it imports, so order_ lists an importer ahead of its DLLs, and initialise() ran TLS callbacks and DllMain in that order. Keep a separate init_order_ filled after a module's imports are loaded and initialise from it. modules() stays mapping order. pe_loader_test checks tiny_dll comes before tiny_exe.
Diffstat (limited to 'runtime/src/pe_loader.cpp')
-rw-r--r--runtime/src/pe_loader.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index f26527989..f5ada18f2 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -67,14 +67,16 @@ Module& Loader::load(const std::filesystem::path& image) {
67 std::string key = lower(image.filename().string()); 67 std::string key = lower(image.filename().string());
68 if (auto it = by_name_.find(key); it != by_name_.end()) return *it->second; 68 if (auto it = by_name_.find(key); it != by_name_.end()) return *it->second;
69 Module& m = map_image(image); 69 Module& m = map_image(image);
70 bind_imports(m); 70 bind_imports(m); // loads every bundled module m imports first, so they land in init_order_ before m
71 protect_sections(m); 71 protect_sections(m);
72 init_order_.push_back(&m);
72 return m; 73 return m;
73} 74}
74 75
75void Loader::initialise() { 76void Loader::initialise() {
76 // order_ is dependency order: a module is pushed after the modules it imports. 77 // Not order_: map_image pushes a module there before bind_imports maps its dependencies, so order_ lists an
77 for (auto* m : order_) initialise(*m); 78 // importer ahead of the DLLs it imports. init_order_ is filled once a module's imports are all loaded.
79 for (auto* m : init_order_) initialise(*m);
78} 80}
79 81
80void Loader::initialise(Module& m) { 82void Loader::initialise(Module& m) {