Commit Graph

25031 Commits

Author SHA1 Message Date
kcbanner
7bc1695f15 c: musl doesn't implement getcontext, so defer to our implementation in that case 2023-07-20 22:58:14 -04:00
kcbanner
9c908ea814 test: add standalone test for DWARF unwinding with -fomit-frame-pointer 2023-07-20 22:58:14 -04:00
kcbanner
23d9b59b86 c: add getcontext
debug: make getContext public
2023-07-20 22:58:14 -04:00
kcbanner
f991b9dc05 debug: fix reading -gdwarf generated debug sections in COFF files
I had accidentally regressed support for -gdwarf in 461fb499f3 when I changed the logic to
use the already-mapped exe/dll image instead of loading it from disk. The string table is mapped as all zeroes by the loader,
so if a section header's name is longer than 8 bytes (like the ones generated by -gdwarf), then the name can't be read.

Now, if any section headers require the string table, the file is mapped from disk.

windows: Add NtCreateSection/NtMapViewOfSection/NtUnmapViewOfSection
2023-07-20 22:58:14 -04:00
kcbanner
caa334712f linux: rework getcontext to closer match the specification (saved IP/SP match the state after it would return)
debug: fixup ucontext_t check
2023-07-20 22:58:14 -04:00
kcbanner
89ef004646 debug: x86 unwinding support, more unwinding fixes
- Fix unwindFrame using the previous FDE row instead of the current one
- Handle unwinding through noreturn functions
- Add x86-linux getcontext
- Fixup x86_64-linux getcontext not restoring the fp env
- Fix start_addr filtering on x86-windows
2023-07-20 22:58:14 -04:00
kcbanner
5cd8ab2473 debug: enhance writeCurrentStackTrace to use context-based unwinding when available 2023-07-20 22:58:14 -04:00
kcbanner
a9b6f2d929 dwarf: add support for .debug_frame and CIE version 4 2023-07-20 22:58:14 -04:00
kcbanner
41832aa1e6 linux: add getcontext for x86_64 2023-07-20 22:58:14 -04:00
kcbanner
6abf1fbfe6 update to new builtin syntax 2023-07-20 22:58:14 -04:00
kcbanner
84a1244b6c dwarf: use eh_frame length if it's available 2023-07-20 22:58:14 -04:00
kcbanner
521988299d add more safety checks when searching for eh_frame entries using findEntry 2023-07-20 22:58:13 -04:00
kcbanner
a47212c72e - rebase and update to lastest master 2023-07-20 22:58:13 -04:00
kcbanner
adbc5bbdb3 dwarf: fixup pointer cast 2023-07-20 22:58:13 -04:00
kcbanner
5781016c35 dwarf: add support for .eh_frame_hdr when unwinding
- .eh_frame_hdr contains a binary-searchable data structure for finding an FDE. If present, we can use this
section to avoid having to parse the entire FDE/CIE list in the binary, instead only entries that are actually
required for unwinding are read.
- rework the inputs pc-relative pointer decoding to support both already-mapped sections as well as sections
mapped from a file
- store the VirtualMachine on UnwindContext so the allocations can be reused
2023-07-20 22:58:13 -04:00
kcbanner
dd2035735f debug: fix memory leak when an error occurs opening a pdb file 2023-07-20 22:58:13 -04:00
kcbanner
865d4d2d8c debug: more fixups for mips linux not having ucontext_t
- increase test-std max_rss to 1.1 above the CI observed amount
2023-07-20 22:58:13 -04:00
kcbanner
5ebca4392e debug: fixing more compile errors on arches that I hadn't tested on yet 2023-07-20 22:58:13 -04:00
kcbanner
551f153718 dwarf: fixes for non-64 bit systems 2023-07-20 22:58:13 -04:00
kcbanner
2f75d20d87 debug: use an explicit context type instead of anytype for dumpStackTraceFromBase, update crash_report to use this for exceptions 2023-07-20 22:58:13 -04:00
kcbanner
d74c8acdfb dwarf: fixup for sort changes 2023-07-20 22:58:13 -04:00
kcbanner
d1a9bb1fea debug: fixup context detection for wasi 2023-07-20 22:58:13 -04:00
kcbanner
a325d7f6d1 fmt and cleanup 2023-07-20 22:58:13 -04:00
kcbanner
c98e03fc7e - rework CFI instruction parsing to not use std.meta
- move register formatting code to zig-dwardump
2023-07-20 22:58:13 -04:00
kcbanner
e72e762d1e dwarf: implement more register mappings, fix up macos compile 2023-07-20 22:58:13 -04:00
kcbanner
9145ff7da0 dwarf: implement more register number mappings
- add dwarf.abi.RegisterContext to handle register numbers changing based on DWARF format
2023-07-20 22:58:13 -04:00
kcbanner
b449d98a93 - rework StackIterator to optionally use debug_info to unwind the stack
- add abi routines for getting register values
- unwding is working!
2023-07-20 22:58:13 -04:00
kcbanner
69399fbb82 - add default register rule
- fixup eh pointer decoding
2023-07-20 22:58:13 -04:00
kcbanner
a0a40c2e7e - implement more opcodes 2023-07-20 22:58:13 -04:00
kcbanner
7b4611cfb3 - move writing code to zig-dwarfdump
- implement restore_state, restore_extended, offset_extended
2023-07-20 22:58:13 -04:00
kcbanner
338df862d1 - fix remember_state
- implement def_cfa_register
2023-07-20 22:58:13 -04:00
kcbanner
f3f3c877e0 - add DWARF expression parser
- change read apis to use a stream
- add register formatters
2023-07-20 22:58:13 -04:00
kcbanner
38303d7b9c add VirtualMachine to run CFA instructions 2023-07-20 22:58:13 -04:00
kcbanner
8b8d627137 - add call frame instruction parser
- add register printing
2023-07-20 22:58:13 -04:00
kcbanner
6c1d1aa45c begin working on parsing unwind info 2023-07-20 22:58:13 -04:00
kcbanner
f6148f123e add CommonInformationEntry parser 2023-07-20 22:58:12 -04:00
kcbanner
ea9917d9bd debug: support loading elf debug info from external files
Some distributions (ie. Ubuntu) have their libc debug
info in separate files. This change allows the stack walking
code to read that debug info.

- add support for reading compressed ELF sections
- support reading the build-id from the elf headers in order to lookup external debug info
- support reading the .gnu_debuglink section to look up external debug info
2023-07-20 22:58:12 -04:00
Hao Li
8a18abfd60
Remove the SingleThread limitation for ARM (#16442)
The libc++ issue has been fixed in https://reviews.llvm.org/D118391, so
we don't have this issue in llvm 16+

closes #6573
2023-07-20 19:17:28 -04:00
Frank Denis
124448c1b6 Include system headers path when targeting assembly_with_cpp
This is consistent with what clang and gcc are doing, because
headers such as <cet.h> are specifically designed to be used
in the context of assembly code.

Fixes #16449
2023-07-20 16:14:12 -07:00
Andrew Kelley
3f15010abe
Merge pull request #16430 from jacobly0/llvm-builder
llvm: begin the journey of independence from llvm
2023-07-20 12:55:03 -07:00
Linus Groh
3bada8e3ce std.hash_map: Fix casing of keyPtr variables
The only case where those should be written in camelCase is if they were
function pointers, which they aren't.
2023-07-20 12:52:05 -07:00
Alex Kladov
772debb03a reduce AstGen.numberLiteral stack usage
At the moment, the LLVM IR we generate for this fn is

define internal fastcc void @AstGen.numberLiteral ...  {
Entry:
  ...
  %16 = alloca %"fmt.parse_float.decimal.Decimal(f128)", align 8
  ...

That `Decimal` is huuuge! It stores

    pub const max_digits =  11564;
    digits: [max_digits]u8,

on the stack.

It comes from `convertSlow` function, which LLVM happily inlined,
despite it being the cold path. Forbid inlining that to not penalize
callers with excessive stack usage.

Backstory: I was looking for needles memcpys in TigerBeetle, and came up
with this copyhound.zig tool for doing just that:

   ee67e2ab95/src/copyhound.zig

Got curious, run it on the Zig's own code base, and looked at some of
the worst offenders.

List of worst offenders:

warning: crypto.kyber_d00.Kyber.SecretKey.decaps: 7776 bytes memcpy
warning: crypto.ff.Modulus.powPublic: 8160 bytes memcpy
warning: AstGen.numberLiteral: 11584 bytes memcpy
warning: crypto.tls.Client.init__anon_133566: 13984 bytes memcpy
warning: http.Client.connectUnproxied: 16896 bytes memcpy
warning: crypto.tls.Client.init__anon_133566: 16904 bytes memcpy
warning: objcopy.ElfFileHelper.tryCompressSection: 32768 bytes memcpy

Note from Andrew: I removed `noinline` from this commit since it should
be enough to set it to be cold.
2023-07-20 12:51:18 -07:00
xdBronch
e313584a48 more UEFI alignment fixes 2023-07-20 12:46:33 -07:00
Jacob Young
17255bed41
Merge pull request #16443 from notcancername/cbe-empty-enum
cbe: fix bug where empty enum would be generated
2023-07-20 02:47:26 -04:00
Jacob Young
4d31d4d875 llvm: cleanup LLVM IR dumping 2023-07-20 02:44:40 -04:00
Jacob Young
a1062c63ca llvm: add Builder trailing extra interface 2023-07-20 01:48:50 -04:00
Jacob Young
ea72fea1a4 llvm: fix bootstrap 2023-07-19 23:39:42 -04:00
Jacob Young
9dd7a9eb02 llvm: fix various crashes 2023-07-19 23:38:40 -04:00
Jacob Young
9c4d5e64b4 llvm: minor fixes 2023-07-19 23:38:40 -04:00
Jacob Young
9afb349aba llvm: convert most instructions 2023-07-19 23:38:40 -04:00