aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/DebugSymbols.zig
AgeCommit message (Collapse)Author
2022-09-09macho: use globals free list like in COFF linkerJakub Konka
2022-09-07macho+wasm: unify and clean up closing file handlesJakub Konka
2022-08-30coff: reorganize the linkerJakub Konka
2022-08-12macho: update __DWARF sections before and after writing out __LINKEDITJakub Konka
2022-08-03macho: do not preempt segment headers; do it when commiting to fileJakub Konka
This way, tracking segment-to-section mapping becomes a lot easier since it's effectively just start index plus number of sections defined within the segment. If a section becomes empty however care needs to be taken to remove the header upon committing to the final binary.
2022-08-03macho: fix linking in incremental contextJakub Konka
Fix incorrect writing of symtab and strtab in dSYM bundle in incremental context. Fix incorrectly navigating unnamed consts (freeing) in incremental context. This is currently hard-coded to require all consts to land in `__TEXT,__const`, which is wrong and needs a rewrite.
2022-08-03macho: sync with zldJakub Konka
gitrev a2c32e972f8c5adfcda8ed2d99379ae868f59c24 https://github.com/kubkon/zld/commit/a2c32e972f8c5adfcda8ed2d99379ae868f59c24
2022-07-22macho: do not GC local symbols unless reference dead symbolsJakub Konka
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-22macho: rework symbol handling for incremental stage2 buildsJakub Konka
2022-07-22macho: rework symbol handling to match zld/ELFJakub Konka
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-05-27math: make `cast` return optional instead of an errorAli Chraghi
2022-04-15stage2 macho: workaround stage2 bugsVeikka Tuominen
2022-04-13macho,x64: resolve debug info relocs for RIP-based addressingJakub Konka
Sometimes we will want to generate debug info for a constant that has been lowered to memory and not copied anywhere else. For this we will need to defer resolution on PIE platforms until all locals (including GOT entries) have been allocated.
2022-03-27dwarf: track type relocation state in Dwarf moduleJakub Konka
2022-03-19Sema: implement zirSwitchCaptureElse for error setsVeikka Tuominen
2022-03-08dwarf: move all dwarf into standalone moduleJakub Konka
Hook up Elf and MachO linkers to the new solution.
2022-03-05macho: fix incorrect line and pc advancementJakub Konka
2022-03-05macho: remove anon_struct_type which is now redundantJakub Konka
2022-03-05macho: migrate to named struct for slicesJakub Konka
2022-03-05macho: handle optional non-ptr types in DWARFJakub Konka
2022-02-16macho: handle binary updates in dSYM companion fileJakub Konka
* move DWARF in file if LINKEDIT spilled in dSYM * update VM addresses for all segments * introduce copyFileRangeOverlappedAll instead of File.copyRangeAll since we make lots of overlapping writes in MachO linker
2022-02-14macho: re-enable creating dSYM bundleJakub Konka
* update number of type abbrevs to match Elf linker * update `DebugSymbols` to write symbol and string tables at the end to match the `MachO` linker * TODO: update segment vm addresses when growing segments in the binary * TODO: store DWARF relocations in linker's interned arena
2022-01-25stage2: add naive impl of pointer type in ELFJakub Konka
Augment relocation tracking mechanism to de-duplicate potential creation of base as well as composite types while unrolling composite types in the linker - there is still potential for further space optimisation by moving all type information into a separate section `.debug_types` and providing references to entries within that section whenever required (e.g., `ref4` form). Currently, we duplicate type definitions on a per-decl basis. Anyhow, with this patch, an example function signature of the following type: ```zig fn byPtrPtr(ptr_ptr_x: **u32, ptr_x: *u32) void { ptr_ptr_x.* = ptr_x; } ``` will generate the following `.debug_info` for formal parameters: ``` <1><1aa>: Abbrev Number: 3 (DW_TAG_subprogram) <1ab> DW_AT_low_pc : 0x8000197 <1b3> DW_AT_high_pc : 0x2c <1b7> DW_AT_name : byPtrPtr <2><1c0>: Abbrev Number: 7 (DW_TAG_formal_parameter) <1c1> DW_AT_location : 1 byte block: 55 (DW_OP_reg5 (rdi)) <1c3> DW_AT_type : <0x1df> <1c7> DW_AT_name : ptr_ptr_x <2><1d1>: Abbrev Number: 7 (DW_TAG_formal_parameter) <1d2> DW_AT_location : 1 byte block: 54 (DW_OP_reg4 (rsi)) <1d4> DW_AT_type : <0x1e4> <1d8> DW_AT_name : ptr_x <2><1de>: Abbrev Number: 0 <1><1df>: Abbrev Number: 5 (DW_TAG_pointer_type) <1e0> DW_AT_type : <0x1e4> <1><1e4>: Abbrev Number: 5 (DW_TAG_pointer_type) <1e5> DW_AT_type : <0x1e9> <1><1e9>: Abbrev Number: 4 (DW_TAG_base_type) <1ea> DW_AT_encoding : 7 (unsigned) <1eb> DW_AT_byte_size : 4 <1ec> DW_AT_name : u32 ```
2022-01-24stage2: rework a lot of stuffAndrew Kelley
AstGen: * rename the known_has_bits flag to known_non_opv to make it better reflect what it actually means. * add a known_comptime_only flag. * make the flags take advantage of identifiers of primitives and the fact that zig has no shadowing. * correct the known_non_opv flag for function bodies. Sema: * Rename `hasCodeGenBits` to `hasRuntimeBits` to better reflect what it does. - This function got a bit more complicated in this commit because of the duality of function bodies: on one hand they have runtime bits, but on the other hand they require being comptime known. * WipAnonDecl now takes a LazySrcDecl parameter and performs the type resolutions that it needs during finish(). * Implement comptime `@ptrToInt`. Codegen: * Improved handling of lowering decl_ref; make it work for comptime-known ptr-to-int values. - This same change had to be made many different times; perhaps we should look into merging the implementations of `genTypedValue` across x86, arm, aarch64, and riscv.
2021-12-15macho: put `LC_*` consts in a typed enum(u32) LCJakub Konka
repeat for `PLATFORM_*` and `TOOL_*` sets
2021-12-10macho: move all helpers from commands.zig into std.machoJakub Konka
This way we will finally be able to share common parsing logic between different Zig components and 3rd party packages.
2021-12-10macho: move helper functions to libstdJakub Konka
Helper functions such as `commands.sectionName`, etc. should really belong in `std.macho.section_64` extern struct.
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-11-04Replace ArrayList.init/ensureTotalCapacity pairs with initCapacityRyan Liptak
Because ArrayList.initCapacity uses 'precise' capacity allocation, this should save memory on average, and definitely will save memory in cases where ArrayList is used where a regular allocated slice could have also be used.
2021-09-19Update all ensureCapacity calls to the relevant non-deprecated versionRyan Liptak
2021-09-13Merge remote-tracking branch 'origin/master' into zld-incrJakub Konka
2021-09-01stage2: update for new usingnamespace semanticsAndrew Kelley
2021-09-01stage2: first pass at implementing usingnamespaceAndrew Kelley
Ran into a design flaw here which will need to get solved by having AstGen annotate ZIR with which instructions are closed over.
2021-08-31macho: fix allocating sections within segment when parsing objectsJakub Konka
2021-07-15zld: remove StringTable abstractionJakub Konka
2021-07-15zld: abstract away string table with fewer allocsJakub Konka
2021-07-15zld: clean up logic for creating mach headerJakub Konka
2021-06-24zld+macho: populate segname from SegmentCommand when adding sectionJakub Konka
2021-06-24zld+stage2: refactor creating segments and sectionsJakub Konka
Move the logic into default-init structs part of constructors in `SegmentCommand` struct in `commands.zig` module.
2021-06-21fix code broken from previous commitJacob G-W
2021-06-21std, src, doc, test: remove unused variablesJacob G-W
2021-06-03Breaking hash map changes for 0.8.0Martin Wickham
- hash/eql functions moved into a Context object - *Context functions pass an explicit context - *Adapted functions pass specialized keys and contexts - new getPtr() function returns a pointer to value - remove functions renamed to fetchRemove - new remove functions return bool - removeAssertDiscard deleted, use assert(remove(...)) instead - Keys and values are stored in separate arrays - Entry is now {*K, *V}, the new KV is {K, V} - BufSet/BufMap functions renamed to match other set/map types - fixed iterating-while-modifying bug in src/link/C.zig
2021-05-16MachO/DebugSymbols: fix debug line offsetAndrew Kelley
In c8b78706b74d16ed21113096d2b47717abb53d4d I incorrectly made it be the line offset from Decl to function lbrace; it needed to be line offset from lbrace to rbrace.
2021-05-16linker: update MachO DebugSymbols to use the new line/column Decl APIAndrew Kelley
2021-05-16Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
Need that _main -> main improvement
2021-05-16macho: fix DWARF in dSYM and sym naming more consistentJakub Konka
* Advance line and PC prior to ending sequence in debug line program for a fn_decl. This is equivalent to closing scope in the debugger and without it, the debugger will not map source-to-address info as a result will not print the source when breaking at a symbol. * Fix debug aranges sentinels to be of the size as the actual tuple descriptor (assuming segment selector to be ommitted). In summary, the sentinels were 32bit 0s, whereas they ought to be 64bit 0s. * Make naming of symbols in the binary more consistent by prefixing each symbol name with an underscore '_'.
2021-05-13link/MachO: fixes to debug symbolsAndrew Kelley
commitDeclDebugInfo: stop trying to write length 0 debug info - avoids hitting an error where zig tries to move the debug info section unnecessarily, gets confused, and reports `error.InputOutput`. The 2 pieces of code that looked at the source and tried to compute source line offsets is now improved to match link/Elf - use the line/column data stored in the Decl object to skip the costly scanning of source bytes. No need to load Zig source code, AST, or tokens, when we have the ZIR!
2021-04-28stage2: semaDecl properly analyzes the decl blockAndrew Kelley
Also flattened out Decl TypedValue fields into ty, val, has_tv and add relevant fields to Decl for alignment and link section.
2021-04-15stage2: entry point via std lib and proper updated file detectionAndrew Kelley
Instead of Module setting up the root_scope with the root source file, instead, Module relies on the package table graph being set up properly, and inside `update()`, it does the equivalent of `_ = @import("std");`. This, in term, imports start.zig, which has the logic to call main (or not). `Module` no longer has `root_scope` - the root source file is no longer special, it's just in the package table mapped to "root". I also went ahead and implemented proper detection of updated files. mtime, inode, size, and source hash are kept in `Scope.File`. During an update, iterate over `import_table` and stat each file to find out which ones are updated. The source hash is redundant with the source hash used by the struct decl that corresponds to the file, so it should be removed in a future commit before merging the branch. * AstGen: add "previously declared here" notes for variables shadowing decls. * Parse imports as structs. Module now calls `AstGen.structDeclInner`, which is called by `AstGen.containerDecl`. - `importFile` is a bit kludgy with how it handles the top level Decl that kinda gets merged into the struct decl at the end of the function. Be on the look out for bugs related to that as well as possibly cleaner ways to implement this. * Module: factor out lookupDeclName into lookupIdentifier and lookupNa * Rename `Scope.Container` to `Scope.Namespace`. * Delete some dead code. This branch won't work until `usingnamespace` is implemented because it relies on `@import("builtin").OutputMode` and `OutputMode` comes from a `usingnamespace`.