bluespec / Piccolo

RISC-V CPU, simple 3-stage pipeline, for low-end applications (e.g., embedded, IoT)
Apache License 2.0
301 stars 48 forks source link

relocation truncated error when compiling `elf_to_hex.c` file to create the Mem Hex files #44

Open jrmejiaa opened 1 year ago

jrmejiaa commented 1 year ago

Hi all,

I don't know if it is only with my gcc version 11.1.0 but I am getting the next error when I tried to use the elf_to_hex.c file to compile with the Makefile in Tests/elf_to_hex.

The error:

gcc -g -o elf_to_hex  elf_to_hex.c  -lelf
/tmp/cc4D9tPQ.o: in function `c_mem_load_elf':
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:94:(.text+0x25a): relocation truncated to fit: R_X86_64_PC32 against symbol `bitwidth' defined in .bss section in /tmp/cc4D9tPQ.o
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:98:(.text+0x2a2): relocation truncated to fit: R_X86_64_PC32 against symbol `bitwidth' defined in .bss section in /tmp/cc4D9tPQ.o
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:130:(.text+0x394): relocation truncated to fit: R_X86_64_PC32 against symbol `min_addr' defined in .bss section in /tmp/cc4D9tPQ.o
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:131:(.text+0x39f): relocation truncated to fit: R_X86_64_PC32 against symbol `max_addr' defined in .bss section in /tmp/cc4D9tPQ.o
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:132:(.text+0x3aa): relocation truncated to fit: R_X86_64_PC32 against symbol `pc_start' defined in .bss section in /tmp/cc4D9tPQ.o
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:133:(.text+0x3b5): relocation truncated to fit: R_X86_64_PC32 against symbol `pc_exit' defined in .bss section in /tmp/cc4D9tPQ.o
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:134:(.text+0x3c0): relocation truncated to fit: R_X86_64_PC32 against symbol `tohost_addr' defined in .bss section in /tmp/cc4D9tPQ.o
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:155:(.text+0x4c6): relocation truncated to fit: R_X86_64_PC32 against symbol `min_addr' defined in .bss section in /tmp/cc4D9tPQ.o
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:156:(.text+0x4d6): relocation truncated to fit: R_X86_64_PC32 against symbol `min_addr' defined in .bss section in /tmp/cc4D9tPQ.o
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:157:(.text+0x4f3): relocation truncated to fit: R_X86_64_PC32 against symbol `max_addr' defined in .bss section in /tmp/cc4D9tPQ.o
/home/jairom/Documents/TUD_Projects/05_Semester/Piccolo/Tests/elf_to_hex/elf_to_hex.c:158:(.text+0x515): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
make: *** [Makefile:7: elf_to_hex] Error 1

The problem can be solved adding the the flag -mcmodel=medium. According to what I have read is because this particular C file requires a large amount of memory in the stack that could not be fulfilled using a 32 bits AS operations. Is this a unique problem from my environment?

Thank you for your time,

Jairo M

yswntht commented 5 days ago

@jrmejiaa Thank you for posting this. I see the same error on Ubuntu 22.04 (gcc 11.4.0). adding -mcmodel fixed it. gcc -g -o elf_to_hex elf_to_hex.c -lelf -mcmodel=medium