1816 Commits

Author SHA1 Message Date
Jakub Konka
2c68fb3d7c macho: merge Zld state with MachO state 2023-08-29 11:40:18 +02:00
Jakub Konka
42e0850d78 macho: save indexes to all sections of interest 2023-08-29 11:39:35 +02:00
Jakub Konka
84853c5c56 macho: unify resolving globals 2023-08-29 11:39:35 +02:00
Jakub Konka
7f6973fbae macho: unify segment handling 2023-08-29 11:39:35 +02:00
Jakub Konka
d17867939e macho: unify writeLinkeditSegmentData func 2023-08-29 11:39:35 +02:00
Jakub Konka
7f74b3562d macho: unify creating atoms 2023-08-29 11:39:35 +02:00
Jakub Konka
ef0d35e00c macho: unify allocating special symbols 2023-08-29 11:39:35 +02:00
Jakub Konka
664b983518 macho: unify writeSegmentHeaders func 2023-08-29 11:39:35 +02:00
Jakub Konka
b2773cd712 macho: move initSection into MachO from Zld 2023-08-29 11:39:34 +02:00
Jakub Konka
180979ee41 macho: move getOutputSection into Atom 2023-08-29 11:39:34 +02:00
Jakub Konka
f29d9ec61c macho: unify entry point handling 2023-08-29 11:39:34 +02:00
Jakub Konka
b2af2dc8b7 macho: move symbol resolver into zld driver's state 2023-08-29 11:39:34 +02:00
Jakub Konka
19afd794d0 macho: remove dead code 2023-08-29 11:39:34 +02:00
Jakub Konka
e54f286c3b macho: assert every global is extern in incremental context 2023-08-29 11:39:34 +02:00
Jakub Konka
e9ad9e04c9 macho: collect bind data by scanning atoms directly in objects 2023-08-29 11:39:34 +02:00
Jakub Konka
7c11355556 macho: collect rebase data by scanning atoms directly in objects 2023-08-29 11:39:34 +02:00
Jakub Konka
bf5c35145d macho: remove dead code 2023-08-29 11:39:34 +02:00
Jakub Konka
4b934b1f78 macho: use TableSection for stub entries in zld driver
Write thunks separately from other atoms - this can still be improved
by not using atoms at all, but one thing at a time.
2023-08-29 11:39:34 +02:00
Jakub Konka
ee02517bce macho: remove obsolete function createDyldStubBinderGotAtom 2023-08-29 11:39:34 +02:00
Jakub Konka
5750620715 macho: use TableSection for TLV pointer entries in zld driver 2023-08-29 11:39:34 +02:00
Jakub Konka
04e93dd265 macho: use TableSection for GOT entries in zld driver 2023-08-29 11:39:34 +02:00
Jakub Konka
837114f019 macho: change dyld_private_sym_index to dyld_private_atom_index in zld 2023-08-29 11:39:34 +02:00
Jakub Konka
da9e7e498a macho: unify Atom concept between drivers 2023-08-29 11:39:34 +02:00
Jakub Konka
85f2df5050 macho: unify more of the linker state 2023-08-29 11:39:34 +02:00
Jakub Konka
e1e0ccb0c7 macho: unify Section concept across drivers 2023-08-29 11:39:34 +02:00
Jakub Konka
05c9d6c00b macho: add simple error reporting for misc errors 2023-08-29 11:39:34 +02:00
Jakub Konka
7b282dffe6 macho: unify concept of SymbolWithLoc across drivers 2023-08-29 11:39:34 +02:00
Jakub Konka
702bcfecf5 macho: simplify input file parsing for both drivers 2023-08-29 11:39:34 +02:00
Jakub Konka
69193a4ae4 macho: remove page_size field as it can be computed when and where required 2023-08-29 11:39:34 +02:00
Jakub Konka
e6891b2422 macho: remove dead code 2023-08-29 11:39:34 +02:00
Jakub Konka
3b2b9fcbc5 darwin: move inference of SDK version into the linker
`std.zig.system.darwin.getSdk` now pulls only the SDK path
so we execute a child process only once and not twice as it was
until now since we parse the SDK version directly from the pulled path.
This is actually how `ld64` does it too.
2023-08-29 06:43:41 +02:00
Andrew Kelley
ada0010471 compiler: move unions into InternPool
There are a couple concepts here worth understanding:

Key.UnionType - This type is available *before* resolving the union's
fields. The enum tag type, number of fields, and field names, field
types, and field alignments are not available with this.

InternPool.UnionType - This one can be obtained from the above type with
`InternPool.loadUnionType` which asserts that the union's enum tag type
has been resolved. This one has all the information available.

Additionally:

* ZIR: Turn an unused bit into `any_aligned_fields` flag to help
  semantic analysis know whether a union has explicit alignment on any
  fields (usually not).
* Sema: delete `resolveTypeRequiresComptime` which had the same type
  signature and near-duplicate logic to `typeRequiresComptime`.
  - Make opaque types not report comptime-only (this was inconsistent
    between the two implementations of this function).
* Implement accepted proposal #12556 which is a breaking change.
2023-08-22 13:54:14 -07:00
Jakub Konka
b73ef34289 frontend: directly pass resolved frameworks container to the linker
We can infer the framework name from the included resolved framework
path.

Fix hash implementation, and bump linker hash value from 9 to 10.
2023-08-21 08:07:44 +02:00
Jakub Konka
4793dafa04 frontend: move framework path resolution from the linker to frontend 2023-08-20 10:43:20 +02:00
Jakub Konka
e687c87d69 macho: we no longer need to resolve framework dirs against sysroot 2023-08-20 08:37:44 +02:00
Andrew Kelley
7ef1eb1c27 InternPool: safer enum API
The key changes in this commit are:

```diff
-        names: []const NullTerminatedString,
+        names: NullTerminatedString.Slice,
-        values: []const Index,
+        values: Index.Slice,
```

Which eliminates the slices from `InternPool.Key.EnumType` and replaces
them with structs that contain `start` and `len` indexes. This makes the
lifetime of `EnumType` change from expiring with updates to InternPool,
to expiring when the InternPool is garbage-collected, which is currently
never.

This is gearing up for a larger change I started working on locally
which moves union types into InternPool.

As a bonus, I fixed some unnecessary instances of `@as`.
2023-08-17 18:16:03 -07:00
Jakub Konka
787e755a2f macho: tie FDEs and unwind records to all symbol aliases
This is in particular very important to the Zig language which
allows exporting the same symbol under different names. For instance,
it is possible to have a case such that:

```
...
4258 T _foo
4258 T _bar
...
```

In this case we need to keep track of both symbol names when resolving
FDEs and unwind records.
2023-08-16 12:07:37 +02:00
Jacob Young
c4848694d2 llvm: enable even without libllvm linked 2023-08-09 05:47:13 -04:00
Jakub Konka
f96d773d98 macho: append syslibroot to search dirs when resolving libSystem 2023-08-03 09:52:15 -07:00
Andrew Kelley
da91ef5c28 zig libc: restore functionality on macOS
Regressed in 2006add8496c47804ee3b6c562f420871cb4ea0a.

References to native_darwin_sdk are no longer kept in the frontend.
Instead the darwin SDK is detected as part of NativePaths and as part of
LibCInstallation.
2023-08-03 09:52:15 -07:00
Andrew Kelley
986a3d23ab frontend: make SystemLib.path optional
This can be null in two cases right now:
1. Windows DLLs that zig ships such as advapi32.
2. extern "foo" fn declarations where we find out about libraries too late
TODO: make this non-optional and resolve those two cases somehow.
2023-08-03 09:52:14 -07:00
Andrew Kelley
9e50f96087 MachO: put system_libs into libs not positionals
Putting them in both causes collisions because the same lib ends up
being linked in twice.

Putting them in positionals instead of libs makes their properties about
needed and weak being ignored.
2023-08-03 09:52:14 -07:00
Andrew Kelley
2725c20a72 coff: always link uuid.lib as part of mingw libc 2023-08-03 09:52:14 -07:00
Andrew Kelley
a08cc7d2ae compiler: resolve library paths in the frontend
search_strategy is no longer passed to Compilation at all; instead it is
used in the CLI code only.

When using Zig CLI mode, `-l` no longer has the ability to link
statically; use positional arguments for this.

The CLI has a small abstraction around library resolution handling which
is used to remove some code duplication regarding static libraries, as
well as handle the difference between zig cc CLI mode and zig CLI mode.

Thanks to this, system libraries are now included in the cache hash, and
thus changes to them will correctly cause cache misses.

In the future, lib_dirs should no longer be passed to Compilation at
all, because it is a frontend-only concept.

Previously, -search_paths_first and -search_dylibs_first were
Darwin-only arguments; they now work the same for all targets. Same
thing with --sysroot.

Improved the error reporting for failure to find a system library. An
example error now looks like this:

```
$ zig build-exe test.zig -lfoo -L. -L/a -target x86_64-macos --sysroot /home/andy/local
error: unable to find Dynamic system library 'foo' using strategy 'no_fallback'. search paths:
  ./libfoo.tbd
  ./libfoo.dylib
  ./libfoo.so
  /home/andy/local/a/libfoo.tbd
  /home/andy/local/a/libfoo.dylib
  /home/andy/local/a/libfoo.so
  /a/libfoo.tbd
  /a/libfoo.dylib
  /a/libfoo.so
```

closes #14963
2023-08-03 09:52:14 -07:00
Andrew Kelley
f887b02518
Merge pull request #16359 from g-w1/plan9-more-std
Plan 9: more standard library support
2023-08-03 09:41:20 -07:00
Jakub Konka
26adbf2cb7 macho: set first and last atom indexes to 0 when marking section for pruning 2023-08-03 00:12:30 +02:00
Jacob G-W
4d711e8edd Plan 9 linker: don't try to calculate the vaddr before we know it
Previously, this worked on small codebases, but it is not correct.
Unconditionally emitting a reloc fixes it (and it might be more performant).
2023-08-02 17:39:52 -04:00
Jacob G-W
6293a646e3 Plan9: support linking to external 'special' symbols 2023-08-02 17:39:52 -04:00
Jakub Konka
d6e095de2c macho: track unwind/dwarf cfi records by symbol rather than atom
This solves the nuance case of compiling hand-crafted assembly files
which do not feature `MH_SUBSECTIONS_VIA_SYMBOLS` flag resulting in
input `Atom`s encompassing multiple symbols each with unique unwind
information.
2023-08-02 21:45:33 +02:00
Jacob Young
228c956377 std: finish cleanup up asm
This also required implementing the necessary syntax in the x86_64 backend.
2023-07-31 03:49:21 -04:00