Skip to contentSkip to conversation

Config.in: change default optimization level from -Os to -O2

PATCH Applied Thomas Petazzoni via buildroot 2 participants 2 messages Jan 2, 2024 – Jan 7, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Config.in: change default optimization level from -Os to -O2

Historically, Buildroot has defaulted to -Os as the gcc optimization flags. However, this default is probably not the most appropriate anymore, and this commit therefore changes the default to -O2.

Here are some arguments in favor of this change:

- Most Buildroot users use Buildroot for platforms that have a reasonable amount of storage, and the difference between -Os and -O2 in terms of code size is no longer as significant compared to the size of storage available on average embedded Linux devices typically found these days.

- -Os can have a pretty bad performance impact, compared to -O2.

- -Os is much less widely tested than -O2. For example, with recent versions of gcc, there are parts of Qt5 that segfault when compiled with -Os and work perfectly fine with -O2. Yes, it's a compiler bug that should be fixed, but in the mean time, having a default that's more widely used/tested makes sense.

---
 Config.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Config.in +2 -2
index 554b4062eb..bd4bf872aa 100644
@@ -474,7 +474,7 @@ config BR2_STRIP_EXCLUDE_DIRS
 
 choice
 	prompt "gcc optimization level"
-	default BR2_OPTIMIZE_S
+	default BR2_OPTIMIZE_2
 	help
 	  Set the optimization level for gcc
 
@@ -520,6 +520,7 @@ config BR2_OPTIMIZE_2
 	  -falign-loops -falign-labels -ftree-vrp -ftree-pre. Please
 	  note the warning under -fgcse about invoking -O2 on programs
 	  that use computed gotos.
+	  This is the default.
 
 config BR2_OPTIMIZE_3
 	bool "optimization level 3"
@@ -548,7 +549,6 @@ config BR2_OPTIMIZE_S
 	  -falign-loops -falign-labels -freorder-blocks
 	  -freorder-blocks-and-partition -fprefetch-loop-arrays
 	  -ftree-vect-loop-version
-	  This is the default.
 
 config BR2_OPTIMIZE_FAST
 	bool "optimize for fast (may break packages!)"
Signature · 6 lines
2.43.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Thomas, All,

On 2024-01-02 09:36 +0100, Thomas Petazzoni via buildroot spake thusly:

Quoted 14 lines

Historically, Buildroot has defaulted to -Os as the gcc optimization flags. However, this default is probably not the most appropriate anymore, and this commit therefore changes the default to -O2.

Here are some arguments in favor of this change:

- Most Buildroot users use Buildroot for platforms that have a reasonable amount of storage, and the difference between -Os and -O2 in terms of code size is no longer as significant compared to the size of storage available on average embedded Linux devices typically found these days.

- -Os can have a pretty bad performance impact, compared to -O2.

Quoted 8 lines

- -Os is much less widely tested than -O2. For example, with recent versions of gcc, there are parts of Qt5 that segfault when compiled with -Os and work perfectly fine with -O2. Yes, it's a compiler bug that should be fixed, but in the mean time, having a default that's more widely used/tested makes sense.

Applied to master, thanks.

Regards,
Yann E. MORIN.

Quoted 40 lines
---
 Config.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Config.in +2 -2
index 554b4062eb..bd4bf872aa 100644
@@ -474,7 +474,7 @@ config BR2_STRIP_EXCLUDE_DIRS
 
 choice
 	prompt "gcc optimization level"
-	default BR2_OPTIMIZE_S
+	default BR2_OPTIMIZE_2
 	help
 	  Set the optimization level for gcc
 
@@ -520,6 +520,7 @@ config BR2_OPTIMIZE_2
 	  -falign-loops -falign-labels -ftree-vrp -ftree-pre. Please
 	  note the warning under -fgcse about invoking -O2 on programs
 	  that use computed gotos.
+	  This is the default.
 
 config BR2_OPTIMIZE_3
 	bool "optimization level 3"
@@ -548,7 +549,6 @@ config BR2_OPTIMIZE_S
 	  -falign-loops -falign-labels -freorder-blocks
 	  -freorder-blocks-and-partition -fprefetch-loop-arrays
 	  -ftree-vect-loop-version
-	  This is the default.
 
 config BR2_OPTIMIZE_FAST
 	bool "optimize for fast (may break packages!)"
Signature · 6 lines
2.43.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot