-
Notifications
You must be signed in to change notification settings - Fork 32
Description
I'm working on porting the Binary Analysis Platform / BAP to Windows.
Unless I am misunderstanding, the mingw64 chain , >=OCaml 4.12.1, and >=Binutils 2.36 should no longer be experiencing runtime plugin/dll relocation failures with RELOC_REL32.
Using MSYS2's UCRT shell/toolchain (I have this same issue in Cygwin, too.), MinGW GCC 11.2, OCaml 4.13.1 + flambda, and the latest git source of flexdll.
However, the LLVM-backend plugin for BAP is erroring out here. If I get flexlink to pass --default-image-base-low when linking the main executable and the breaking plugin, it's fine. Decorating the symbol as a dllimport, in the plugin code, didn't appear to make a difference.
No other plugins seem to have this issue, even when they are left with a high base address & the executable is low.
Failed to load plugin "bap-plugin-llvm": Failed to load bap_llvm: error loading shared library: Dynlink.Error (Dynlink.Cannot_open_dll "(Failure\n \"flexdll error: cannot relocate _ZN3bap21register_disassemblerENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt10shared_ptrINS_14disasm_factoryEE RELOC_REL32, target is too far: FFFFFFFCCE4E7D5B FFFFFFFFCE4E7D5B\")")
bap::register_disassembler(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::shared_ptr<bap::disasm_factory>)
These are the instantiation of the register_disassembler function in the main executable:
https://github.com/BinaryAnalysisPlatform/bap/blob/master/lib/bap_disasm/disasm.hpp
https://github.com/BinaryAnalysisPlatform/bap/blob/master/lib/bap_disasm/disasm.cpp
And this is the plugin's usage of it:
https://github.com/BinaryAnalysisPlatform/bap/blob/master/lib/bap_llvm/llvm_disasm.cpp
I'll be honest and say that I'm only guessing that this problem lies with FlexDLL, but it could be in OCaml itself, BAP's source code, MinGW, etc.
If needed, I can provide a way to reproduce this; however, it's unfortunately not a quick process, and will require manual steps in the build process. At that, I could also provide the virtual machine image or the msys64 folder.