Implementing stack trace capture on iree_status_t for Win/Mac. (#15151)

Enabled only when `IREE_STATUS_MODE`>=3, which by default means off in
release builds and on in debug builds. Capturing stacks isn't free so
performance sensitive code should keep them off, though we do split the
symbol resolution/string formatting such that it's not the worst thing
if they are always-on. It's important that we consistently use
`iree_status_from_code` when using status returns for control flow.

Example from Windows:
```
D:\Dev\iree\runtime\src\iree\base\internal\file_io.c:295: NOT_FOUND; failed to open file 'oops.vmfb'; stack:
  0x00007ff6346eeff3 iree-run-module <iree_file_map_contents_readonly_platform+0xa3> (D:\Dev\iree\runtime\src\iree\base\internal\file_io.c:294)
  0x00007ff6346eece7 iree-run-module <iree_file_map_contents_readonly+0x117> (D:\Dev\iree\runtime\src\iree\base\internal\file_io.c:229)
  0x00007ff6346eea13 iree-run-module <iree_file_read_contents+0xa3> (D:\Dev\iree\runtime\src\iree\base\internal\file_io.c:132)
  0x00007ff634622c9d iree-run-module <iree_tooling_load_bytecode_module+0x27d> (D:\Dev\iree\runtime\src\iree\tooling\context_util.c:73)
  0x00007ff634621f97 iree-run-module <iree_tooling_load_modules_from_flags+0x347> (D:\Dev\iree\runtime\src\iree\tooling\context_util.c:155)
  0x00007ff6346259d4 iree-run-module <iree_tooling_create_run_context+0x74> (D:\Dev\iree\runtime\src\iree\tooling\run_module.c:96)
  0x00007ff634624e3e iree-run-module <iree_tooling_run_module_with_data+0x11e> (D:\Dev\iree\runtime\src\iree\tooling\run_module.c:341)
  0x00007ff634624d10 iree-run-module <iree_tooling_run_module_from_flags+0x90> (D:\Dev\iree\runtime\src\iree\tooling\run_module.c:327)
  0x00007ff63461a32e iree-run-module <main+0x10e> (D:\Dev\iree\tools\iree-run-module-main.c:43)
  0x00007ff6347d92e9 iree-run-module <invoke_main+0x39> (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79)
  0x00007ff6347d918e iree-run-module <__scrt_common_main_seh+0x12e> (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
  0x00007ff6347d904e iree-run-module <__scrt_common_main+0xe> (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331)
  0x00007ff6347d937e iree-run-module <mainCRTStartup+0xe> (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17)
  0x00007ffc27b97344 ??? <BaseThreadInitThunk+0x14>
  0x00007ffc29a026b1 ??? <RtlUserThreadStart+0x21>
; loading bytecode module at 'oops.vmfb'; loading modules and dependencies; creating run context
```

Example from MacOS:
```
iree/runtime/src/iree/base/internal/file_io.c:253: NOT_FOUND; failed to open file '/Users/ben/Dev/iree/../iree-tmp/foo.vmfb'; stack:
  0x0000000100093644 iree-run-module <iree_file_map_contents_readonly_platform+0x64>
  0x0000000100093318 iree-run-module <iree_file_map_contents_readonly+0x12c>
  0x0000000100092ff0 iree-run-module <iree_file_read_contents+0x80>
  0x0000000100028a04 iree-run-module <iree_tooling_load_bytecode_module+0x208>
  0x0000000100028518 iree-run-module <iree_tooling_load_modules_from_flags+0x28c>
  0x000000010002ab90 iree-run-module <iree_tooling_create_run_context+0x68>
  0x000000010002a9d8 iree-run-module <iree_tooling_run_module_with_data+0x98>
  0x000000010002a934 iree-run-module <iree_tooling_run_module_from_flags+0x64>
  0x0000000100006228 iree-run-module <main+0xcc>
  0x000000018dd61058 dyld <start+0x8b0>
; loading bytecode module at '/Users/ben/Dev/iree/../iree-tmp/foo.vmfb'; loading modules and dependencies; creating run context
```

Example from Linux:
```
iree/runtime/src/iree/base/internal/file_io.c:199: NOT_FOUND; failed to open file 'oops.vmfb'; stack:
  0x00000000004cdafc iree-run-module <???>
  0x0000000000725319 iree-run-module <???>
  0x0000000000724e7b iree-run-module <???>
  0x00000000004dddc2 iree-run-module <???>
  0x00000000004dc898 iree-run-module <???>
  0x00000000004e7123 iree-run-module <???>
  0x00000000004e6586 iree-run-module <???>
  0x00000000004e5f8a iree-run-module <???>
  0x00000000004c8623 iree-run-module <???>
  0x00007f84b58e1083 libc.so.6 <__libc_start_main+0xf3>
  0x000000000041d9ce iree-run-module <???>
; loading bytecode module at 'oops.vmfb'; loading modules and dependencies; creating run context
```
^ https://www.youtube.com/watch?v=lRAZk0Xb0xM

If we want stack traces with symbols on linux we'll need to have
libdwarf-dev installed and use it to resolve things ala
https://gist.github.com/tuxology/6144170 - I'm happy with having symbols
on Windows and basic ones in debug mode on Mac for now. We've got
everything in place for making linux resolution better if someone cares.
I couldn't figure out how to make the builds happy with all the
GNU_SOURCE shenannigans and just disabled the whole thing for now.

Fixes #55.
4 files changed
tree: b884a23fb329950aefbbe14bdd2ea967bcd2450d
  1. .devcontainer/
  2. .github/
  3. build_tools/
  4. compiler/
  5. docs/
  6. experimental/
  7. integrations/
  8. lib/
  9. llvm-external-projects/
  10. runtime/
  11. samples/
  12. tests/
  13. third_party/
  14. tools/
  15. .bazel_to_cmake.cfg.py
  16. .bazelignore
  17. .bazelrc
  18. .bazelversion
  19. .clang-format
  20. .dockerignore
  21. .git-blame-ignore-revs
  22. .gitignore
  23. .gitmodules
  24. .yamllint.yml
  25. AUTHORS
  26. BUILD.bazel
  27. CITATION.cff
  28. CMakeLists.txt
  29. configure_bazel.py
  30. CONTRIBUTING.md
  31. LICENSE
  32. README.md
  33. WORKSPACE
README.md

IREE: Intermediate Representation Execution Environment

IREE (Intermediate Representation Execution Environment, pronounced as “eerie”) is an MLIR-based end-to-end compiler and runtime that lowers Machine Learning (ML) models to a unified IR that scales up to meet the needs of the datacenter and down to satisfy the constraints and special considerations of mobile and edge deployments.

See our website for project details, user guides, and instructions on building from source.

CI Status

Project Status

IREE is still in its early phase. We have settled down on the overarching infrastructure and are actively improving various software components as well as project logistics. It is still quite far from ready for everyday use and is made available without any support at the moment. With that said, we welcome any kind of feedback on any communication channels!

Communication Channels

Related Project Channels

  • MLIR topic within LLVM Discourse: IREE is enabled by and heavily relies on MLIR. IREE sometimes is referred to in certain MLIR discussions. Useful if you are also interested in MLIR evolution.

Architecture Overview

IREE Architecture IREE Architecture

See our website for more information.

Presentations and Talks

License

IREE is licensed under the terms of the Apache 2.0 License with LLVM Exceptions. See LICENSE for more information.