在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 2780|回复: 4

[原创] RISC-V GNU Toolchain and Flags and APIs

[复制链接]
发表于 2020-12-2 09:11:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
GNU网站上面介绍的RISC-V Options
这里的说明3.19.42 RISC-V Options ,会随着gcc版本的升级而更新,这里以gcc 10.2版本为例说明。
-mabi=ABI-stringSpecify 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.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. There is also the ‘ilp32e’ ABI that can only be used with the ‘rv32e’ architecture. This ABI is not well specified at present, and is subject to change.

-march=ISA-stringGenerate code for given RISC-V ISA (e.g. ‘rv64im’). ISA strings must be lower-case. Examples include ‘rv64i’, ‘rv32g’, ‘rv32e’, and ‘rv32imaf’.When -march= is not specified, use the setting from -mcpu.If both -march and -mcpu= are not specified, the default for this argument is system dependent, users who want a specific architecture extensions should specify one explicitly.

具体含义
尽管在RISC-V GNU Compiler Toolchain 的说明中,有一个简单的介绍,但是可能很多还是不知道具体指的是什么。
Supported ABIs are ilp32 (32-bit soft-float), ilp32d (32-bit hard-float), ilp32f (32-bit with single-precision in registers and double in memory, niche use only), lp64 lp64f lp64d (same but with 64-bit long and pointers).

而在RISC-V ABIs Gentoo的wiki网站上面,却有一个较为详细的说明。
RISC-V has two integer ABIs and three floating-point ABIs, which can essentially be combined at will. Code generation is controlled by the -mabi argument to compiler calls, which concatenates the integer and floating point ABI name.Example: -mabi=ilp32dThe choice of ABI places requirements on the instruction set supported by the hardware and emitted by the compiler.

Integer ABIs
ilp32
  • int, long, pointers are 32bit
  • long long is 64bit
  • char is 8bit
  • short is 16bit ilp32 is currently only supported for 32-bit targets.
lp64
  • int is 32bit
  • long and pointers are 64bit
  • long long is 64bit
  • char is 8bit
  • short is 16bit lp64 is only supported for 64-bit targets.
Floating Point ABIs
”” (empty string)
  • No floating point arguments are passed in registers.
  • No requirements on instruction set / hardware. f
  • 32bit and smaller floating point types are passed in registers.
  • Requires F type floating point registers and instructions. d
  • 64bit and smaller floating point types are passed in registers.
  • Requires D type floating point registers and instructions.
如何针对性地生成Multilib
采用默认的配置,使能-enable-multilib,编译出来的可能不是我们需要的组合,需要手动进行配置。
可以通过修改gcc/config/riscv/t-elf-multilib文件,添加自己需要的组合,比如,我个人添加了rv32imfc/ilp32f(因为我不需要A指令集),则再次编译之后,可以生成对应的库。
MULTILIB_OPTIONS = march=rv32i/march=rv32ic/march=rv32im/march=rv32imc/march=rv32iac/march=rv32imac/march=rv32imafc/march=rv32imfc/march=rv32imafdc/march=rv32gc/march=rv64imac/march=rv64imafdc/march=rv64gc mabi=ilp32/mabi=ilp32f/mabi=lp64/mabi=lp64dMULTILIB_DIRNAMES = rv32i \rv32ic \rv32im \rv32imc \rv32iac \rv32imac \rv32imafc \rv32imfc \rv32imafdc \rv32gc \rv64imac \rv64imafdc \rv64gc ilp32 \ilp32f \lp64 \lp64dMULTILIB_REQUIRED = march=rv32i/mabi=ilp32 \march=rv32im/mabi=ilp32 \march=rv32iac/mabi=ilp32 \march=rv32imac/mabi=ilp32 \march=rv32imc/mabi=ilp32 \march=rv32imafc/mabi=ilp32f \march=rv32imfc/mabi=ilp32f \march=rv64imac/mabi=lp64 \march=rv64imafdc/mabi=lp64d

编译的结果如下:
ab@haawking-pc1 MINGW64 ~/work/riscv-gnu-toolchain-58c9d86$ ../HX2000-Toolchain/riscv-tc-gcc-1123/bin/riscv64-unknown-elf-gcc.exe --print-multi-lib.;rv32i/ilp32;@march=rv32i@mabi=ilp32rv32im/ilp32;@march=rv32im@mabi=ilp32rv32imc/ilp32;@march=rv32imc@mabi=ilp32rv32iac/ilp32;@march=rv32iac@mabi=ilp32rv32imac/ilp32;@march=rv32imac@mabi=ilp32rv32imafc/ilp32f;@march=rv32imafc@mabi=ilp32frv32imfc/ilp32f;@march=rv32imfc@mabi=ilp32frv64imac/lp64;@march=rv64imac@mabi=lp64rv64imafdc/lp64d;@march=rv64imafdc@mabi=lp64d


 楼主| 发表于 2020-12-2 09:12:26 | 显示全部楼层
感兴趣的可以关注我的个人博客:RISC-V GNU Toolchain and Flags and APIs
发表于 2020-12-16 13:31:30 | 显示全部楼层
路过学习,很实用,谢谢分享
发表于 2020-12-16 15:38:13 | 显示全部楼层
路过学习,很实用,谢谢分享
发表于 2021-11-13 15:47:39 | 显示全部楼层
感谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条


小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-12-27 12:36 , Processed in 0.018440 second(s), 6 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表