objectcompilationelfriscvlow-level-code

how to pack a section of machine code as a function in .o object file


GOAL: Given a section of machine code, which conatins RISC-V extended instructions, I want to wrap it as a function and create an .o object file.

The function is something like void foo(), there's no arguments with void return type. and it call no other external functions and needs no relocation. How do I achieve that?


Solution

  • Use the .incbin assembly directive. Example 1. Example 2.

    You'll need to adjust the section name to something like .text.foo and section attributes to make the code executable.