GCC-march -mabi

GCC编译器的-E、-S、-c和-g选项分别对应预处理、编译、汇编和包含调试信息的操作。-mabi选项用于指定RISC-V架构中的整数和浮点调用约定,如lp64d和lp64f等,影响着数据类型大小和浮点值在寄存器中的传递方式。ABI规定了寄存器使用和参数传递的规则,不同的ISA和ABI组合可能有不同的限制和实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GCC编译器

常用选项
​​-E​​:只进行预处理,不编译
​​-S​​:只编译,不汇编
​​-c​​:只编译、汇编,不链接
​-g​​:包含调试信息
​​-I​​:指定include包含文件的搜索目录
​​-o​​:输出成指定文件名

GCC参数详解

RISC-V基本介绍

https://blog.youkuaiyun.com/lijianyi0219/article/details/122634356

RISCV 入门

RISC-V数据模型,-mabi

https://blog.51cto.com/zoomdy/5871699
RISC-V GCC 使用手册对​​-mabi​​选项的说明:
-mabi=ABI-string
.
Specify integer and floating-point calling convention. ABI-string contains two parts: the size of integer types and the registers used for floating-point types. For example -march=rv64ifd -mabi=lp64d means that long and pointers are 64-bit (implicitly defining int to be 32-bit), and that floating-point values up to 64 bits wide are passed in F registers. Contrast this with -march=rv64ifd -mabi=lp64f, which still allows the compiler to generate code that uses the F and D extensions but only allows floating-point values up to 32 bits long to be passed in registers; or -march=rv64ifd -mabi=lp64, in which no floating-point arguments will be passed in registers.

指定整数和浮点调用约定。ABI字符串包含两部分:整数类型的大小和用于浮点类型的寄存器。例如,-march=rv64ifd-mabi=lp64d意味着long和指针是64位的(隐式地将int定义为32位),并且在F寄存器中传递高达64位宽的浮点值。
与之形成对比的是 -march=rv64ifd-mabi=lp64f,它仍然允许编译器生成使用F和D扩展的代码,但只允许在寄存器中传递长达32位的浮点值;或-march=rv64ifd-mabi=lp64,其中不会在寄存器中传递浮点参数。
.
The default for this argument is system dependent, users who want a specific calling convention should specify one explicitly. The valid calling conventions are: ilp32, ilp32f, ilp32d, lp64, lp64f, and lp64d. Some calling conventions are impossible to implement on some ISAs: for example, -march=rv32if -mabi=ilp32d is invalid because the ABI requires 64-bit values be passed in F registers, but F registers are only 32 bits wide.
此参数的默认值取决于系统,需要特定调用约定的用户应明确指定一个。有效的调用约定有:ilp32、ilp32f、ilp32d、lp64、lp64f和lp64d。有些调用约定无法在某些ISAs上实现:例如,-march=rv32if-mabi=ilp32d无效,因为ABI要求在F寄存器中传递64位值,但F寄存器只有32位宽。


ABI协议规定了寄存器、堆栈的使用规则以及参数传递规则。用于约束硬件与系统之间的通信协议。编译器必须按照ABI给出的寄存器功能定义,将C程序转为汇编程序。
寄存器是唯一能被被所有函数共享的资源。因此,在函数中调用其它函数时,需要考虑到数据的保存与覆盖问题(即防止被调函数直接修改寄存器导致主调函数的数据被覆盖)。

IA32采用了统一的寄存器使用约定,所有函数必须遵守。

C语言函数调用底层实现原理

参数的传递规则

mktemp -u XXXXXX 932979 test_cpp_condition stddef.h __riscv_zbb test_cpp BEGIN /tmp/ffconf.c1932982/test.c 1 #include <stddef.h> 2 #if !(__riscv_zbb) 3 #error "unsatisfied condition: __riscv_zbb" 4 #endif END /tmp/ffconf.c1932982/test.c riscv64-tizen-linux-gnu-gcc -O2 -g2 -gdwarf-4 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong -Wformat-security -Wformat -fmessage-length=0 -Wno-implicit-fallthrough -Wl,-z,relro,--as-needed -feliminate-unused-debug-types -Wformat -mabi=lp64d -march=rv64gc -Wl,-O1 -Wl,--hash-style=gnu -g -Wall -g -fPIC -DTIZEN_FEATURE_FFMPEG -DDBG_GSTFFMPEG_ALONE -DENABLE_SW_TBM_VXIMAGESINK -DTIZEN_PRODUCT_TV -DDRM_MAPI_AARCH_64 -fno-lto -fPIC -march=rv64gcv_zbb -I/home/abuild/rpmbuild/BUILD/gst-ffmpeg-1.45.0.tv/gst-libs/ext/ffmpeg/fdk-aac/include -I/usr/include/libpng16 -Wl,-z,relro -E -o /tmp/ffconf.c1932982/test.o /tmp/ffconf.c1932982/test.c test_ld cc test_cc BEGIN /tmp/ffconf.c1932982/test.c 1 int main(void){ return 0; } END /tmp/ffconf.c1932982/test.c riscv64-tizen-linux-gnu-gcc -O2 -g2 -gdwarf-4 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong -Wformat-security -Wformat -fmessage-length=0 -Wno-implicit-fallthrough -Wl,-z,relro,--as-needed -feliminate-unused-debug-types -Wformat -mabi=lp64d -march=rv64gc -Wl,-O1 -Wl,--hash-style=gnu -g -Wall -g -fPIC -DTIZEN_FEATURE_FFMPEG -DDBG_GSTFFMPEG_ALONE -DENABLE_SW_TBM_VXIMAGESINK -DTIZEN_PRODUCT_TV -DDRM_MAPI_AARCH_64 -fno-lto -fPIC -march=rv64gcv_zbb -I/home/abuild/rpmbuild/BUILD/gst-ffmpeg-1.45.0.tv/gst-libs/ext/ffmpeg/fdk-aac/include -I/usr/include/libpng16 -Wl,-z,relro -c -o /tmp/ffconf.c1932982/test.o /tmp/ffconf.c1932982/test.c riscv64-tizen-linux-gnu-gcc -ldl -L/home/abuild/rpmbuild/BUILD/gst-ffmpeg-1.45.0.tv/gst-libs/ext/ffmpeg/fdk-aac/lib -L/usr/lib -Wl,-z,relro,-z,now -o /tmp/ffconf.c1932982/test /tmp/ffconf.c1932982/test.o -ldl -lpng16 -lfdk-aac /usr/lib64/gcc/riscv64-tizen-linux-gnu/13.1.0/../../../../riscv64-tizen-linux
03-21
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值