grahamedgecombe / icicle

32-bit RISC-V system on chip for iCE40 FPGAs
ISC License
301 stars 52 forks source link

Linker failure when running 'make BOARD=blackice-ii' #17

Open philtomson opened 3 years ago

philtomson commented 3 years ago

$ make BOARD=blackice-ii riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -Wall -Wextra -pedantic -DFREQ=48000000 -Os -ffreestanding -nostartfiles -g -Iprograms/hello -c -o programs/hello/main.o programs/hello/main.c cp start-ram.s start.s riscv64-unknown-elf-as -march=rv32i -mabi=ilp32 -o start.o start.s cp arch/ice40-ram.lds progmem.lds riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -Wall -Wextra -pedantic -DFREQ=48000000 -Os -ffreestanding -nostartfiles -g -Iprograms/hello -Wl,-Tprogmem.lds -o progmem programs/hello/main.o start.o start.o: In function .L0 ': (.text+0x4): relocation truncated to fit: R_RISCV_PCREL_LO12_I against.L0 ' collect2: error: ld returned 1 exit status Makefile:48: recipe for target 'progmem' failed make: *** [progmem] Error 1

philtomson commented 3 years ago

First problem was that I was using a riscv-gnu-toolchain built in 2018 (I think that was causing the linking problem for some reason).

Then the problem was that I had built riscv-gnu-toolchain wrong using the default params to the configure script. I built it using the following configure params and things worked fine (after removing all of the previously built toolchain - I ended up doing 'rm -rf /opt/riscv' to make sure.

When building the riscv-gnu-toolchain you should configure with: $ ./configure --prefix=/opt/riscv --with-arch=rv32i --with-abi=ilp32

(might be good to add a note in the README.md at the part about needing to build the riscv-gnu-toolchain)