Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Plat-8106] Remove calls to libc printf #1397

Merged
merged 1 commit into from
Jun 2, 2022
Merged

[Plat-8106] Remove calls to libc printf #1397

merged 1 commit into from
Jun 2, 2022

Conversation

kstenerud
Copy link
Contributor

Goal

Libc printf acquires locks, and so it not safe for use in async-safe code.

This PR replaces these calls with async-safe alternatives, and also disables low level logging by default so that it doesn't run in production (it doesn't hurt anything, but bloats the binary size, and is of no use in the field).

Design

Low level number-to-string functions from the JSON encoder have now been exposed so that they can be used from elsewhere.

Added stb_sprintf to replace the few sprintf calls in the logger and other places in the codebase that can't be easily replaced with simpler alternatives.

All low level logging is now dependent upon the define BSG_KSLOG_ENABLE_LOW_LEVEL_LOGGING. When 0, no low level logging code is compiled.

Testing

Added tests for the low level number-to-string functions.
Tested manually with BSG_KSLOG_ENABLE_LOW_LEVEL_LOGGING = 1 and = 0.

@github-actions
Copy link

github-actions bot commented Jun 1, 2022

Bugsnag.framework binary size decreased by 536 bytes from 819,056 to 818,520 🎉

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +76% +10.2Ki   +75% +10.2Ki    [__TEXT]
  [ = ]       0  +372%    +536    [__LINKEDIT]
  +5.7%    +112  +5.7%    +112    __TEXT,__const
  +2.7%     +96  +2.7%     +96    __TEXT,__gcc_except_tab
  +0.3%     +24  +0.2%     +32    [__DATA]
  [ = ]       0  -0.1%      -8    __DATA,__bss
  -0.8%      -8  -0.8%      -8    __DATA,__data
  -1.0%     -16  -1.0%     -16    Indirect Symbol Table
  -1.1%     -16  -1.1%     -16    __DATA,__la_symbol_ptr
  -1.1%     -24  -1.1%     -24    __TEXT,__stub_helper
  -1.1%     -24  -1.1%     -24    __TEXT,__stubs
  -1.6%     -32  -1.6%     -32    Function Start Addresses
  -0.9%     -40  -0.9%     -40    Lazy Binding Info
  -1.1%     -40  -1.1%     -40    __TEXT,__unwind_info
  -0.6%     -56  -0.6%     -56    Export Info
  -0.1%    -104  -0.1%    -104    String Table
  -0.2%    -288  -0.2%    -288    Symbol Table
 -21.3% -4.93Ki -21.3% -4.93Ki    __TEXT,__cstring
  -2.1% -5.36Ki  -2.1% -5.36Ki    __TEXT,__text
  -0.1%    -536  [ = ]       0    TOTAL

Generated by 🚫 Danger

@kstenerud kstenerud force-pushed the PLAT-8106-printf branch 5 times, most recently from 3696d78 to 1a57232 Compare June 1, 2022 14:38
@kstenerud kstenerud merged commit 7d21289 into next Jun 2, 2022
@kstenerud kstenerud deleted the PLAT-8106-printf branch June 2, 2022 14:26
This was referenced Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants