{"id":16976153,"url":"https://github.com/ashvardanian/libsee","last_synced_at":"2025-07-29T16:42:41.523Z","repository":{"id":228453723,"uuid":"767278638","full_name":"ashvardanian/LibSee","owner":"ashvardanian","description":"Link to this library and it will log all the LibC functions you are calling and how much time you are spending in them!","archived":false,"fork":false,"pushed_at":"2025-01-04T17:17:10.000Z","size":169,"stargazers_count":18,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-07-21T16:48:45.865Z","etag":null,"topics":["assembly","benchmark","benchmarking","fuzzing","glibc","ld-preload","ld-preload-hack","libc"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ashvardanian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-03-05T02:10:11.000Z","updated_at":"2025-05-21T19:21:33.000Z","dependencies_parsed_at":"2024-03-20T22:30:39.875Z","dependency_job_id":"b1844ed7-273e-4498-bdbd-0b889143aa67","html_url":"https://github.com/ashvardanian/LibSee","commit_stats":null,"previous_names":["ashvardanian/libsee"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ashvardanian/LibSee","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashvardanian%2FLibSee","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashvardanian%2FLibSee/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashvardanian%2FLibSee/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashvardanian%2FLibSee/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashvardanian","download_url":"https://codeload.github.com/ashvardanian/LibSee/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashvardanian%2FLibSee/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267718783,"owners_count":24133464,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["assembly","benchmark","benchmarking","fuzzing","glibc","ld-preload","ld-preload-hack","libc"],"created_at":"2024-10-14T01:25:07.076Z","updated_at":"2025-07-29T16:42:41.472Z","avatar_url":"https://github.com/ashvardanian.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"![LibSee Thumbnail](https://github.com/ashvardanian/ashvardanian/blob/master/repositories/LibSee.jpg?raw=true)\n\n\u003e _See where you use LibC the most._ \u003cbr/\u003e\n\u003e _Trace calls failing tests. Then - roast!_\n\n__LibSee__ is a single-file library for profiling LibC calls and 🔜 fuzzy testing.\nTo download and compile the script and run your favorite query:\n\n```bash\ngcc -g -O2 -fno-builtin -fPIC -nostdlib -nostartfiles -shared -o libsee.so libsee.c\n```\n\nLibSee overrides LibC symbols using `LD_PRELOAD`, profiling the most commonly used functions, and, optionally, fuzzing their behavior for testing.\nThe library yields a few binaries when compiled:\n\n```bash\nlibsee.so # Profiles LibC calls\nlibsee_and_knee.so # Correct LibC behavior, but fuzzed!\n```\n\n## Tricks Used\n\nThere are several things worth knowing, that came handy implementing this.\n\n- One way to implement this library would be to override the `_start` symbols, but implementing correct loading sequence for a binary is tricky, so I use conventional `dlsym` to lookup the symbols on first function invocation.\n- On `x86_64` architecture, the `rdtscp` instruction yields both the CPU cycle and also the unique identifier of the core. Very handy if you are profiling a multi-threaded application.\n- Once the unloading sequence reaches `libsee.so`, the `STDOUT` is already closed. So if you want to print to the console, you may want to reopen the `/dev/tty` device before printing usage stats.\n- Calling convention for system calls on Aarch64 and x86 differs significantly. On Aarch64 I use the [generalized `openat`](https://github.com/torvalds/linux/blob/bf3a69c6861ff4dc7892d895c87074af7bc1c400/include/uapi/asm-generic/unistd.h#L158-L159) with opcode 56. On [x86 it's opcode 2](https://github.com/torvalds/linux/blob/0dd3ee31125508cd67f7e7172247f05b7fd1753a/arch/x86/entry/syscalls/syscall_64.tbl#L13).\n- On MacOS the `sprintf`, `vsprintf`, `snprintf`, `vsnprintf` are macros. You have to `#undef` them.\n- On `Release` builds compilers love replacing your code with `memset` and `memcpy` calls. As the symbol can't be found from inside LibSee, it will `SEGFAULT` so don't forget to disable such optimizations for built-ins `-fno-builtin`.\n- No symbol versioning is implemented, vanilla `dlsym` is used over the `dlvsym`.\n\n## Coverage\n\nLibC standard is surprisingly long, so not all of the functions are covered.\nFeel free to suggest PRs covering the rest:\n\n- [x] [memory management](https://en.cppreference.com/w/c/memory)\n- [x] [byte-strings](https://en.cppreference.com/w/c/string/byte)\n- [x] [algorithms](https://en.cppreference.com/w/c/algorithm)\n- [x] [date and time](https://en.cppreference.com/w/c/chrono)\n- [x] [input/output](https://en.cppreference.com/w/c/io)\n- [x] [wide-character strings](https://en.cppreference.com/w/c/string/wide)\n- [ ] [concurrency and atomics](https://en.cppreference.com/w/c/thread)\n- [ ] retrieving error numbers\n- [ ] [numerics](https://en.cppreference.com/w/c/numeric)\n- [ ] [multi-byte strings](https://en.cppreference.com/w/c/string/multibyte)\n- [ ] [wide-character IO](https://en.cppreference.com/w/c/io)\n- [ ] [localization](https://en.cppreference.com/w/c/locale)\n- [ ] anything newer than C 11\n\nThere are a few other C libraries that most of the world reuses, rather than implementing from scratch in other languages:\n\n- [ ] BLAS and LAPACK\n- [ ] PCRE RegEx\n- [ ] `hsearch`, `tsearch`, and pattern matching [extensions](https://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_node/libc_toc.html)\n\n[Program support](https://en.cppreference.com/w/c/program) utilities aren't intended.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashvardanian%2Flibsee","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashvardanian%2Flibsee","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashvardanian%2Flibsee/lists"}