fusesoc / elf-loader

VPI library to load ELF files from verilog test benches
8 stars 2 forks source link

elf-loader does not build on Windows #1

Open cr1901 opened 7 years ago

cr1901 commented 7 years ago

When attempting to use iverilog with fusesoc, compiling the elf-loader, compilation of the VPI module fails due to missing <gelf.h>:

../src/elf-loader_1.0/elf-loader.c:26:18: fatal error: gelf.h: No such file or directory
compilation terminated.
../src/elf-loader_1.0/vpi_wrapper.c: In function 'setup_reset_callbacks':
../src/elf-loader_1.0/vpi_wrapper.c:184:3: warning: missing initializer for field 'high' of 's_vpi_time {aka struct t_vpi_time}' [-Wmissing-field-initializers]
   static s_vpi_time time_s = {vpiScaledRealTime};
   ^
In file included from ../src/elf-loader_1.0/vpi_wrapper.c:21:0:
C:/msys64/mingw32/include/iverilog/vpi_user.h:95:18: note: 'high' declared here
       PLI_UINT32 high;
                  ^
../src/elf-loader_1.0/vpi_wrapper.c:185:3: warning: missing initializer for field 'value' of 's_vpi_value {aka struct t_vpi_value}' [-Wmissing-field-initializers]
   static s_vpi_value value_s = {vpiBinStrVal};
   ^
In file included from ../src/elf-loader_1.0/vpi_wrapper.c:21:0:
C:/msys64/mingw32/include/iverilog/vpi_user.h:128:9: note: 'value' declared here
       } value;
         ^
../src/elf-loader_1.0/vpi_wrapper.c:193:5: warning: missing initializer for field 'index' of 's_cb_data {aka struct t_cb_data}' [-Wmissing-field-initializers]
     };
     ^
In file included from ../src/elf-loader_1.0/vpi_wrapper.c:21:0:
C:/msys64/mingw32/include/iverilog/vpi_user.h:461:17: note: 'index' declared here
       PLI_INT32 index;
                 ^
../src/elf-loader_1.0/vpi_wrapper.c: In function 'setup_endofcompile_callbacks':
../src/elf-loader_1.0/vpi_wrapper.c:219:3: warning: missing initializer for field 'high' of 's_vpi_time {aka struct t_vpi_time}' [-Wmissing-field-initializers]
   static s_vpi_time time_s = {vpiScaledRealTime};
   ^
In file included from ../src/elf-loader_1.0/vpi_wrapper.c:21:0:
C:/msys64/mingw32/include/iverilog/vpi_user.h:95:18: note: 'high' declared here
       PLI_UINT32 high;
                  ^
../src/elf-loader_1.0/vpi_wrapper.c:220:3: warning: missing initializer for field 'value' of 's_vpi_value {aka struct t_vpi_value}' [-Wmissing-field-initializers]
   static s_vpi_value value_s = {vpiBinStrVal};
   ^
In file included from ../src/elf-loader_1.0/vpi_wrapper.c:21:0:
C:/msys64/mingw32/include/iverilog/vpi_user.h:128:9: note: 'value' declared here
       } value;
         ^
../src/elf-loader_1.0/vpi_wrapper.c:228:5: warning: missing initializer for field 'index' of 's_cb_data {aka struct t_cb_data}' [-Wmissing-field-initializers]
     };
     ^
In file included from ../src/elf-loader_1.0/vpi_wrapper.c:21:0:
C:/msys64/mingw32/include/iverilog/vpi_user.h:461:17: note: 'index' declared here
       PLI_INT32 index;
                 ^
../src/elf-loader_1.0/vpi_wrapper.c: In function 'setup_finish_callbacks':
../src/elf-loader_1.0/vpi_wrapper.c:251:3: warning: missing initializer for field 'high' of 's_vpi_time {aka struct t_vpi_time}' [-Wmissing-field-initializers]
   static s_vpi_time time_s = {vpiScaledRealTime};
   ^
In file included from ../src/elf-loader_1.0/vpi_wrapper.c:21:0:
C:/msys64/mingw32/include/iverilog/vpi_user.h:95:18: note: 'high' declared here
       PLI_UINT32 high;
                  ^
../src/elf-loader_1.0/vpi_wrapper.c:252:3: warning: missing initializer for field 'value' of 's_vpi_value {aka struct t_vpi_value}' [-Wmissing-field-initializers]
   static s_vpi_value value_s = {vpiBinStrVal};
   ^
In file included from ../src/elf-loader_1.0/vpi_wrapper.c:21:0:
C:/msys64/mingw32/include/iverilog/vpi_user.h:128:9: note: 'value' declared here
       } value;
         ^
../src/elf-loader_1.0/vpi_wrapper.c:260:5: warning: missing initializer for field 'index' of 's_cb_data {aka struct t_cb_data}' [-Wmissing-field-initializers]
     };
     ^
In file included from ../src/elf-loader_1.0/vpi_wrapper.c:21:0:
C:/msys64/mingw32/include/iverilog/vpi_user.h:461:17: note: 'index' declared here
       PLI_INT32 index;

On msys2 installations, libelf headers are provided under /mingw{32,64}/include/libelf. For now, I hardcoded the icarus simulator to search that path.

When that issue is taken care of, I tickle what I suspect is a bug in iverilog-vpi (have not currently checked if it was reported, too busy), so I had to compile to object files manually and pass in the object files to iverilog-vpi (since I cannot customize how VPI modules are build in fusesoc).

gcc -c -Wall -Wextra -Wshadow   -g -O2 -I"C:\msys64\mingw32\\include\\iverilog" -I/mingw32/include/libelf vpi_wrapper.c
gcc -c -Wall -Wextra -Wshadow   -g -O2 -I"C:\msys64\mingw32\\include\\iverilog" -I/mingw32/include/libelf elf-loader.c
iverilog-vpi -lelf --name=elf-loader_1.0 -I/mingw32/include/libelf vpi_wrapper.o elf-loader.o

Even after all that, compiling the elf-loader failed because it appears my libelf is too new (which is the one provided by msys2):

elf-loader.o: In function `dump_program_data':
C:\msys64\home\William\src\ymsoc2\build\ymsoc2_0\src\elf-loader_1.0/elf-loader.c:64: undefined reference to `elf_getdata_rawchunk'
collect2.exe: error: ld returned 1 exit status

At the moment, I am unsure how to proceed, but the consequence is that iverilog simulation does not work at all since (AFAICT) the elf loader is a prerequisite. This is a placeholder issue for now. I currently don't have the time to try and fix this myself :(.

olofk commented 7 years ago

It seems like you have put in quite some effort to make this work. I tried something similar and eventually gave up. I think one problem is that libelf is too old to work, and has been more or less replace with elfutils. Unfortunately, it seems like no one has ever managed to compile elfutils on Windows.

This is very unfortunate, since elf-loader is a dependency for a lot of the systems in the base library. I've been thinking a lot about how to solve this, and come to the conclusion that I will need to either or both

  1. Build a simple elf parser (based on elfutils or something else) that doesn't have all the complexities of elfutils, and can be easier ported to windows
  2. Make elf-loader an optional dependency, and add an alternative to preload memories from verilog hex files, or similar (I'm working right now on better support for optional dependencies in FuseSoC)

So, for now, all I can say is that I'm sorry that things involving elf-loader doesn't work well on windows. I've had reports that it might work on cygwin, so maybe that could be a workaround.

Kreijstal commented 1 month ago

maybe elfutils has gotten better nowdays?