This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ARM-CGT-CLANG: warning: call to function could clobber interruptee's VFP registers; consider using the `interrupt_save_fp` attribute to prevent this behavior [-Wextra]

Part Number: ARM-CGT-CLANG

Below is compiler test case for the above generated warning.

PP file -  HwiP_armv7r_handlers_nortos.o.txt

Compiler option - "C:/ti/ti-arm-clang/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c -mcpu=cortex-r5 -mfloat-abi=hard -mfpu=vfpv3-d16 -mlittle-endian -mthumb -I"C:/ti/ti-arm-clang/ti-cgt-armllvm_4.0.3.LTS/include/c" -I"C:/ti/MCU_SDK/AM243x/mcu_plus_sdk/source" -DSOC_AM243X -DOS_NORTOS -D_DEBUG_=1 -save-temps -g -C -E -Wall -Wno-gnu-variable-sized-type-not-at-end -Wno-unused-function -I"C:/Users/a0502728/Downloads/ReferencePrj/MBN-V3.1.2T/hello_world_am243x-evm_r5fss0-0_nortos_ti-arm-clang/Debug/syscfg"   -o"HwiP_armv7r_handlers_nortos.o" "../HwiP_armv7r_handlers_nortos.c"

Compiler Version - ti-cgt-armllvm_4.0.3.LTS

Thanks

 

  • Reference Project - hello_world_am243x-evm_r5fss0-0_nortos_ti-arm-clang.zip

    The above project is build using MCU+SDK v11.02.00.24 and the device is AM243x.

  • The compiler is correct to issue the diagnostic.  Because of these compiler options ...

    -mfloat-abi=hard -mfpu=vfpv3-d16

    ... the compiler knows VFP registers are present in the CPU.  Many functions use __attribute__((interrupt)) and make a function call.  The compiler is forced to assume the called function overwrites every register, including the VFP registers.  Because __attribute__((interrupt_save_fp)) is not used, code generated by the compiler does not preserve the VFP registers.  Therefore, it is possible for the contents in the VFP registers to suddenly change.  

    If you change to __attribute__((interrupt_save_fp)), then this unsafe behavior is avoided.  But at the cost of more instructions and cycles to preserve the VFP registers.

    I do not advise using the option -Wno-extra to disable the diagnostic.  But it is supported.

    For further information, view the video titled preserve floating point registers during interrupts from the tiarmclang video series.

    Thanks and regards,

    -George

  • Hi George,

    If you change to __attribute__((interrupt_save_fp)), then this unsafe behavior is avoided.

    Thanks for your reply. We do have suggested customer to use the interrupt_save_fp attribute to avoid the warnings but customer don't want to use that attribute.

    In our MCU+SDK, we are building libraries that uses the same source file (HwiP_armv7r_handlers_nortos.c) without using the interrupt_save_fp attribute and it compiles without warnings.

    Below are the content of makefile used for building library.

    export MCU_PLUS_SDK_PATH?=$(abspath ../../..)
    include $(MCU_PLUS_SDK_PATH)/imports.mak
    
    CG_TOOL_ROOT=$(CGT_TI_ARM_CLANG_PATH)
    
    CC=$(CGT_TI_ARM_CLANG_PATH)/bin/tiarmclang
    AR=$(CGT_TI_ARM_CLANG_PATH)/bin/tiarmar
    
    PROFILE?=release
    ConfigName:=$(PROFILE)
    
    LIBNAME:=nortos.am243x.r5f.ti-arm-clang.$(PROFILE).lib
    
    FILES_common := \
        boot_armv7r.c \
        DebugP_shmLogWriter.c \
        DebugP_shmLogReader.c \
        DebugP_uartLogWriter.c \
        DebugP_uartScanf.c \
        DebugP_memTraceLogWriter.c \
        DebugP_log.c \
        DebugP_nortos.c \
        SemaphoreP_nortos.c \
        ClockP_nortos.c \
        ClockP_nortos_r5.c \
        EventP_nortos.c \
        HeapP_nortos.c \
        TimerP.c \
        TaskP_nortos.c \
        HwiP_armv7r_vim.c \
        HwiP_armv7r_handlers_nortos.c \
        MpuP_armv7r.c \
        CacheP_armv7r.c \
        CpuId_armv7r.c \
        HeapP_internal.c \
        printf.c \
        AddrTranslateP.c \
        PmuP_armv7r.c \
        QueueP_nortos.c \
    
    ASMFILES_common := \
        HwiP_armv7r_handlers_nortos_asm.S \
        HwiP_armv7r_vectors_nortos_asm.S \
        HwiP_armv7r_vectors_nortos_sbl_asm.S \
        boot_armv7r_asm.S \
        HwiP_armv7r_asm.S \
        MpuP_armv7r_asm.S \
        CacheP_armv7r_asm.S \
        CpuId_armv7r_asm.S \
        PmuP_armv7r_asm.S \
        Mutex_armv7r_asm.S \
    
    FILES_PATH_common = \
        dpl/r5 \
        dpl/common \
    
    INCLUDES_common := \
        -I${CG_TOOL_ROOT}/include/c \
        -I${MCU_PLUS_SDK_PATH}/source \
    
    DEFINES_common := \
        -DSOC_AM243X \
        -DOS_NORTOS \
    
    CFLAGS_common := \
        -mcpu=cortex-r5 \
        -mfloat-abi=hard \
        -mfpu=vfpv3-d16 \
        -mthumb \
        -Wall \
        -Werror \
        -g \
        -Wno-gnu-variable-sized-type-not-at-end \
        -Wno-unused-function \
        -Wno-extra \
    
    CFLAGS_cpp_common := \
        -Wno-c99-designator \
        -Wno-extern-c-compat \
        -Wno-c++11-narrowing \
        -Wno-reorder-init-list \
        -Wno-register \
        -Wno-writable-strings \
        -Wno-enum-compare \
        -Wno-reserved-user-defined-literal \
        -Wno-unused-const-variable \
        -Wno-vla-cxx-extension \
        -x c++ \
    
    CFLAGS_debug := \
        -D_DEBUG_=1 \
    
    CFLAGS_release := \
        -Os \
    
    ARFLAGS_common := \
        rc \
    
    FILES := $(FILES_common) $(FILES_$(PROFILE))
    ASMFILES := $(ASMFILES_common) $(ASMFILES_$(PROFILE))
    FILES_PATH := $(FILES_PATH_common) $(FILES_PATH_$(PROFILE))
    CFLAGS := $(CFLAGS_common) $(CFLAGS_$(PROFILE))
    ASMFLAGS := $(CFLAGS_common) $(CFLAGS_$(PROFILE))
    ifeq ($(INSTRUMENTATION_MODE), yes)
    CFLAGS += -fprofile-instr-generate -fcoverage-mapping
    endif
    ifeq ($(CPLUSPLUS_BUILD), yes)
    CFLAGS += $(CFLAGS_cpp_common)
    endif
    DEFINES := $(DEFINES_common) $(DEFINES_$(PROFILE))
    INCLUDES := $(INCLUDES_common) $(INCLUDE_$(PROFILE))
    ARFLAGS := $(ARFLAGS_common) $(ARFLAGS_$(PROFILE))
    
    LIBDIR := lib
    OBJDIR := obj/am243x/ti-arm-clang/$(PROFILE)/r5f/nortos/nortos/
    OBJS := $(FILES:%.c=%.obj)
    OBJS += $(ASMFILES:%.S=%.obj)
    DEPS := $(FILES:%.c=%.d)
    
    vpath %.obj $(OBJDIR)
    vpath %.c $(FILES_PATH)
    vpath %.S $(FILES_PATH)
    
    $(OBJDIR)/%.obj %.obj: %.c
    	@echo  Compiling: $(LIBNAME): $<
    	$(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) -MMD -o $(OBJDIR)/$@ $<
    
    $(OBJDIR)/%.obj %.obj: %.S
    	@echo  Compiling: $(LIBNAME): $<
    	$(CC) -c $(ASMFLAGS) $(INCLUDES) $(DEFINES) -o $(OBJDIR)/$@ $<
    
    all: $(LIBDIR)/$(LIBNAME)
    
    $(LIBDIR)/$(LIBNAME): $(OBJS) | $(LIBDIR)
    	@echo  .
    	@echo  Archiving: $(LIBNAME) to $@ ...
    	$(AR) $(ARFLAGS) $@ $(addprefix $(OBJDIR), $(OBJS))
    	@echo  Archiving: $(LIBNAME) Done !!!
    	@echo  .
    
    clean:
    	@echo  Cleaning: $(LIBNAME) ...
    	$(RMDIR) $(OBJDIR)
    	$(RM) $(LIBDIR)/$(LIBNAME)
    
    scrub:
    	@echo  Scrubing: $(LIBNAME) ...
    	-$(RMDIR) obj/
    	-$(RMDIR) lib/
    
    $(OBJS): | $(OBJDIR)
    
    $(LIBDIR) $(OBJDIR):
    	$(MKDIR) $@
    
    -include $(addprefix $(OBJDIR)/, $(DEPS))
    

    Customer wants to know why the warnings are not generated while compiling libraries v/s warning generated while compiling application?

    Regards,

    Tushar

  • we are building libraries that uses the same source file (HwiP_armv7r_handlers_nortos.c) without using the interrupt_save_fp attribute and it compiles without warnings.

    You see no warnings because of the compiler option -Wno-extra (line 75 in the makefile).  While this is supported, I advise against it.  This is safe only if all the functions called from the ISR, directly or indirectly, never modify any VFP registers.  To see which functions you have to check, build without -Wno-extra.

    Thanks and regards,

    -George