Skip to content

Fix Verilator warning and ELF-to-HEX build issues on 64-bit Linux #26

@mdjannatulnayem

Description

@mdjannatulnayem

While building and running Clarinet on a 64-bit Linux system, I encountered two issues:

  1. Simulator warnings are treated as fatal errors
  2. elf_to_hex build fails due to large global/static memory allocations

Problem 1: Verilator fatal warnings

When running make simulator, some warnings cause the build to fail.

Proposed fix:
Append the flag --Wno-fatal to Verilator:

make simulator VERILATOR_FLAGS+=" --Wno-fatal"

This prevents warnings from stopping the simulation build.


Problem 2: elf_to_hex fails on 64-bit Linux

The elf_to_hex.c file defines a very large static buffer:

#define MAX_MEM_SIZE ((uint64_t) 0x90000000)
uint8_t mem_buf[MAX_MEM_SIZE];  // ~2.4 GB

On 64-bit Linux, the default PIE executable uses R_X86_64_PC32 relocations, which cannot address such a large global. The linker fails with:

relocation truncated to fit

Proposed fixes:

  1. Disable PIE:
gcc -g -no-pie -o elf_to_hex elf_to_hex.c -lelf
  1. Use the large memory model for globals > 2 GB:
gcc -g -mcmodel=large -o elf_to_hex elf_to_hex.c -lelf
  1. Or combine both:
gcc -g -mcmodel=large -no-pie -o elf_to_hex elf_to_hex.c -lelf

Steps to reproduce manually:

# Build elf_to_hex first
cd Tests/elf_to_hex
make clean
gcc -g -mcmodel=large -no-pie -o elf_to_hex elf_to_hex.c -lelf

# Then build tests in Verilator
cd ../../builds/RV32ACDFIMSU_verilator
make test

Conclusion:
Applying these fixes allows the project to build successfully on modern 64-bit Linux systems and prevents trivial warnings from breaking the simulation build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions