-
Notifications
You must be signed in to change notification settings - Fork 13.3k
WIP -Make SPIFFS and LittleFS stay out of link when not needed #6697
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
Conversation
Fixes esp8266#6691 Idea is to use same principal of weak references to allow the call to SPIFFS.end() only to ever be linked in (along with all of SPIFFS) if there is a call somewhere in the app to SPIFFS.begin(). The biggest use case is httpUpdateServer which includes both LittleFS and SPIFFS code because it has embedded SPIFFS/LittleFS.end() calls. Standard apps need no changes and continue using standard calls. Users of the HttpUpdateServer will automatically save an extra 10-40K of code if they do not use one or both filesystems, or will be unaffected if they use both.
e268fa1
to
c7863f4
Compare
Using objdump I see this PR removing the littlefs/spiffs code when I don't have an explicit call to SPIFFS.begin() in my user app. HOWEVER This needs a runtime verification by @TD-er or others to make sure that spiffs.end/littlefs.end are still being called. You'll need to add a I don't have the HW handy now so can't run on real chip myself, and will be unable to try it for a good week or so... |
Marking as WIP because I believe it still to be broken. I added a printf("UNIQUESTRING"); to the weak function that does the LITTLEFS.end() call (littlefs_weak_end_redefinable) but I'm not finding that string in the generated binary which indicates the weak function is not being overridden properly and it's just never calling xxx.end() in the weak overrides. |
As I said, I didn't know how this strong/weak link stuff works in C++, so I started Googl'ing and came across this very elaborate reply: StackOverflow - attribute((weak)) and static libraries The thing I'm wondering about is, are we trying to fix it in the right place? In traditional coding, you will have a void pointer or a pointer to some base class, which does have to be checked for nullptr. If it is a valid pointer, it should be either casted to the right class, or the end() function should be strictly virtual in the base class. Another way could be to have some factory design pattern to deliver a valid new instance of the object. The presence of such factory design pattern does suggest to destruct the FS class and thus The approach displayed in this PR is doing some hocus-pocus in juggling with multiple weak implementations of the same function, which does seem to be order dependent on the files processed during compile.
If the compile/link step does already have Given you do see the compiled binary has been decreased in size, I guess the weak one is used. |
That's true, I though of that too, I'll update #6699
That's right too. There'd be code to check which FS is used. A bit of complexity. @TD-er about complexity discussion please head to #6699 . |
Closing in favor of #6699 . |
Fixes #6691
Idea is to use same principal of weak references to allow the call to
SPIFFS.end() only to ever be linked in (along with all of SPIFFS) if
there is a call somewhere in the app to SPIFFS.begin().
The biggest use case is httpUpdateServer which includes both LittleFS
and SPIFFS code because it has embedded SPIFFS/LittleFS.end() calls.
Standard apps need no changes and continue using standard calls.
Users of the HttpUpdateServer will automatically save an extra 10-40K
of code if they do not use one or both filesystems, or will be
unaffected if they use both.