GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
loongarch

LoongArch: Implement support for naked functions

LoongArch GCC now supports the 'naked' function attribute.

This commit introduces support for the naked function attribute on the LoongArch architecture. Naked functions allow developers to bypass the compiler’s standard function prologue and epilogue generation, providing fine-grained control over function entry and exit code. This is useful for low-level code like bootloaders or interrupt handlers. The changes involve modifying frame information calculation, preventing prologue/epilogue emission, handling stack slot allocation for arguments, and recording the naked status in machine-specific function data. New test cases are included to verify this functionality.

In Details

Support for the __attribute__((naked)) function attribute has been added to the LoongArch backend. This attribute instructs the compiler not to generate a standard prologue or epilogue for the function. The implementation in config/loongarch/loongarch.cc and related files ensures that: frame register masks are not computed for naked functions; the prologue and epilogue emission is skipped (loongarch_expand_prologue/epilogue); static stack size is reported as zero; TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS is handled by a new function; TARGET_WARN_FUNC_RETURN is implemented; the `naked_…

For Context
Naked function
A function for which the compiler generates no prologue or epilogue code, allowing the programmer to provide custom entry and exit sequences.
Prologue
The initial sequence of instructions in a function that sets up the stack frame, saves registers, and prepares for function execution.
Epilogue
The final sequence of instructions in a function that restores saved registers, tears down the stack frame, and returns control to the caller.
Stack frame
A region of memory on the call stack allocated for a function call, used to store local variables, parameters, and return addresses.
LoongArch
A RISC-based instruction set architecture developed in China.
Filed Under: loongarchattributecompiler-backendlow-level-code