Also, calculate non-extern, section offset based addends for SIGNED
and UNSIGNED relocations on x86_64 upfront as an offset wrt to the
target symbol representing position of the section/atom within the
final artifact.
Otherwise, Apple's tooling goes mental and reports that the executable
is malformed/fails strict validation. We absolutely have to get it
right to support tools such `codesign` which are required to
successfully launch an app on an iOS device for instance. When Zig
matures enough so that we can ditch any Apple tooling and still be
able to successfully codesign for iOS and other, we can revisit this
area. Until then however, we are stuck in having to rewrite the LINKEDIT
segment at every update run of the self-hosted.
FYI, the strict layout for the MachO binary apparently is (please,
read this with a pinch of salt as this is inferred by me):
* __TEXT segment
* __DATA_CONST segment
* __DATA segment
* __LINKEDIT segment
* dyld info (rebase, bind, weak bind, lazy bind, export)
* symbol table
* dynamic symbol table
* string table
* code signature (if expected)
Instead of checking for stage1 at every callsite, move the logic
inside `allocateAtom`. This is fine since this logic will disappear
anyhow once I add expanding and shifting segments and sections.
This commit makes it possible to combine self-hosted with a pre-compiled
C object file, e.g.:
```
zig-out/bin/zig build-exe hello.zig add.o
```
where `add.o` is a pre-compiled C object file.
This way, we will conform to the standard practice of setting the
offset within the section header to the beginning of the file and
we will be able to track the location of the section in the file
for incremental updates.
Locals are not allowed to shadow declarations, but declarations are
allowed to shadow each other, as long as there are no ambiguous
references.
closes#678
Instead of referencing stub indices since these can now be obtained
in a more generic fashion from the actual linked-list of atoms in
the __stub_helper section.
This is a backwards-compatible language change.
Previously, `@intToEnum` coerced its integer operand to the integer tag
type of the destination enum type, often requiring the callsite to
additionally wrap the operand in an `@intCast`. Now, the `@intCast` is
implicit, and any integer operand can be passed to `@intToEnum`.
The same as before, it is illegal behavior to pass any integer which does
not have a corresponding enum tag.
With this routine, we are now able to freely shift stub_helper
section in memory and in file since the VM addressing is now dynamically
dependent on the positioning of `__stub_helper` preamble and other
sections generated by the linker.