decaf-lang / minidecaf-tutorial

The MiniDecaf tutorial documentation.
https://decaf-lang.github.io/minidecaf-tutorial/
93 stars 18 forks source link

Fail to compile on macOS #6

Closed Co1lin closed 3 years ago

Co1lin commented 3 years ago

Hi, I tried to compile the C program in the doc on macOS, but failed:

❯ cat test.c
#include <stdio.h>
int main() { printf("Hello world!\n"); }
❯ riscv64-unknown-elf-gcc -O3 test.c -march=rv32im -mabi=ilp32
riscv64-unknown-elf-gcc: fatal error: Can't found suitable multilib set for '-march=rv32im'/'-mabi=ilp32'
compilation terminated.

However, I can generate the assembly code:

❯ riscv64-unknown-elf-gcc -O3 -S test.c -march=rv32im -mabi=ilp32
❯ cat test.s
    .file   "test.c"
    .option nopic
    .attribute arch, "rv32i2p0_m2p0"
    .attribute unaligned_access, 0
    .attribute stack_align, 16
    .text
    .section    .rodata.str1.4,"aMS",@progbits,1
    .align  2
.LC0:
    .string "Hello world!"
    .section    .text.startup,"ax",@progbits
    .align  2
    .globl  main
    .type   main, @function
main:
    lui a0,%hi(.LC0)
    addi    sp,sp,-16
    addi    a0,a0,%lo(.LC0)
    sw  ra,12(sp)
    call    puts
    lw  ra,12(sp)
    li  a0,0
    addi    sp,sp,16
    jr  ra
    .size   main, .-main
    .ident  "GCC: (SiFive GCC-Metal 10.2.0-2020.12.8) 10.2.0"

Additionally, when I removed the options for 32-bit, It worked well. But it didn't meet the requirement of this course.

❯ riscv64-unknown-elf-gcc -O3 test.c
❯ ls | grep a.out
a.out

BTW, the last snippet on this page which uses qemu-riscv32 is not compatible for macOS. It can be removed to avoid confusion.

Co1lin commented 3 years ago

Problem solved by using the download link to riscv64-unknown-elf-gcc-8.3.0-2020.04.0-x86_64-apple-darwin.tar.gz. But I am wondering why toolchains downloaded from https://www.sifive.com/software -> Prebuilt RISC‑V GCC Toolchain and Emulator -> GNU Embedded Toolchain — v2020.12.8 -> macOS cannot work...

namasikanam commented 3 years ago

This is caused by issue #13 of SiFive prebuilt risc-v gcc toolchain. Thus, unfortunately, we can only use August 2020 release or prior for now.

Co1lin commented 3 years ago

Thanks~