serge1 / ELFIO

ELFIO - ELF (Executable and Linkable Format) reader and producer implemented as a header only C++ library
http://serge1.github.io/ELFIO
MIT License
720 stars 155 forks source link

Compile warnings on platforms where size_t is not 64-bits #85

Closed Matthew-McRaven closed 2 years ago

Matthew-McRaven commented 2 years ago

In elfio_segment.hpp, line 172, a ULLONG is passed to set_stream_size. On platforms where sizeof(size_t) != sizeof(uint64_t), this will cause a compile time warning about constant conversion. This also affects elfio_section.hpp

I am raising this issue because (strangely enough), I have a 32-bit use case. My project consumes this library, and outputs a WASM binary. WASM, as of right now, always uses 32-bit pointers, which to my understanding means size_t is 32-bits, not 64-bits. This causes my compilation logs to be flooded with constant conversion warning.

I see two easy ways to fix this:

  1. Change the signature of set_stream_size to always take a uint64_t.
  2. Pass a value of std::numeric_limits<size_t>::max() to set_stream_size (see reference).

My preference would be option 2, as this would avoid API type changes.

If either of these approaches are acceptable, I will open a pull request.

serge1 commented 2 years ago

Hi,

Thank you for your interest in the library. Yes, please submit the PR. In case additional questions will raise, we'll be able to discuss them there.

Best regards, Serge