"Does it mean MCUXpresso SDK and examples cannot be compiled with LTO options?"
I would assume so, as I expect they would not have put in the proper attributes such as 'used'.
Reasons like this is why I only look at the SDK code source to see how it does something and never actually use the code in my products.
Here are the LTO notes from my Makefile from trying to get it to work over the years.
At least give -flto-report a shot and see if tells you what it removed.
See also if MCU added which I believe are required:
#LDFLAGS += -flto -ffunction-sections -fdata-sections
# Link-time optimization does not work well with generation of
# debugging information. Combining -flto with -g is currently
# experimental and expected to produce unexpected results.
# -fwhole-program
# Assume that the current compilation unit represents the whole
# program being compiled. All public functions and variables with the
# exception of main and those merged by attribute externally_visible
# become static functions and in effect are optimized more
# aggressively by interprocedural optimizers.
# This option should not be used in combination with -flto. Instead
# relying on a linker plugin should provide safer and more precise
# information.
# Link Time Optimization (LTO) gives GCC the capability of dumping its
# internal representation (GIMPLE) to disk, so that all the different
# compilation units that make up a single executable can be optimized
# as a single module. This expands the scope of inter-procedural
# optimizations to encompass the whole program (or, rather, everything
# that is visible at link time).
# To see it in action, complle with -v -Wl,-v -save-temps and spot for
# /cc1, /as, /collect2, /lto-plugin, /lto1 and /ld.
# LTO is broken until ARM version GCC 8.3.
# Note that the same optimization flags (-flto -Os) should be passed
# both at compile time and at link time.
# LTO requires the same optimization setting be passed to the linker
# that the compile phase is using. Keep this even when LTO is
# disabled for consistency in the options between compile and linkng.
LDFLAGS += -O$(OPT)
#CFLAGS += -flto
#CPPFLAGS += -flto
# Enables the use of a linker plugin during link-time optimization.
#LDFLAGS += -fuse-linker-plugin
# Specify -flto=jobserver to use GNU make's job server mode to
# determine the number of parallel jobs. This is useful when the
# Makefile calling GCC is already executing in parallel. You must
# prepend a ‘+’ to the command recipe in the parent Makefile for this
# to work. This option likely only works if MAKE is GNU make.
#CFLAGS += -flto=jobserver
#CPPFLAGS += -flto=jobserver
#LDFLAGS += -flto=jobserver
#LDFLAGS += -flto -ffunction-sections -fdata-sections
# Prints a report with internal details on the workings of the
# link-time optimizer. The contents of this report vary from version
# to version. It is meant to be useful to GCC developers when
# processing object files in LTO mode (via -flto).
#LDFLAGS += -flto-report
# -why_live symbol_name
# Logs a chain of references to symbol_name. Only applicable with
# -dead_strip. It can help debug why something that you think should
# be dead strip removed is not removed.
https://gcc.gnu.org/wiki/LinkTimeOptimization
If the code is to big without LTO the code may simply be to big.
In the past I would have suggested using Gimpel Lint for static analysis to find out how to make the code smaller (In effect doing what LTO was doing).
Alas they don't sell Lint any more only Lint+ with a bizarre unusable license model.
Trace is unrelated to LTO issue, it is related to the attributes. I'll make a separate post about that sometime.