Skip to content

Commit 0db1ef0

Browse files
committed
ghs: update the compile option to recommended options
add new build option config that recommended from other mass-produced products Signed-off-by: guoshichao <guoshichao@xiaomi.com>
1 parent 68a5732 commit 0db1ef0

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

arch/arm/src/cmake/ghs.cmake

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ endif()
151151

152152
if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS)
153153
add_compile_options(-ffunction-sections -fdata-sections)
154+
155+
# instruct the exlr deletet the unused functions during link procedure
156+
add_link_options(-delete)
154157
endif()
155158

156159
# Debug --whole-archive
@@ -163,10 +166,29 @@ endif()
163166

164167
if(CONFIG_DEBUG_LINK_MAP)
165168
add_link_options(-map=nuttx.map)
169+
# instruct the exlr the contents that needs to be contained in the generated
170+
# map file
171+
add_link_options(-Mn -map_eofn_symbols -Mx -Ms -Mu -Ml)
172+
173+
# instruct the compiler to keep the temp files generated at compile time after
174+
# they are used
175+
add_compile_options(-keeptempfiles)
176+
# instruct the compiler to generate a source listing of the asm file
177+
add_compile_options(-list)
166178
endif()
167179

168180
if(CONFIG_DEBUG_SYMBOLS)
169-
add_compile_options(-G -gdwarf-2)
181+
add_compile_options(-G -dual_debug)
182+
# instruct the exlr to ignore relocations from DWARF debug sections when using
183+
# -delete
184+
add_link_options(-ignore_debug_references)
185+
186+
# instruct the exlr to dump verbose information during link procedure
187+
add_link_options(-v)
188+
189+
# instruct the gsize to generate a *.siz file that contains the detailed
190+
# section size
191+
add_link_options(-gsize)
170192
endif()
171193

172194
add_compile_options(
@@ -201,6 +223,20 @@ if(NOT CONFIG_CXX_RTTI)
201223
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
202224
endif()
203225

226+
# instruct the compiler to treat the functions referenced or called when no
227+
# prototype has been provided as error
228+
229+
add_compile_options(--prototype_errors)
230+
231+
# instruct the compiler to treat #pragma directives that using wrong syntax as
232+
# warnings
233+
234+
add_compile_options(--incorrect_pragma_warnings)
235+
236+
# instruct the exlr do not link the start files into executable
237+
238+
add_link_options(-nostartfiles)
239+
204240
set(PREPROCESS ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} -E -P)
205241

206242
# override nuttx_generate_preprocess_target

arch/arm/src/common/Toolchain.defs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ ZIGFLAGS = -target $(ZARCH)-freestanding-$(ZEABI) $(ZARCHCPUFLAGS)
443443

444444
ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),)
445445
ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
446-
ifeq ($(CONFIG_ARCH_TOOLCHAIN_GHS),)
446+
ifeq ($(CONFIG_ARCH_TOOLCHAIN_GHS),y)
447+
# instruct the exlr deletet the unused functions during link procedure
448+
LDFLAGS += -delete
449+
else
447450
LDFLAGS += --gc-sections
448451
endif
449452
ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
@@ -461,6 +464,15 @@ endif
461464
ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
462465
ifeq ($(CONFIG_ARM_TOOLCHAIN_GHS),y)
463466
LDFLAGS += -map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map)
467+
# instruct the compiler to keep the temp files generated at
468+
# compile time after they are used
469+
ARCHOPTIMIZATION += -keeptempfiles
470+
471+
# instruct the compiler to generate a source listing of the asm file
472+
ARCHOPTIMIZATION += -list
473+
474+
# instruct the exlr the contents that needs to be contained in the generated map file
475+
LDFLAGS += -map_eofn_symbols -Mn -Mx -Ms -Mu -Ml
464476
else ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),)
465477
LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map)
466478
else
@@ -476,10 +488,34 @@ ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
476488
LDFLAGS += --debug
477489
endif
478490
else
479-
ARCHOPTIMIZATION += -G -gdwarf-2
491+
# instruct the exlr to ignore relocations from DWARF debug sections when using -delete
492+
LDFLAGS += -ignore_debug_references
493+
494+
# instruct the exlr to dump verbose information during link procedure
495+
LDFLAGS += -v
496+
497+
# instruct the gsize to generate a *.siz file that contains the detailed section size
498+
LDFLAGS += -gsize
499+
500+
ARCHOPTIMIZATION += -G -dual_debug
480501
endif
481502
endif
482503

504+
ifeq ($(CONFIG_ARCH_TOOLCHAIN_GHS),y)
505+
506+
# instruct the compiler to treat the functions referenced or called when no prototype has
507+
# been provided as error
508+
ARCHCFLAGS += --prototype_errors
509+
ARCHCXXFLAGS += --prototype_errors
510+
511+
# instruct the compiler to treat #pragma directives that using wrong syntax as warnings
512+
ARCHCFLAGS += --incorrect_pragma_warnings
513+
ARCHCXXFLAGS += --incorrect_pragma_warnings
514+
515+
# instruct the exlr do not link the start files into executable
516+
LDFLAGS += -nostartfiles
517+
endif
518+
483519
# Add the builtin library
484520

485521
ifeq ($(CONFIG_BUILTIN_TOOLCHAIN),y)

0 commit comments

Comments
 (0)