Save ~3KB of RAM by moving constant strings out of RODATA #46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This complements the work you've been doing on moving the constant arrays in the encryption routines to PMEM.
Constant text strings actually take up SRAM space on the ESP8266 because the .RODATA segment must be copied to the top of RAM at startup since FLASH isn't byte-accessible but all string(char*) functions (like ets_printf, Serial.*, etc.) need this. There are a lot of string literals in the axtls code for certificate debugging, and that eats up nearly 10% of the free RAM in any project w/SSL.
This patch moves the constant format strings in axtls' printf completely into FLASH and add a wrapper to copy it into a local stack-allocated space when needed, freeing up about 3100 bytes of RAM for use. This doesn't make FLASH usage any higher, either, since those strings were already being stored there (but never used after the power-on startup code).
Minor edits required in some of the output/debug/tracing functions, but no logic changed.
Constant strings do NOT show up in the symbol table, so they aren't easily visible by many tools like READELF. One easy way to check what string literals are eating up RAM in RODATA is to use the command:
objdump
-s -j .rodata /tmp/arduino_build_89991/*.elfwhere the number will vary depending on the Arduino PID, etc.