Question Details

No question body available.

Tags

c caching arm64 raspberry-pi5

Answers (1)

April 20, 2026 Score: 2 Rep: 1,736 Quality: Low Completeness: 80%

The answer is simple, I can just use the builtinclearcache intrinsic (available in both gcc and clang).
For C compilers that don't have this intrinsic, I can use the clearcache libgcc function (tested with tcc on the raspberry pi 5).

According to the gcc documentation this is exactly what I need:

Built-in Function: void builtinclearcache (void *begin, void *end)

This function is used to flush the processor’s instruction cache for the region of memory between begin inclusive and end exclusive. [...]

If the target does not require instruction cache flushes, builtinclearcache has no effect. Otherwise either instructions are emitted in-line to clear the instruction cache or a call to the clearcache function in libgcc is made.

With this I can set OFFSET2 as low as sizeof(instr_ret42) and it just works fine.