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

Inline decarations need replacing by static declarations #2232

Closed
TerryE opened this issue Jan 19, 2018 · 8 comments
Closed

Inline decarations need replacing by static declarations #2232

TerryE opened this issue Jan 19, 2018 · 8 comments

Comments

@TerryE
Copy link
Collaborator

TerryE commented Jan 19, 2018

Expected behavior

The application should compile clean if the optimization level is set of O0

Actual behaviour

The link app/lua fails on undefined vfs references in luaxlib.c and loadlib.c

Test code

Replace references to O2 by O0 in the root Makefile, rm -R app/lua/.output and remake.

NodeMCU version

current dev

Root cause

See Stackoverflow: gcc fails to inline functions without -O2. The app/platform/vfs.h header uses the inline, but in In C99, this means that function's definition is provided only for inlining and inlining is not carried out at O0 so the function isnot compiled in. These functions should be declared static instead of inline and the compile will inline them anyway at O2.

One for @devsuarus

PS I note that app/coap/coap.c, app/coap/coap.c, and app/fatfs/myfatfs.c have the same issue.

@devsaurus
Copy link
Member

Right, I can reproduce this with DEBUG=1 make. Will have a look.

@TerryE
Copy link
Collaborator Author

TerryE commented Jan 20, 2018

@devsaurus Hi Arnim, AFAIK it's a foible of C89 vs C99. Up to C89 inline was a directive meaning a static function that may generate an inline expansion with the appropriate optimisation level. In C99 inline function template only generate code if the optimisation level allows it. The main issues that triggers this is that the xtensa-lx106-elf-gdb remote debugging is such a PITA to use with O2 that its just easier to recompile the modules that you are working on as O0 (or in my case app/lua) exposing this barf. 😄

The current gcc generators just generate gobsmackingly good code in general and will often inline any non-forward referenced function if this results in a shorter / faster code sequence. So IMO, we should just substitute static for inline declarations in the few places that we use them.

@TerryE TerryE closed this as completed Jan 20, 2018
@TerryE TerryE reopened this Jan 20, 2018
@TerryE
Copy link
Collaborator Author

TerryE commented Jan 20, 2018

Oops sorry; closed in error. Finger trouble and clicked the wrong button.

@devsaurus
Copy link
Member

The compiler's obviously smart enough (even with the our -Os) to figure out that the vfs wrappers don't have any flesh and declaring them as inline wasn't needed after all 😄

@TerryE
Copy link
Collaborator Author

TerryE commented Jan 20, 2018

-Os is a bad choice for us. About the only material difference between it and -O2 is that Flash string constants are packed and not word aligned so the unaligned exception handler counts go through the roof. I always compile with -O2.

@devsaurus
Copy link
Member

-Os is a bad choice for us

Should we make -O2 the default then? What would be the drawback of this - increased image size?

@TerryE
Copy link
Collaborator Author

TerryE commented Jan 21, 2018

@devsaurus, there is a increase in the Flash image size, a few % if I recall, but the typical count of unaligned exceptions goes down by over 5x so this is well worth doing. We've already touched on this in #1590 and #2146 (which is where we should address this).

@TerryE
Copy link
Collaborator Author

TerryE commented Feb 10, 2018

This patch has already been picked up be @devsaurus so there's no point in keeping this issue open.

@TerryE TerryE closed this as completed Feb 10, 2018
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

No branches or pull requests

2 participants