{"id":15570787,"url":"https://github.com/keith/ubsan-xcode-absolute-paths","last_synced_at":"2025-10-03T00:31:29.544Z","repository":{"id":143169512,"uuid":"573217635","full_name":"keith/ubsan-xcode-absolute-paths","owner":"keith","description":"Example of forcing absolute paths in ubsan errors for Xcode","archived":false,"fork":false,"pushed_at":"2024-02-01T20:58:33.000Z","size":25,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-16T22:43:17.930Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/keith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-12-02T00:25:03.000Z","updated_at":"2022-12-04T04:57:46.000Z","dependencies_parsed_at":"2023-07-22T21:18:16.250Z","dependency_job_id":null,"html_url":"https://github.com/keith/ubsan-xcode-absolute-paths","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keith%2Fubsan-xcode-absolute-paths","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keith%2Fubsan-xcode-absolute-paths/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keith%2Fubsan-xcode-absolute-paths/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keith%2Fubsan-xcode-absolute-paths/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keith","download_url":"https://codeload.github.com/keith/ubsan-xcode-absolute-paths/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235053760,"owners_count":18928440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T17:44:37.733Z","updated_at":"2025-10-03T00:31:29.215Z","avatar_url":"https://github.com/keith.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Summary\n\nThis repo has an example of how you can create a dylib to work around\nissues with ubsan warnings with relative paths in Xcode.\n\nSpecifically if you have reproducible builds, there will be no absolute\npaths in ubsan errors, but Xcode expects all file paths in ubsan errors\nto be absolute in order for it to show annotations in the editor\npointing to the specific issues.\n\nWarning: this heavily relies today's (Xcode 14.1) internals of ubsan +\nlldb.\n\n## How to use\n\n1. Compile `ubsan-hacks.c` into `libclang_rt.ubsan_hacks.dylib` (see\n   `build-hacks-dylib.sh` for an example)\n2. Run your binary with `SRCROOT=$(SRCROOT)` in the environment to\n   provide the root path for source files\n3. Insert that library at runtime with\n   `DYLD_INSERT_LIBRARIES=/path/to/dylib`\n4. When ubsan errors are produced, Xcode annotations should work\n   correctly\n\nNote: if you're not attaching lldb in Xcode you don't need this since\nXcode doesn't show annotations at all in that case.\n\nNote: the stack trace of the ubsan errors include a few extra stack\nframes because lldb attempts to filter these out based on a heuristic\nthat we're violating.\n\n## How it works\n\nUbsan's errors include file paths from your binary by referencing\ninstances of\n[`OverflowData`](https://github.com/llvm/llvm-project/blob/3a86931f56a9a1cd96a491119eb30fea76fbf9a7/compiler-rt/lib/ubsan/ubsan_handlers.h#L52-L55)\nin your binary. These paths come from the paths on the command line, and\nare relative in the case you pass relative paths to the compiler.\n\nWhen ubsan produces errors at runtime, its monitoring mechanism calls\n`__ubsan_on_report`, which lldb sets an internal breakpoint for (you can\nsee internal breakpoints with `br list -i`). lldb then calls ubsan's\n`__ubsan_get_current_report_data` function to get the specific\ninformation of the current report. The instance of\n`__ubsan_get_current_report_data` it calls, and the `__ubsan_on_report`\nmust reside in the same module.\n\nThis hack works by:\n\n1. Tricking lldb into thinking this library is ubsan so it sets the\n   `__ubsan_on_report` breakpoint in our library instead of in the\n   actual ubsan library\n2. Once ubsan finds an error, since the breakpoint is in our module, it\n   then calls `__ubsan_get_current_report_data` in our module instead.\n   We use this hook to call the original function, and fixup the path to\n   be absolute if it's not already.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeith%2Fubsan-xcode-absolute-paths","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeith%2Fubsan-xcode-absolute-paths","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeith%2Fubsan-xcode-absolute-paths/lists"}