? uname -a
Linux mt-pc 5.10.202-1-MANJARO #1 SMP PREEMPT Tue Nov 28 19:17:16 UTC 2023 x86_64 GNU/Linux
? pacman -Q riscv64-linux-gnu-gcc
riscv64-linux-gnu-gcc 12.2.0-1
对于riscv汇编程序,默认生成elf64二进制。
? cat test.s
# Add
# Format:
# ADD RD, RS1, RS2
# Description:
# The contents of RS1 is added to the contents of RS2 and the result is
# placed in RD.
.text # Define beginning of text section
.global _start # Define entry _start
_start:
li x6, 1 # x6 = 1
li x7, 2 # x7 = 2
add x5, x6, x7 # x5 = x6 + x7
stop:
j stop # Infinite loop to stop execution
.end # End of file
? riscv64-linux-gnu-gcc -nostdlib -fno-builtin -g -Wall test.s -o test
? riscv64-linux-gnu-readelf -h test
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Position-Independent Executable file)
Machine: RISC-V
Version: 0x1
Entry point address: 0x29a
Start of program headers: 64 (bytes into file)
Start of section headers: 5536 (bytes into file)
Flags: 0x5, RVC, double-float ABI
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 8
Size of section headers: 64 (bytes)
Number of section headers: 19
Section header string table index: 18