查看: 492|回复: 0
收起左侧

RISC-V指令集GNU工具链

[复制链接]

  离线 

  • TA的每日心情
    慵懒
    前天 09:25
  • 签到天数: 57 天

    [LV.5]

    RISC-V商家RISC-V活跃会员RISC-V热心会员RISC-V推广达人

    发表于 2020-6-11 10:49:24 | 显示全部楼层 |阅读模式

    有人预言,RISC-V或将是继Intel和Arm之后的第三大主流处理器体系。欢迎访问全球首家只专注于RISC-V单片机行业应用的中文网站

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

    x
    本帖最后由 小飞飞 于 2020-10-10 12:58 编辑

    要编译RISC-V指令集代码,需要使用GNU工具链,使用GCC等工具进行交叉编译。

    该项目文件如下:


    在GitHub上有相关工具链的项目:https://github.com/riscv/riscv-gnu-toolchain

    该项目说明如下:


    RISC-V GNU Compiler Toolchain 国外芯片技术交流-RISC-V指令集GNU工具链risc-v单片机中文社区(1)

    This is the RISC-V C and C++ cross-compiler.


    It supports two build modes:a generic ELF/Newlib toolchain and a more sophisticated Linux-ELF/glibctoolchain.

    Getting the sources


    This repository uses submodules. You need the --recursive option to fetch the submodules automatically

    1. $ git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
    复制代码

    Alternatively :
    1. $ git clone https://github.com/riscv/riscv-gnu-toolchain
    2. $ cd riscv-gnu-toolchain
    3. $ git submodule update --init --recursive
    复制代码


    Prerequisites

    Several standard packages are needed to build the toolchain.  On Ubuntu,executing the following command should suffice:

    1. $ sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev
    复制代码

    On Fedora/CentOS/RHEL OS, executing the following command should suffice:

    1. $ sudo yum install autoconf automake libmpc-devel mpfr-devel gmp-devel gawk  bison flex texinfo patchutils gcc gcc-c++ zlib-devel expat-devel
    复制代码

    On OS X, you can use Homebrew to install the dependencies:

    1. $ brew install gawk gnu-sed gmp mpfr libmpc isl zlib expat
    复制代码

    To build the glibc (Linux) on OS X, you will need to build within a case-sensitive filesystem.  The simplest approach is to create and mount a new disk image witha case sensitive format.  Make sure that the mount point does not contain spaces. This is not necessary to build newlib or gcc itself on OS X.

    This process will start by downloading about 200 MiB of upstream sources, thenwill patch, build, and install the toolchain.  If a local cache of theupstream sources exists in $(DISTDIR), it will be used; the default locationis /var/cache/distfiles.  Your computer will need about 8 GiB of disk space tocomplete the process.



    Installation (Newlib)


    To build the Newlib cross-compiler, pick an install path.  


    If you choose,say, /opt/riscv, then add /opt/riscv/bin to your PATH now.  


    Then, simplyrun the following command:

    1. ./configure --prefix=/opt/riscv
    2. make
    复制代码

    You should now be able to use riscv64-unknown-elf-gcc and its cousins.


    Installation (Linux)


    To build the Linux cross-compiler, pick an install path.  


    If you choose,say, /opt/riscv, then add /opt/riscv/bin to your PATH now.  


    Then, simplyrun the following command:

    1. ./configure --prefix=/opt/riscv
    2. make linux
    复制代码

    The build defaults to targetting RV64GC (64-bit), even on a 32-bit buildenvironment.  To build the 32-bit RV32GC toolchain, use:

    1. ./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32d
    2. make linux
    复制代码

    Supported architectures are rv32i or rv64i plus standard extensions (a)tomics,(m)ultiplication and division, (f)loat, (d)ouble, or (g)eneral for MAFD.

    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, nicheuse only), lp64 lp64f lp64d (same but with 64-bit long and pointers).



    Installation (Linux multilib)


    To build the Linux cross-compiler with support for both 32-bit and64-bit, run the following commands:

    1. ./configure --prefix=/opt/riscv --enable-multilib
    2. make linux
    复制代码

    The multilib compiler will have the prefix riscv64-unknown-linux-gnu-,but will be able to target both 32-bit and 64-bit systems.



    Troubleshooting Build Problems
    Builds work best if installing into an empty directory.

    If you build a hard-float toolchain and then try to build a soft-float toolchain with the same --prefix directory, then the build scripts may get confused and exit with a linker error complaining that hard float code can't be linked with soft float code.

    Removing the existing toolchain first, or using a different prefix for the second build, avoids the problem.

    It is OK to build one newlib and one linux toolchain with the same prefix.

    But you should avoid building two newlib or two linux toolchains with the same prefix.

    If building a linux toolchain on a MacOS system, or on a Windows system using the Linux subsystem or cygwin, you must ensure that the filesystem is case-sensitive.

    A build on a case-insensitive filesystem will fail when building glibc because *.os and *.oS files will clobber each other during the build eventually resulting in confusing link errors.

    Centos (and RHEL) provide old GNU tools versions that may be too old to build a RISC-V toolchain.

    There is an alternate toolset provided that includes current versions of the GNU tools.

    This is the devtoolset provided as part of the Software Collection service.

    For more info, see the devtoolset-7 URL.

    There are various versions of the devtoolset that are available, so you can also try other versions of it, but we have at least one report that devtoolset-7 works.


    Advanced Options

    There are a number of additional options that may be passed toconfigure.  See './configure --help' for more details.


    Test Suite


    The DejaGnu test suite has been ported to RISC-V.  


    This can run with GDBsimulator for elf toolchain or Qemu for linux toolchain, and GDB simulatordoesn't support floating-point.


    To test GCC, run the following commands:

    1. ./configure --prefix=$RISCV --disable-linux --with-arch=rv64ima # or --with-arch=rv32ima
    2. make newlib
    3. make report-newlib

    4. ./configure --prefix=$RISCV
    5. make linux
    6. make report-linux
    复制代码






    上一篇:书籍 《Computer_Organization_and_Design_RISC-V_Edition_1th_2017》
    下一篇:兆易创新联手IAR Systems发布全新RISC-V解决方案
    题主优质好文
    相信自已,未来是自已创造的。
    点评回复

    使用道具 举报

    高级模式
    B Color Image Link Quote Code Smilies @朋友

    本版积分规则

    关闭

    RISC-V单片机中文网上一条 /2 下一条




    版权及免责声明|RISC-V单片机中文网 |网站地图

    GMT+8, 2021-7-29 02:25 , Processed in 0.505154 second(s), 44 queries .

    快速回复 返回顶部 返回列表