summaryrefslogtreecommitdiff
path: root/docs/decompiling.md
diff options
context:
space:
mode:
authorAetias <aetias@outlook.com>2024-04-20 13:38:52 +0200
committerAetias <aetias@outlook.com>2024-04-20 13:38:52 +0200
commita7b01da72af70c75fd8e064eab320902de9e9f6d (patch)
tree399f9e987ae8cf1447f507137d3c25a2f509603d /docs/decompiling.md
parent0e5b67f37bae9fe34812b05493ac7ad3baf79dfc (diff)
Add info on decomping static initializers
Diffstat (limited to 'docs/decompiling.md')
-rw-r--r--docs/decompiling.md23
1 files changed, 22 insertions, 1 deletions
diff --git a/docs/decompiling.md b/docs/decompiling.md
index a779f120..bedb1cbb 100644
--- a/docs/decompiling.md
+++ b/docs/decompiling.md
@@ -3,6 +3,7 @@ This document describes how you can start decompiling code and contribute to the
stuck or need assistance.
- [Pick a source file](#pick-a-source-file)
- [Decompiling a function](#decompiling-a-function)
+- [Decompiling `.init` functions](#decompiling-init-functions)
- [The Ghidra project](#the-ghidra-project)
## Pick a source file
@@ -49,7 +50,27 @@ _0211bf50: .word data_ov09_0211f59c
- In the worst case, you can also contribute [non-matching functions](/CONTRIBUTING.md#non-matching-functions) to this
project.
+## Decompiling `.init` functions
+> [!NOTE]
+> This section will be updated as we learn more about global objects. Feel free to contribute or provide us with more
+> information!
+
+Functions in the `.init` section are static initializers. Their purpose is to call C++ constructors on global objects, and to
+register destructors so the global objects can be destroyed when their overlay unloads.
+
+Static initializers are generated implicitly and do not require us to write any code ourselves. So, to generate one, you must
+define a global variable by using a constructor.
+
+If the static initializer calls `__register_global_object`, that means the global object has a destructor. This means you'll
+have to declare a destructor if it doesn't exist already.
+
+Another consequence of having a destructor is that a `DestructorChain` object will be added to the `.bss` section. This struct
+is 12 (`0xc`) bytes long and is also implicit, so we don't need to define it ourselves.
+
+> [!IMPORTANT]
+> An important thing to keep in mind is that a static initializer can construct multiple global objects.
+
## The Ghidra project
We use a shared Ghidra project to analyze the game and decompile functions. To gain access to the project, install
[Ghidra version 10.2.3](https://github.com/NationalSecurityAgency/ghidra/releases/tag/Ghidra_10.2.3_build) and request access
-from @aetias on Discord. \ No newline at end of file
+from @aetias on Discord.