168 Commits

Author SHA1 Message Date
Andrew Kelley
aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
Jakub Konka
f63eda3f6a macho: parse and sort data-in-code entries ahead of time 2023-02-06 16:08:42 +01:00
Jakub Konka
b32f5ee932 macho: downgrade alignment requirements for symtab in object files
Parse and sort relocations by address descending.
2023-02-06 13:23:08 +01:00
Jakub Konka
983e373409 macho: fix sorting symbols by seniority 2023-01-21 16:53:46 +01:00
Jakub Konka
3dff040ca5 macho: synthesise unwind records in absence of compact unwind section
Unlike Apple ld, we will not do any DWARF CFI parsing and simply
output DWARF type unwind records.
2023-01-21 13:37:48 +01:00
Jakub Konka
835a60a34f zld: parse, synthesise and emit unwind records 2023-01-20 18:43:16 +01:00
Jakub Konka
9b0c555db4 macho: fix regression in dead strip for x86_64
Correctly handle calculating encompassing atoms for local
relocations (`r_extern == 0`).
2022-10-30 10:49:00 +01:00
Jakub Konka
593b75b109 macho: some docs 2022-10-22 14:53:53 +02:00
Jakub Konka
5823f19c5e macho: gracefully handle uninitialized symtabs in objects 2022-10-22 07:59:24 +02:00
Jakub Konka
2c2ff4558f macho: fix handling of lack of subsections and tracking of inner symbols 2022-10-22 07:59:24 +02:00
Jakub Konka
c15e03ac79 macho: fix bug in incorrectly splicing nodes in trie 2022-10-22 07:59:23 +02:00
Jakub Konka
5b9eaf2938 macho: do not assume __la_symbol_ptr was created 2022-10-22 07:59:23 +02:00
Jakub Konka
d57639a308 macho: upstream rewritten traditional linker, zld
kubkon/zld gitrev 5733ed87abe2f07e1330c3232a252e9defec638a
2022-10-22 07:59:23 +02:00
Jakub Konka
f4706c23e9 macho: fix after sync with master 2022-09-18 11:01:29 +02:00
Jakub Konka
e601969244 macho: rewrite how we allocate space in incremental context 2022-09-18 10:00:04 +02:00
Jakub Konka
34f9360ea2 macho: do not call populateMissingMetadata in full link mode 2022-09-18 10:00:04 +02:00
Jakub Konka
e5da251635 macho: clean up use of section ids 2022-09-18 10:00:04 +02:00
Jakub Konka
05d0c42894 macho: move main driver loop for one-shot into standalone zld module 2022-09-18 10:00:03 +02:00
Jakub Konka
5391541f11 macho: do not assume every object has a symtab
For example, building stage2 requires an empty `empty.cc` source file
compiling which generates a valid translation unit with no symtab/strtab.
In this case, we cannot simply assume that every translation unit will
have a valid symtab; instead, we cautiously default the input symtab
and strtab fields to optional `null` to signal symtab's presence or its lack of.
In case the symtab is not present, we catch this fact when splitting
input sections into subsections and create a synthetic symbol per every
suitable section.
2022-09-17 18:42:47 +02:00
Andrew Kelley
2a96209c40
Merge pull request #12574 from Vexu/remove-bit-op-type-param
stage2+stage1: remove type parameter from bit builtins
2022-08-24 15:57:44 -04:00
Jakub Konka
cf9f6fd7f0 macho: fix compile errors in std.debug 2022-08-23 22:01:05 +02:00
Andrew Kelley
1ce71c86bf std.debug: implement support for DWARFv5 2022-08-23 00:28:45 -07:00
Keith Chambers
96737ef499
Dwarf: Added stroffsetsptr support (#12270)
* Added support for stroffsetsptr class in Dwarf stdlib

* Proper initializion of debug_str_offsets in DwarfInfo

* Added missing null initializer to DwarfInfo in Macho

* Added missing is_64 field to getAttrString in DwarfInfo

* Fixed formatting

* Added missing is_64 param to getAttrString

* Added required cast to usize

* Adding missing .debug_str_offsets initialization

* getAttrString now uses the str_offsets_base attr
2022-08-22 20:50:06 -04:00
Veikka Tuominen
62ff8871ed stage2+stage1: remove type parameter from bit builtins
Closes #12529
Closes #12511
Closes #6835
2022-08-22 11:19:20 +03:00
Andrew Kelley
fa620ef710 link.MachO: use accurate alignment attribute on pointers
Also adds a new method to ArrayList: appendUnalignedSlice
2022-08-10 22:28:05 -07:00
Andrew Kelley
cc56400e62 Revert "macho: allow unaligned offsets in object files"
This reverts commit 45c444ff18b43d30a7277e346174ba6eca4a6193.
2022-08-10 22:27:59 -07:00
Jakub Konka
45c444ff18 macho: allow unaligned offsets in object files 2022-08-10 18:45:46 -04:00
Jakub Konka
bb532584bc macho: update how we insert output sections
Instead of generating sections upfront, allow generation by scanning
the object files for input -> output sections mapping. Next, always
strive to keep output sections in the final container sorted as they
appear in the final binary. This makes the linker less messy wrt
handling of output sections sort order for dyld/macOS not to complain.
There's still more work to be done for incremental context though
to make this work but looks promising already.
2022-08-03 21:19:41 +02:00
Jakub Konka
f26d5ee7ea macho: sync with zld
gitrev a2c32e972f8c5adfcda8ed2d99379ae868f59c24

a2c32e972f
2022-08-03 21:19:41 +02:00
r00ster91
baafb8a491 std.fmt: add more invalid format string errors 2022-07-27 18:07:53 +03:00
Jakub Konka
20ea44ef10 macho: fix memory leak and refactor Target usage 2022-07-25 22:46:43 -07:00
Jakub Konka
ca74656685 macho: move GC code into dead_strip.zig module
Implement marking live atoms that reference other live atoms if
required by the compiler (via section attribute).
2022-07-22 16:58:21 +02:00
Jakub Konka
7345976261 macho: sort subsection symbols by seniority 2022-07-22 16:58:21 +02:00
Jakub Konka
39df241df4 macho: do not GC local symbols unless reference dead symbols
If a local references another local, we keep it. If it doesn't
reference anything, we keep it. Otherwise, we dead strip it.
2022-07-22 16:58:21 +02:00
Jakub Konka
a089a6dc4f macho: parse data-in-code when writing LINKEDIT segment 2022-07-22 16:58:21 +02:00
Jakub Konka
0da8ba816a macho: do not store stabs; generate on-the-fly instead 2022-07-22 16:58:21 +02:00
Jakub Konka
817939d20a macho: don't store GC roots globally
Instead, if dead-strip was requested, create a temp container and
pass it around.
2022-07-22 16:58:20 +02:00
Jakub Konka
61b4119a7d macho: link atom starting section by orig section id
In x86_64 relocs, it can so happen that the compiler
refers to the same atom by both the actual assigned symbol
and the start of the section. In this case, we need to
link the two together so add an alias.
2022-07-22 16:58:20 +02:00
Jakub Konka
d80fcc8a0b macho: rework symbol handling for incremental stage2 builds 2022-07-22 16:58:20 +02:00
Jakub Konka
eeb6d8f045 macho: fix compilation issues on 32bit hosts 2022-07-22 16:58:20 +02:00
Jakub Konka
9eb7e5182b macho: rework symbol handling to match zld/ELF
Now, each object file will store a mutable table of symbols that it
defines. Upon symbol resolution between object files, the symbol
will be updated with a globally allocated section ordinal and address
in virtual memory. If the object defines a globally available symbol,
its location only (comprising of the symbol index and object index)
will be stored in the globals map for easy access when relocating, etc.
This approach cleans up the symbol management significantly, and matches
the status quo used in zld/ELF.

Additionally, this makes scoping symbol stabs easier too as they are
now naturally contained within each object file.
2022-07-22 16:58:20 +02:00
Jakub Konka
03feea0fb2 macho: split section into subsections if requested and/or possible 2022-07-22 16:58:20 +02:00
Jakub Konka
d042b88c11 macho: put parsing into an atom into a helper 2022-07-22 16:58:20 +02:00
Jakub Konka
b81c48d985 macho: read the entire file contents into memory at once 2022-07-22 16:58:20 +02:00
Ali Chraghi
0e6285c8fc math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
Jakub Konka
26153ce73a dwarf: clean up allocations in std.dwarf module
While this code probably could do with some love and a redesign,
this commit fixes the allocations by making sure we explicitly
pass an allocator where required, and we use arenas for temporary
or narrowly-scoped objects such as a `Die` (for `Die` in particular,
not every `FormValue` will be allocated - we could duplicate, or
we can use an arena which is the proposal of this commit).
2022-04-21 00:06:52 +02:00
Veikka Tuominen
ef7282bab4 stage2 macho: workaround stage2 bugs 2022-04-15 16:05:27 +03:00
Andrew Kelley
2587474717 stage2: progress towards stage3
* The `@bitCast` workaround is removed in favor of `@ptrCast` properly
   doing element casting for slice element types. This required an
   enhancement both to stage1 and stage2.
 * stage1 incorrectly accepts `.{}` instead of `{}`. stage2 code that
   abused this is fixed.
 * Make some parameters comptime to support functions in switch
   expressions (as opposed to making them function pointers).
 * Avoid relying on local temporaries being mutable.
 * Workarounds for when stage1 and stage2 disagree on function pointer
   types.
 * Workaround recursive formatting bug with a `@panic("TODO")`.
 * Remove unreachable `else` prongs for some inferred error sets.

All in effort towards #89.
2022-04-14 10:12:45 -07:00
William Sengir
6de8b4bc3d std.dwarf: implement basic DWARF 5 parsing
DWARF 5 moves around some fields and adds a few new ones that can't be
parsed or ignored by our current DWARF 4 parser. This isn't a complete
implementation of DWARF 5, but this is enough to make stack traces
mostly work. Line numbers from C++ don't show up, but I know the info
is there. I think the answer is to iterate through .debug_line_str in
getLineNumberInfo, but I didn't want to fall into an even deeper rabbit
hole tonight.
2022-03-15 16:53:45 -04:00
Jakub Konka
f9f792ab70 zld: fix num nlist calc when there's no dynsymtab
Handle `__DATA,.rustc` section containing `rustc` metadata - this
is required to get crates like `serde_derive` link properly.
Note to self: this special section has to be copied __verbatim__
from the relocatable object file - this includes preserving its size
even though unpadded according the section's required alignment.
2022-01-13 20:02:11 +01:00