Skip to content

Enable various compilation flags to reduce the binary size#401

Merged
JF002 merged 2 commits intodevelopfrom
enable-compilation-flags
Jun 1, 2021
Merged

Enable various compilation flags to reduce the binary size#401
JF002 merged 2 commits intodevelopfrom
enable-compilation-flags

Conversation

@JF002
Copy link
Copy Markdown
Collaborator

@JF002 JF002 commented May 25, 2021

Enable the following compilation flags:

  • -fno-exceptions and -fno-non-call-exceptions : disable exception handling
  • -fno-rtti : disable run time type information (needed by dynamic_cast, for example)
  • -Os : optimize for size

These flags reduce the binary size by about 100KB!

Also, -fstack-usage generate debug info (not in final binary) to allow tools like Puncover to do a stack analysis.

#335
#389

TODO:

  • Remove duplicated flags
  • Replace -O0 by -Og (for DEBUG builds)

 * -fno-exceptions and -fno-non-call-exceptions : disable exception handling
 * -fno-rtti : disable run time type information (needed by dynamic_cast, for example)

These flags reduce the binary size by about 100KB!

Also, -fstack-usage generate debug info (not in final binary) to allow tools like Puncover to do a stack analysis.
@jonvmey
Copy link
Copy Markdown
Contributor

jonvmey commented May 25, 2021

I'd personally recommend -Og instead of -O0 for debug builds. It just enables optimizations which won't make debugging harder which is a lot nicer (IMO) than -O0's very unoptimized output.

@JF002
Copy link
Copy Markdown
Collaborator Author

JF002 commented May 26, 2021

I'd personally recommend -Og instead of -O0 for debug builds. It just enables optimizations which won't make debugging harder which is a lot nicer (IMO) than -O0's very unoptimized output.

You're probably right 👍
Wait... I've just tested on my working copy (cannot commit right now) and -Og generates a binary that is smaller than -O0 ! i'll probably add it to this PR :)

…/CMakeLists.txt).

Replace -O0 by -Og in DEBUG builds. This generates a smaller binary (small enough for the internal memory) that is debugger friendly.
@JF002 JF002 added this to the Version 1.2 milestone Jun 1, 2021
@JF002 JF002 merged commit 1b6acde into develop Jun 1, 2021
@Avamander Avamander deleted the enable-compilation-flags branch September 27, 2022 21:28
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.

Add compiler flags : -fno-rtti, -fno-exceptions, -fno-non-call-exceptions,... Optimizing the build size

2 participants