mirror of
https://github.com/neovim/neovim.git
synced 2025-11-15 14:59:20 +00:00
build: fix RelWithDebInfo optimization flags #31802
Problem:
RelWithDebInfo generates redundant flags:
Compilation: /usr/bin/cc -O2 -g -Og -g
The `CMAKE_C_FLAGS_RELWITHDEBINFO` variable is being modified in a way
that caused duplicate `-Og` and `-g` flags to be added. The resulting
flags were `-O2 -g -Og -g`.
- `-Og` (Optimize for debugging) and `-O2` (Optimize for performance)
are different optimization levels. We can't use both at once.
- The duplicate `-g` flag is redundant and no effect.
multiple -O flags has no effect for code, just redundant.
> If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
Solution:
Adjust the flags to use the more appropriate `-O2 -g`.
Compilation: /usr/bin/cc -O2 -g
BEFORE:
```
:verbose version
NVIM v0.11.0-dev-1443+ge00cd1ab40
Build type: RelWithDebInfo
LuaJIT 2.1.1734355927
Compilation: /usr/bin/cc -O2 -g -Og -g -flto -fno-fat-lto-ob
jects -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict
...
```
AFTER:
```
:verbose version
NVIM v0.11.0-dev-e00cd1ab4-dirty
Build type: RelWithDebInfo
LuaJIT 2.1.1734355927
Compilation: /usr/bin/cc -O2 -g -flto -fno-fat-lto-objects -
Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-protot
...
```
This commit is contained in:
@@ -149,11 +149,6 @@ set(NVIM_API_LEVEL 13) # Bump this after any API/stdlib change.
|
||||
set(NVIM_API_LEVEL_COMPAT 0) # Adjust this after a _breaking_ API change.
|
||||
set(NVIM_API_PRERELEASE true)
|
||||
|
||||
# Build-type: RelWithDebInfo
|
||||
# /Og means something different in MSVC
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -Og -g")
|
||||
endif()
|
||||
# We _want_ assertions in RelWithDebInfo build-type.
|
||||
if(CMAKE_C_FLAGS_RELWITHDEBINFO MATCHES DNDEBUG)
|
||||
string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
{
|
||||
"name": "default",
|
||||
"displayName": "RelWithDebInfo",
|
||||
"description": "Enables optimizations (-Og or -O2) with debug information",
|
||||
"description": "Enables optimizations (-O2) with debug information",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
|
||||
},
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#
|
||||
# - Debug: Disables optimizations (-O0), enables debug information.
|
||||
#
|
||||
# - RelWithDebInfo: Enables optimizations (-Og or -O2) with debug information.
|
||||
# - RelWithDebInfo: Enables optimizations (-O2) with debug information.
|
||||
#
|
||||
# - MinSizeRel: Enables all -O2 optimization that do not typically
|
||||
# increase code size, and performs further optimizations
|
||||
|
||||
Reference in New Issue
Block a user