[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

Michael Kenzel via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 20 13:29:14 PST 2023


================
@@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf,
   Dl_info dyldInfo;
   if (dladdr((void *)addr, &dyldInfo)) {
     if (dyldInfo.dli_sname != NULL) {
-      snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
+      strncpy(buf, dyldInfo.dli_sname, bufLen);
----------------
michael-kenzel wrote:

Indeed. I did a quick test on my machine here:
```
-------------------------------------------------------------
Benchmark                   Time             CPU   Iterations
-------------------------------------------------------------
copy_snprintf         4005109 ns      4005097 ns          175
copy_strncpy          3580506 ns      3580409 ns          194
copy_memcpy_strlen    3346781 ns      3346773 ns          213
```
so doing `strlen` + `memcpy` seems to be the best option. I'll update the PR.

https://github.com/llvm/llvm-project/pull/72040


More information about the cfe-commits mailing list