256 Commits

Author SHA1 Message Date
Jacob Young
f3d0fc7a66 backends: port to new std.io.BufferedWriter API 2025-07-01 16:35:26 -07:00
Alex Rønne Petersen
f87b443af1 link.MachO: Add support for the -x flag (discard local symbols).
This can also be extended to ELF later as it means roughly the same thing there.

This addresses the main issue in #21721 but as I don't have a macOS machine to
do further testing on, I can't confirm whether zig cc is able to pass the entire
cgo test suite after this commit. It can, however, cross-compile a basic program
that uses cgo to x86_64-macos-none which previously failed due to lack of -x
support. Unlike previously, the resulting symbol table does not contain local
symbols (such as C static functions).

I believe this satisfies the related donor bounty: https://ziglang.org/news/second-donor-bounty
2025-02-22 06:35:19 +01:00
Andrew Kelley
16180f525a macho linker: conform to explicit error sets
Makes linker functions have small error sets, required to report
diagnostics properly rather than having a massive error set that has a
lot of codes.

Other linker implementations are not ported yet.

Also the branch is not passing semantic analysis yet.
2025-01-15 15:11:35 -08:00
Jakub Konka
0769afbb0f macho: refactors errors from parsing DWARF
Currently we don't report any errors to the user due to a bug in
self-hosted x86_64-macos backend.
2024-12-02 22:05:21 -05:00
Jakub Konka
c824b35051 macho: move things around in MachO/Object.zig and refactor 2024-12-02 22:05:21 -05:00
Jakub Konka
8e81500051 macho: handle DWARFv5 when parsing debug info in objects 2024-12-02 22:05:21 -05:00
Jakub Konka
7e530c13b3 macho: create dummy atom of size 0 marking end of a section
Some compilers such as Go reference the end of a section (addr + size)
which cannot be contained in any non-zero atom (since then this atom
would exceed section boundaries). In order to facilitate this behaviour,
we create a dummy zero-sized atom at section end (addr + size).
2024-10-12 02:53:15 -07:00
Andrew Kelley
14c8e270bb link: fix false positive crtbegin/crtend detection
Embrace the Path abstraction, doing more operations based on directory
handles rather than absolute file paths. Most of the diff noise here
comes from this one.

Fix sorting of crtbegin/crtend atoms. Previously it would look at all
path components for those strings.

Make the C runtime path detection partially a pure function, and move
some logic to glibc.zig where it belongs.
2024-10-10 14:21:52 -07:00
Linus Groh
8588964972 Replace deprecated default initializations with decl literals 2024-09-12 16:01:23 +01:00
mlugg
0fe3fd01dd
std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.

This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
2024-08-28 08:39:59 +01:00
Alex Rønne Petersen
fb6f5a30b2
link: Rename InvalidCpuArch error to InvalidMachineType. 2024-08-23 19:56:29 +02:00
Jakub Konka
06a0da3e8a macho: cache string len 2024-07-22 12:06:02 +02:00
Jakub Konka
2b84592858 macho: run more things in parallel 2024-07-22 12:06:02 +02:00
Jakub Konka
cba3389d90 macho: redo input file parsing in prep for multithreading 2024-07-22 12:05:56 +02:00
Jakub Konka
34f34dbe32 macho: reinstate duplicate definition checking 2024-07-18 09:13:09 +02:00
Jakub Konka
e9328e7da8 macho: fix 32bit compilation issues 2024-07-18 09:13:09 +02:00
Jakub Konka
b62281a9c8 macho: re-enable relocatable mode 2024-07-18 09:13:08 +02:00
Jakub Konka
90c54f1eb6 macho: fix symbol visibility merging logic 2024-07-18 09:13:08 +02:00
Jakub Konka
3d58faed12 macho: we do not yet support interposable symbols 2024-07-18 09:13:08 +02:00
Jakub Konka
18778e2a0a macho: bring back parts of ar 2024-07-18 09:13:08 +02:00
Jakub Konka
174de37cef macho: fix compile errors 2024-07-18 09:13:08 +02:00
Jakub Konka
355992cbdf macho: migrate some of MachO driver 2024-07-18 09:13:08 +02:00
Jakub Konka
b9bac32a25 macho: migrate Atom and Symbol 2024-07-18 09:13:08 +02:00
Jakub Konka
9d5a900f4b macho: migrate Object to self-ownership of atoms and symbols 2024-07-18 09:13:08 +02:00
Jakub Konka
e2bfd6fc69 macho: revamp how we compute dyld relocs 2024-07-18 09:13:07 +02:00
Jakub Konka
101299e856 macho: move unwind info records ownership to Objects 2024-07-18 09:13:07 +02:00
Jakub Konka
ed7073c630 link/macho: fix perf bug in DWARF parsing 2024-05-24 15:34:48 +02:00
Jakub Konka
d31eb744ce link/macho: fix 32bit build 2024-05-23 12:04:17 +02:00
Jakub Konka
f3a503eca2 link/macho: ensure we set alignment of literals to max alignment 2024-05-23 12:04:17 +02:00
Jakub Konka
8fc0c7dce1 link/macho: apply fixes to deduping logic
* test non-ObjC literal deduping logic
2024-05-23 12:04:17 +02:00
Jakub Konka
434e69482e link/macho: dedup literals in objects and internal object file 2024-05-23 12:04:17 +02:00
zhylmzr
3648d7df19 fix: object size error in archive 2024-04-25 18:27:11 +02:00
Jakub Konka
6fd09f8d2d link/macho: make --verbose-link represent the actual linker line 2024-04-22 15:14:56 +02:00
Jakub Konka
a7e4d17226 link/macho: introduce Atom extras for out-of-band data 2024-04-22 12:21:37 +02:00
Jakub Konka
9e402704e2 macho: correctly find N_GSYM symbols when parsing symbol stabs
In `ld -r` mode, the linker will emit `N_GSYM` for any defined
external symbols as well as private externals. In the former case,
the thing is easy since `N_EXT` bit will be set in the nlist's type.
In the latter however we will encounter a local symbol with `N_PEXT`
bit set (non-extern, but was private external) which we also need
to include when resolving symbol stabs.

The major change in the logic for parsing symbol stabs per input
object file is that we no longer try to force-resolve a `N_GSYM`
as a global symbol. This was a mistake since every symbol stab
always describes a symbol defined within the parsed input object file.
We then work out if we should forward `N_GSYM` in the output symtab
after we have resolved all symbols, but never before - intel we lack
when initially parsing symbol stabs. Therefore, we simply record
which symbol has a debug symbol stab, and work out its precise type
when emitting output symtab after symbol resolution has been done.
2024-03-01 10:18:10 +01:00
Jakub Konka
272fc2df2e macho: use preadAll to read in object files when emitting archive 2024-02-07 23:25:15 +01:00
Jakub Konka
f9eb14ddcf macho: parse input object files specifically for incl in archive 2024-02-07 19:27:26 +01:00
Jakub Konka
efa1c6124d macho: emit an archive 2024-02-07 19:27:26 +01:00
Jakub Konka
897a554109 macho: populate output archive symtab 2024-02-07 19:27:26 +01:00
Jakub Konka
db6addf31a macho: store open file descriptors in a global array 2024-02-06 17:38:50 +01:00
Jakub Konka
b8490c05c1 macho: improve weak-ref symbols handling 2024-01-30 13:56:08 +01:00
Jakub Konka
f2214e4371 macho: re-enable dSYM but don't write anything to it yet 2024-01-29 07:26:59 +01:00
Jakub Konka
5b315f8a3a macho: fix 32bit builds 2024-01-28 19:14:55 +01:00
Jakub Konka
6337ce16ae macho: do not allocate input files in full 2024-01-28 00:40:50 +01:00
Jakub Konka
f2dce0c337 macho: exclude symbols from empty sections when parsing unwind info 2024-01-24 12:34:42 +01:00
Jakub Konka
82628dd151 macho: synthesise unwind records from __eh_frame even if no __compact_unwind 2024-01-24 12:34:42 +01:00
Jakub Konka
06224c23b7 macho: fix 32bit compilation issues 2024-01-24 12:34:42 +01:00
Jakub Konka
67ea039426 macho: do not enforce platform check for now 2024-01-24 12:34:42 +01:00
Jakub Konka
a8629fb850 macho: fix symbol index dereference in codegen wrt ZigObject
This is incredibly confusing and I really need to simplify it.
Elf also possesses this shortcoming so once I get Coff up to speed
it should hopefully become clear on how to refactor this.
2024-01-24 12:34:41 +01:00
Jakub Konka
bd9d8bd462 macho: create Atom for Decl in ZigObject 2024-01-24 12:34:41 +01:00