Why jetson build can't support -finstrument-functions?

-finstrument-functions is one of GCC’s features. But when i try to add this flag to kernel build as below, build would failed with error. Could you help to check how to fix this? Thanks!

KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs
-fno-strict-aliasing -fno-common -fshort-wchar
-Wno-format-security -finstrument-functions

Hi, Can you provide the full logs for this failure? Or is this the entire error message?

Give more detail information would be good. Like the modification or any command line for build/configure.

@DBrisingr @ShaneCCC This build error cause after I add -finstrument-functions flag to KBUILD_CFLAGS. The complete log after this change please check attached ff.log.

And later I add attribute ((no_instrument_function)) to the function rise above error. Then there’s not compiling error, but report section mismatch error when link vmlinux. Please check attached ff_aa.log.

Follow the note, set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to the project config, the build success finally-check ff_smwo.log. But once I run the test, the HDMI output chaos firstly, then system freeze and reboot.

For more detail about this issue and background. I suspect there’s a memory overflow access in my system. So i want to use GCC finstrument-function which could set a hook to each function entry and exit to locate this issue. Refer to http://www.logix.cz/michal/devel/CygProfiler/cyg-profile.c.

Could you please help to verify on your build and fix this? Thanks!
BTW no other modification to build command/configuration.ff.log (38.9 KB) ff_aa.log (22.1 KB) ff_smwo.log (21.1 KB)

The hook i put to the __cyg_profile_func_enter/exit is just to check a suspect tegra_spi_data member address which assigned to a global pointer in premised.

@ShaneCCC @DBrisingr @kayccc Is there any update about this issue? Thanks!

Sorry, maybe due to some command line misconfiguration. I found the logs uploaded last time weren’t complete. Just update ff_aa.log and ff_smwo.log with complete error/warning info. And for ff.log, since build would take long time, the entire error message is as the snipping picture. I wouldn’t update new one. Thanks!

Hi @fh2077


Generate instrumentation calls for entry and exit to functions. Just after func- tion entry and just before function exit, the following profiling functions will be called with the address of the current function and its call site. (On some platforms, __builtin_return_address does not work beyond the current func- tion, so the call site information may not be available to the profiling functions otherwise.)
void __cyg_profile_func_enter (void *this_fn, void *call_site);
void __cyg_profile_func_exit (void *this_fn, void *call_site);

Did you add the _profiler function definitions correctly? I can reproduce the same error locally. Also, if I understand correctly, you want to instrument each function with a callback right? Why not try Linux’s inbuilt ftrace with hooks
Using ftrace to hook to functions — The Linux Kernel documentation. This could be much more easier than doing it manually as you have tried.

@DBrisingr Yes, i want to instrument each function with a callback. For my use case, i need to call my callback not only at entry, but also when a function exit. So that i can know the exact place where the expect event triggered.
And update about this issue. Later debug found if i only add this flag to SPI module(add to subdir-ccflags in SPI module makefile). The profiling function works without any issue. But if add to KBUILD_CFLAGS globally, it would cause system reboot as mention above. That’s i can only monitor/add callback to one module, but not full system. Could you help to check again? Thanks!