apolukhin / Boost.DLL

Library for comfortable work with DLL and DSO
https://boost.org/libs/dll
109 stars 69 forks source link

Reading a dll file on Linux #35

Closed thelfer closed 7 years ago

thelfer commented 7 years ago

Dear developpers,

First, let me thank you all for creating this very usefull library.

I tried to read a dll file under Linux. I am using Boost 1.63 under Debian Jessie with gcc 4.9.2.

The test is the following:

#include <boost/dll/shared_library.hpp>
#include <boost/dll/library_info.hpp>
#include <iostream>

int main(void) {
  boost::dll::library_info i("./MFrontCastemBehaviours.dll");
  return 0;
}

This test fails with the following exception:

terminate called after throwing an instance of 'std::ios_base::failure'
  what():  basic_ios::clear
Abandon

Under gdb, we see that something goes wrong in boost::dll::detail::pe_info::parsing_supported.

#7  0x00007ffff794adda in std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#8  0x00007ffff794dd73 in std::istream::seekg(std::fpos<__mbstate_t>) ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9  0x0000000000402e1d in boost::dll::detail::pe_info<unsigned long>::parsing_supported (f=...) at ../../1.63/install/include/boost/dll/detail/pe_info.hpp:188
#10 0x00000000004025e5 in boost::dll::library_info::init (this=0x7fffffffde70, 
    throw_if_not_native=true)
    at ../../1.63/install/include/boost/dll/library_info.hpp:101
#11 0x0000000000402877 in boost::dll::library_info::library_info (
    this=0x7fffffffde70, library_path=..., throw_if_not_native_format=true)
    at ../../1.63/install/include/boost/dll/library_info.hpp:140
#12 0x0000000000401d4e in main () at symbols.cxx:14

The DLL that is tested comes from the unit-tests of my project and has been generated with Visual Studio 2015. This DLL works as expected under windows so I don't expect that the issue is related to that specific DLL.

With kind regards, Thomas Helfer

MFrontCastemBehaviours.dll.zip

apolukhin commented 7 years ago

Hello,

Thanks for the issue report. Please try the following code:

#include <boost/dll/shared_library.hpp>
#include <boost/dll/library_info.hpp>
#include <iostream>

int main(void) {
  boost::dll::library_info i("./MFrontCastemBehaviours.dll", false);
}

The second parameter in that sample is throw_if_not_native_format

Please, tell me about results of your experiment.

thelfer commented 7 years ago

Hi, does not seem to change anything. Indeed, this argument is considered after the call to boost::dll::detail::elf_info64::parsing_supported and throws an exception derived from boost::exception. Regards

apolukhin commented 7 years ago

That's interesting. I'll take a look soon.

thelfer commented 7 years ago

Thanks. If I can be of any help, do not hesitate. BTW, once this issue will be solved, this dll will be used to open a new one: under Windows, only the imported symbols seems returned by the symbols() method, not the exported ones (however I need to strengthen this point since I don't have access to my Windows box now, this is reason why I tried to read this dll from Linux). Note that if I take the MFrontCastemBehaviours.so shared library generated by the same project under Linux, everything works as expected. Regards, Thomas

apolukhin commented 7 years ago

Congratulations! You're the first one who queried .dll files on 64 bit Linux.

Fixed issue in 9bfe5dd. Tested with getting symbols and sections - worked well.

Great thanks for the issue report.

thelfer commented 7 years ago

Thanks at lot for your work and the fix. Regards, Thomas

apolukhin commented 7 years ago

Fixed a little bit more in 6b566b0