instead, immediately transfer ownership to MachO struct. Also, revert
back to try-ok-fail parsing approach of objects, archives, and dylibs.
It seems easier to try and fail than check if the file *is* of a
certain type given that a dylib may be a stub and parsing yaml
twice in a row seems very wasteful.
Hint for the future: if we optimise yaml/TAPI parsing, this approach
may be rethought!
instead, pass it in functions that require it. Also, when parsing
relocs, make Object part of the context struct where we pass in
additional goodies such as `*MachO` or `*Allocator`.
then, when sorting sections within segments, clear and redo the
ordinals since we re-apply them to symbols anyway. It is vital
to have the ordinals consistent with parsing and resolving relocs
however.
Previously, we'd filter the nlists assuming they were correctly
ordered by type: local < extern defined < undefined within the
object's symbol table but this doesn't seem to be guaranteed,
therefore, we sort by type and address in one go, and filter
defined from undefined afterwards.
For the time being, until we rewrite how atoms are handled across
linkers, store two tables in the MachO linker: one for TextBlocks
directly created and managed by the linker, and one for TextBlocks
that were spawned by Module.Decl. This allows for correct memory
clean up after linking is done.
It makes sense to have them as a dependent type since they only ever
deal with TextBlocks. Simplify Relocations to rely on symbol indices
and symbol resolver rather than pointers.
Also, add a solution to a degenerate case where on x86_64 a relocation
refers to a cell in a section via section start address even though
a symbol exists. In such case, make the section spawned symbol an alias
of the actual symbol.
section's alignment serving as the maximum alignment that
can be seen in this particular section. However, TextBlocks are
still allowed to have at most that alignment.
temporarily by iterating over all defined TextBlocks. However,
once we merge this with MachO incremental, updates will be done
at the point of creation and/or update.
Also, fix mining TLV knowledge for working out TLV pointers.
instead of pointer to the Symbol struct in the hope that we
can overwrite the Symbol in the object's symbol table with the
resolved Symbol later down the line.
which include:
* `__TEXT,__rodata` => `__DATA_CONST,__const`
* `__TEXT,__typelink` => `__DATA_CONST,__const`
* `__TEXT,__itablink` => `__DATA_CONST,__const`
* `__TEXT,__gosymtab` => `__DATA_CONST,__const`
* `__TEXT,__gopclntab` => `__DATA_CONST,__const`
Also, we treat section as containing machine code and mapping
it to `__TEXT,__text` if it is `S_REGULAR` and contains either
`S_ATTR_PURE_INSTRUCTIONS` or `S_ATTR_SOME_INSTRUCTIONS` or both.