• 交叉编译riscv64linuxgnugcc


    root@ubuntu:~#  riscv64-linux-gnu-gcc  -v
    Using built-in specs.
    COLLECT_GCC=riscv64-linux-gnu-gcc
    COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/riscv64-linux-gnu/7/lto-wrapper
    Target: riscv64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,c++,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libsanitizer --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --enable-multiarch --disable-werror --disable-multilib --with-arch=rv64imafdc --with-abi=lp64d --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=riscv64-linux-gnu --program-prefix=riscv64-linux-gnu- --includedir=/usr/riscv64-linux-gnu/include
    Thread model: posix
    gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) 
    root@ubuntu:~# 

    --host=aarch64-linux-gnu --target=riscv64-linux-gnu

    --libdir=/usr/lib

     --includedir=/usr/riscv64-linux-gnu/include

    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt#  ls /usr/lib/gcc-cross/riscv64-linux-gnu/7
    cc1       crtbegin.o   crtbeginT.o  crtendS.o  crtn.o   include-fixed  libatomic.so    libcc1.so  libgcc_eh.a  libgcov.a  libgomp.so    liblto_plugin.so    liblto_plugin.so.0.0.0  lto1         plugin
    collect2  crtbeginS.o  crtend.o     crti.o     include  libatomic.a    libbacktrace.a  libgcc.a   libgcc_s.so  libgomp.a  libgomp.spec  liblto_plugin.so.0  libssp_nonshared.a      lto-wrapper
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt#  ls /usr/lib/gcc-cross/riscv64-linux-gnu/7
    7/     7.5.0/ 
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt#  ls /usr/lib/gcc-cross/riscv64-linux-gnu/7.5.0
    cc1       crtbegin.o   crtbeginT.o  crtendS.o  crtn.o   include-fixed  libatomic.so    libcc1.so  libgcc_eh.a  libgcov.a  libgomp.so    liblto_plugin.so    liblto_plugin.so.0.0.0  lto1         plugin
    collect2  crtbeginS.o  crtend.o     crti.o     include  libatomic.a    libbacktrace.a  libgcc.a   libgcc_s.so  libgomp.a  libgomp.spec  liblto_plugin.so.0  libssp_nonshared.a      lto-wrapper
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# 
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# make
    riscv64-linux-gnu-gcc   -T os.ld -o os.elf start.s sys.s lib.c timer.c os.c
    timer.c: In function ‘timer_init’:
    timer.c:11:4: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       *(reg_t*)CLINT_MTIMECMP(id) = *(reg_t*)CLINT_MTIME + interval;
        ^
    timer.c:14:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
       w_mtvec((reg_t)sys_timer);
               ^
    timer.c: In function ‘timer_handler’:
    timer.c:32:4: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       *(reg_t *)CLINT_MTIMECMP(id) = *(reg_t *)CLINT_MTIME + interval;
        ^
    /tmp/ccoPYDvY.o: In function `_start':
    (.text+0x0): multiple definition of `_start'
    /usr/lib/gcc-cross/riscv64-linux-gnu/7/../../../../riscv64-linux-gnu/lib/crt1.o:(.text+0x2): first defined here
    /usr/lib/gcc-cross/riscv64-linux-gnu/7/../../../../riscv64-linux-gnu/lib/crt1.o: In function `_start':
    (.text+0x6): undefined reference to `main'
    (.text+0x2c): undefined reference to `__global_pointer$'
    /usr/lib/gcc-cross/riscv64-linux-gnu/7/crtbegin.o: In function `deregister_tm_clones':
    crtstuff.c:(.text+0x0): relocation truncated to fit: R_RISCV_HI20 against `__TMC_LIST__'
    /usr/lib/gcc-cross/riscv64-linux-gnu/7/../../../../riscv64-linux-gnu/bin/ld: final link failed: Symbol needs debug section which does not exist
    collect2: error: ld returned 1 exit status
    Makefile:12: recipe for target 'os.elf' failed
    make: *** [os.elf] Error 1

    更改CFLAGS

    CFLAGS = -nostdlib -fno-builtin 

    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# ls /usr/riscv64-linux-gnu/
    bin  include  lib
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# ls /usr/riscv64-linux-gnu/bin/
    ar  as  ld  ld.bfd  nm  objcopy  objdump  ranlib  readelf  strip
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# ls /usr/riscv64-linux-gnu/include/
    aio.h      arpa         cpio.h    envz.h      fenv.h         _G_config.h     gshadow.h   libgen.h   malloc.h    mqueue.h  neteconet  nfs         proc_service.h  regex.h   search.h     spawn.h        string.h    tar.h        uchar.h     utmpx.h    xen
    aliases.h  asm          crypt.h   err.h       fmtmsg.h       gconv.h         iconv.h     libintl.h  math.h      mtd       netinet    nl_types.h  protocols       regexp.h  semaphore.h  stab.h         strings.h   termio.h     ucontext.h  values.h
    alloca.h   asm-generic  ctype.h   errno.h     fnmatch.h      getopt.h        ieee754.h   libio.h    mcheck.h    net       netipx     nss.h       pthread.h       resolv.h  setjmp.h     stdc-predef.h  stropts.h   termios.h    ulimit.h    video
    a.out.h    assert.h     dirent.h  error.h     fpu_control.h  glob.h          ifaddrs.h   limits.h   memory.h    netash    netiucv    obstack.h   pty.h           rpc       sgtty.h      stdint.h       sys         tgmath.h     unistd.h    wait.h
    argp.h     bits         dlfcn.h   execinfo.h  fstab.h        gnu             inttypes.h  link.h     misc        netatalk  netpacket  paths.h     pwd.h           rpcsvc    shadow.h     stdio_ext.h    syscall.h   thread_db.h  ustat.h     wchar.h
    argz.h     byteswap.h   elf.h     fcntl.h     fts.h          gnu-versions.h  langinfo.h  linux      mntent.h    netax25   netrom     poll.h      rdma            sched.h   signal.h     stdio.h        sysexits.h  time.h       utime.h     wctype.h
    ar.h       complex.h    endian.h  features.h  ftw.h          grp.h           lastlog.h   locale.h   monetary.h  netdb.h   netrose    printf.h    re_comp.h       scsi      sound        stdlib.h       syslog.h    ttyent.h     utmp.h      wordexp.h
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# ls /usr/riscv64-linux-gnu/lib/
    crt1.o                       libanl.so                libc-2.27.so      libcrypt.so    libg.a            libm.so                libnss_compat.so.2     libnss_hesiod.so        libpcprofile.so         libresolv.so    libthread_db-1.0.so  Scrt1.o
    crti.o                       libanl.so.1              libc.a            libcrypt.so.1  libgcc_s.so.1     libm.so.6              libnss_dns-2.27.so     libnss_hesiod.so.2      libpthread-2.27.so      libresolv.so.2  libthread_db.so
    crtn.o                       libatomic.so.1           libcidn-2.27.so   libc.so        libgomp.so.1      libnsl-2.27.so         libnss_dns.so          libnss_nis-2.27.so      libpthread.a            librpcsvc.a     libthread_db.so.1
    gcrt1.o                      libatomic.so.1.2.0       libcidn.so        libc.so.6      libgomp.so.1.0.0  libnsl.a               libnss_dns.so.2        libnss_nisplus-2.27.so  libpthread_nonshared.a  librt-2.27.so   libutil-2.27.so
    ld-2.27.so                   libBrokenLocale-2.27.so  libcidn.so.1      libdl-2.27.so  libm-2.27.so      libnsl.so              libnss_files-2.27.so   libnss_nisplus.so       libpthread.so           librt.a         libutil.a
    ld-linux-riscv64-lp64d.so.1  libBrokenLocale.a        libc_nonshared.a  libdl.a        libm.a            libnsl.so.1            libnss_files.so        libnss_nisplus.so.2     libpthread.so.0         librt.so        libutil.so
    libanl-2.27.so               libBrokenLocale.so       libcrypt-2.27.so  libdl.so       libmcheck.a       libnss_compat-2.27.so  libnss_files.so.2      libnss_nis.so           libresolv-2.27.so       librt.so.1      libutil.so.1
    libanl.a                     libBrokenLocale.so.1     libcrypt.a        libdl.so.2     libmemusage.so    libnss_compat.so       libnss_hesiod-2.27.so  libnss_nis.so.2         libresolv.a             libSegFault.so  Mcrt1.o
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# 

    /usr/lib/gcc-cross/riscv64-linux-gnu/7/../../../../riscv64-linux-gnu/bin/ld: error: no memory region specified for loadable section `.note.gnu.build-id'

    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# cat os.ld 
    OUTPUT_ARCH( "riscv" )
    
    ENTRY( _start )
    
    MEMORY
    {
      ram   (wxa!ri) : ORIGIN = 0x80000000, LENGTH = 128M
    }
    
    PHDRS
    {
      text PT_LOAD;
      data PT_LOAD;
      bss PT_LOAD;
    }
    
    SECTIONS
    {
      .text : {
        PROVIDE(_text_start = .);
        *(.text.init) *(.text .text.*)
        PROVIDE(_text_end = .);
      } >ram AT>ram :text
    
      .rodata : {
        PROVIDE(_rodata_start = .);
        *(.rodata .rodata.*)
        PROVIDE(_rodata_end = .);
      } >ram AT>ram :text
    
      .data : {
        . = ALIGN(4096);
        PROVIDE(_data_start = .);
        *(.sdata .sdata.*) *(.data .data.*)
        PROVIDE(_data_end = .);
      } >ram AT>ram :data
    
      .bss :{
        PROVIDE(_bss_start = .);
        *(.sbss .sbss.*) *(.bss .bss.*)
        PROVIDE(_bss_end = .);
      } >ram AT>ram :bss
    
      PROVIDE(_memory_start = ORIGIN(ram));
      PROVIDE(_memory_end = ORIGIN(ram) + LENGTH(ram));
    }
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# cat os.ld  | grep '.note.gnu.build-id'
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# 

    添加CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -Wl,--build-id=none

    gcc-riscv64-unknown-elf

    wget http://ports.ubuntu.com/pool/universe/g/gcc-riscv64-unknown-elf/gcc-riscv64-unknown-elf_9.3.0-0ubuntu1_arm64.deb

    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# dpkg -i gcc-riscv64-unknown-elf_9.3.0-0ubuntu1_arm64.deb 
    Selecting previously unselected package gcc-riscv64-unknown-elf.
    (Reading database ... 146833 files and directories currently installed.)
    Preparing to unpack gcc-riscv64-unknown-elf_9.3.0-0ubuntu1_arm64.deb ...
    Unpacking gcc-riscv64-unknown-elf (9.3.0-0ubuntu1) ...
    dpkg: dependency problems prevent configuration of gcc-riscv64-unknown-elf:
     gcc-riscv64-unknown-elf depends on libgcc-s1 (>= 4.2); however:
      Package libgcc-s1 is not installed.
     gcc-riscv64-unknown-elf depends on binutils-riscv64-unknown-elf; however:
      Package binutils-riscv64-unknown-elf is not installed.
    
    dpkg: error processing package gcc-riscv64-unknown-elf (--install):
     dependency problems - leaving unconfigured
    Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
    Errors were encountered while processing:
     gcc-riscv64-unknown-elf
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# ls
    gcc-riscv64-unknown-elf_9.3.0-0ubuntu1_arm64.deb  lib.c  lib.h  Makefile  os.c  os.h  os.ld  os.ld.bak  README.md  riscv.h  start.s  sys.h  sys.s  timer.c  timer.h
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# dpkg -i gcc-riscv64-unknown-elf_9.3.0-0ubuntu1_arm64.deb 
    Selecting previously unselected package gcc-riscv64-unknown-elf.
    (Reading database ... 146833 files and directories currently installed.)
    Preparing to unpack gcc-riscv64-unknown-elf_9.3.0-0ubuntu1_arm64.deb ...
    Unpacking gcc-riscv64-unknown-elf (9.3.0-0ubuntu1) ...
    dpkg: dependency problems prevent configuration of gcc-riscv64-unknown-elf:
     gcc-riscv64-unknown-elf depends on libgcc-s1 (>= 4.2); however:
      Package libgcc-s1 is not installed.
     gcc-riscv64-unknown-elf depends on binutils-riscv64-unknown-elf; however:
      Package binutils-riscv64-unknown-elf is not installed.
    
    dpkg: error processing package gcc-riscv64-unknown-elf (--install):
     dependency problems - leaving unconfigured
    Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
    Errors were encountered while processing:
     gcc-riscv64-unknown-elf
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# wget http://ports.ubuntu.com/pool/universe/b/binutils-riscv64-unknown-elf/binutils-riscv64-unknown-elf_2.34-0ubuntu1_arm64.deb
    --2021-12-11 16:47:25--  http://ports.ubuntu.com/pool/universe/b/binutils-riscv64-unknown-elf/binutils-riscv64-unknown-elf_2.34-0ubuntu1_arm64.deb
    Resolving ports.ubuntu.com (ports.ubuntu.com)... 91.189.88.152, 91.189.88.142, 2001:67c:1360:8001::23, ...
    Connecting to ports.ubuntu.com (ports.ubuntu.com)|91.189.88.152|:80... 
    connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 2214572 (2.1M) [application/x-debian-package]
    Saving to: ‘binutils-riscv64-unknown-elf_2.34-0ubuntu1_arm64.deb’
    
    binutils-riscv64-unknown-elf_2.34-0ubuntu1_arm64.deb           100%[====================================================================================================================================================>]   2.11M   767KB/s    in 2.8s    
    
    2021-12-11 16:47:44 (767 KB/s) - ‘binutils-riscv64-unknown-elf_2.34-0ubuntu1_arm64.deb’ saved [2214572/2214572]
    
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# 
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# dpkg -i binutils-riscv64-unknown-elf_2.34-0ubuntu1_arm64.deb 
    Selecting previously unselected package binutils-riscv64-unknown-elf.
    (Reading database ... 147572 files and directories currently installed.)
    Preparing to unpack binutils-riscv64-unknown-elf_2.34-0ubuntu1_arm64.deb ...
    Unpacking binutils-riscv64-unknown-elf (2.34-0ubuntu1) ...
    Setting up binutils-riscv64-unknown-elf (2.34-0ubuntu1) ...
    Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# dpkg -i gcc-riscv64-unknown-elf_9.3.0-0ubuntu1_arm64.deb 
    (Reading database ... 147649 files and directories currently installed.)
    Preparing to unpack gcc-riscv64-unknown-elf_9.3.0-0ubuntu1_arm64.deb ...
    Unpacking gcc-riscv64-unknown-elf (9.3.0-0ubuntu1) over (9.3.0-0ubuntu1) ...
    dpkg: dependency problems prevent configuration of gcc-riscv64-unknown-elf:
     gcc-riscv64-unknown-elf depends on libgcc-s1 (>= 4.2); however:
      Package libgcc-s1 is not installed.
    
    dpkg: error processing package gcc-riscv64-unknown-elf (--install):
     dependency problems - leaving unconfigured
    Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
    Errors were encountered while processing:
     gcc-riscv64-unknown-elf
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# apt install libgcc-s1-arm64-cross
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Unable to locate package libgcc-s1-arm64-cross
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# wget https://ubuntu.pkgs.org/20.04/ubuntu-main-arm64/libgcc-s1-arm64-cross_10-20200411-0ubuntu1cross1_all.deb.html
    --2021-12-11 16:50:22--  https://ubuntu.pkgs.org/20.04/ubuntu-main-arm64/libgcc-s1-arm64-cross_10-20200411-0ubuntu1cross1_all.deb.html
    Resolving ubuntu.pkgs.org (ubuntu.pkgs.org)... 46.4.72.43
    Connecting to ubuntu.pkgs.org (ubuntu.pkgs.org)|46.4.72.43|:443... connected.
    HTTP request sent, awaiting response... 403 Forbidden
    2021-12-11 16:50:23 ERROR 403: Forbidden.
    
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# wget http://ports.ubuntu.com/pool/main/g/gcc-10-cross/libgcc-s1-arm64-cross_10-20200411-0ubuntu1cross1_all.deb
    --2021-12-11 16:51:02--  http://ports.ubuntu.com/pool/main/g/gcc-10-cross/libgcc-s1-arm64-cross_10-20200411-0ubuntu1cross1_all.deb
    Resolving ports.ubuntu.com (ports.ubuntu.com)... 91.189.88.142, 91.189.88.152, 2001:67c:1360:8001::24, ...
    Connecting to ports.ubuntu.com (ports.ubuntu.com)|91.189.88.142|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 34752 (34K) [application/x-debian-package]
    Saving to: ‘libgcc-s1-arm64-cross_10-20200411-0ubuntu1cross1_all.deb’
    
    libgcc-s1-arm64-cross_10-20200411-0ubuntu1cross1_all.deb       100%[====================================================================================================================================================>]  33.94K   113KB/s    in 0.3s    
    
    2021-12-11 16:51:03 (113 KB/s) - ‘libgcc-s1-arm64-cross_10-20200411-0ubuntu1cross1_all.deb’ saved [34752/34752]
    
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# ls
    binutils-riscv64-unknown-elf_2.34-0ubuntu1_arm64.deb  lib.c                                                     lib.h     os.c  os.ld      README.md  start.s  sys.s    timer.h
    gcc-riscv64-unknown-elf_9.3.0-0ubuntu1_arm64.deb      libgcc-s1-arm64-cross_10-20200411-0ubuntu1cross1_all.deb  Makefile  os.h  os.ld.bak  riscv.h    sys.h    timer.c
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# dpkg -i libgcc-s1-arm64-cross_10-20200411-0ubuntu1cross1_all.deb 
    Selecting previously unselected package libgcc-s1-arm64-cross.
    (Reading database ... 147649 files and directories currently installed.)
    Preparing to unpack libgcc-s1-arm64-cross_10-20200411-0ubuntu1cross1_all.deb ...
    Unpacking libgcc-s1-arm64-cross (10-20200411-0ubuntu1cross1) ...
    dpkg: dependency problems prevent configuration of libgcc-s1-arm64-cross:
     libgcc-s1-arm64-cross depends on gcc-10-cross-base (>= 10-20200411-0ubuntu1); however:
      Package gcc-10-cross-base is not installed.
     libgcc-s1-arm64-cross depends on libc6-arm64-cross (>= 2.31); however:
      Package libc6-arm64-cross is not installed.
    
    dpkg: error processing package libgcc-s1-arm64-cross (--install):
     dependency problems - leaving unconfigured
    Errors were encountered while processing:
     libgcc-s1-arm64-cross
    root@ubuntu:/home/ubuntu/mini-riscv-os/04-TimerInterrupt# 


    删除红色部分
    riscv64-linux-gnu-gcc -Wall -mcmodel=medany -g -I inc -O0  -nostdlib -march=rv64imac -mabi=lp64 -c src/lib.c -o build/lib.o
    In file included from /usr/riscv64-linux-gnu/include/features.h:448,
                     from /usr/riscv64-linux-gnu/include/bits/libc-header-start.h:33,
                     from /usr/riscv64-linux-gnu/include/stdint.h:26,
                     from /usr/lib/gcc-cross/riscv64-linux-gnu/8/include/stdint.h:9,
                     from inc/riscv.h:4,
                     from inc/lib.h:4,
                     from src/lib.c:1:
    /usr/riscv64-linux-gnu/include/gnu/stubs.h:8:11: fatal error: gnu/stubs-lp64.h: No such file or directory
     # include <gnu/stubs-lp64.h>
               ^~~~~~~~~~~~~~~~~~
    compilation terminated.
    Makefile:27: recipe for target 'build/lib.o' failed
    make: *** [build/lib.o] Error 1
    apt-get install gcc-riscv64-unknown-elf 安装

    riscv-operating-system homework

  • 相关阅读:
    Angular项目中引入jQuery
    ERROR in Error: ***Module is not an NgModule
    angular-cli项目报Error encountered resolving symbol values statically. Function calls are not supported.错误的处理。
    在angular项目中使用bootstrap的tooltip插件时,报错Property 'tooltip' does no t exist on type 'JQuery<HTMLElement>的解决方法和过程
    微信小程序学习笔记(四)--框架-视图层
    js打印窗口内容并当窗口内容较长时自动分页
    微信小程序学习笔记(三)--框架-逻辑层
    微信小程序学习笔记(二)--框架-全局及页面配置
    微信小程序学习笔记(一)--创建微信小程序
    在ag-grid表格上实现类似Excel中的按下enter键自动跳转到下一行对应的输入框功能,Angular4开发
  • 原文地址:https://www.cnblogs.com/dream397/p/15672344.html
Copyright © 2020-2023  润新知