Skip to content

Commit b5cbc02

Browse files
committed
fix: always use delayed loading for WinFsp DLL
1 parent 4e60bbb commit b5cbc02

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

CMakeLists.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,16 @@ list(APPEND MAIN_TARGETS mkdwarfs_main dwarfsck_main dwarfsbench_main
617617
if(FUSE3_FOUND OR WINFSP OR APPLE)
618618
add_library(dwarfs_main src/dwarfs_main.cpp)
619619
target_compile_definitions(dwarfs_main PRIVATE _FILE_OFFSET_BITS=64)
620+
add_executable(dwarfs-bin src/dwarfs.cpp)
621+
target_link_libraries(dwarfs-bin dwarfs_main)
622+
set_target_properties(dwarfs-bin PROPERTIES OUTPUT_NAME dwarfs)
620623
if(WINFSP)
621624
target_compile_definitions(dwarfs_main PRIVATE FUSE_USE_VERSION=32
622625
DWARFS_FUSE_LOWLEVEL=0)
623626
target_include_directories(dwarfs_main SYSTEM PRIVATE "${WINFSP_PATH}/inc")
624627
target_link_libraries(dwarfs_main ${WINFSP})
628+
target_link_libraries(dwarfs-bin delayimp.lib)
629+
target_link_options(dwarfs-bin PRIVATE /DELAYLOAD:winfsp-x64.dll)
625630
if(WITH_UNIVERSAL_BINARY)
626631
target_link_libraries(dwarfsuniversal delayimp.lib)
627632
target_link_options(dwarfsuniversal PRIVATE /DELAYLOAD:winfsp-x64.dll)
@@ -633,9 +638,6 @@ if(FUSE3_FOUND OR WINFSP OR APPLE)
633638
target_compile_definitions(dwarfs_main PRIVATE FUSE_USE_VERSION=35)
634639
target_link_libraries(dwarfs_main PkgConfig::FUSE3)
635640
endif()
636-
add_executable(dwarfs-bin src/dwarfs.cpp)
637-
target_link_libraries(dwarfs-bin dwarfs_main)
638-
set_target_properties(dwarfs-bin PROPERTIES OUTPUT_NAME dwarfs)
639641
if(WITH_UNIVERSAL_BINARY)
640642
target_link_libraries(dwarfsuniversal dwarfs_main)
641643
endif()

src/dwarfs_main.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#endif
7373

7474
#ifdef _WIN32
75+
#include <delayimp.h>
7576
#include <fuse3/winfsp_fuse.h>
7677
#define st_atime st_atim.tv_sec
7778
#define st_ctime st_ctim.tv_sec
@@ -97,6 +98,7 @@
9798
#include "dwarfs_tool_main.h"
9899

99100
namespace {
101+
100102
#ifdef DWARFS_FSP_COMPAT
101103
using native_stat = struct ::fuse_stat;
102104
using native_statvfs = struct ::fuse_statvfs;
@@ -106,8 +108,32 @@ using native_stat = struct ::stat;
106108
using native_statvfs = struct ::statvfs;
107109
using native_off_t = ::off_t;
108110
#endif
111+
112+
#ifdef _WIN32
113+
FARPROC WINAPI delay_hook(unsigned dliNotify, PDelayLoadInfo pdli) {
114+
switch (dliNotify) {
115+
case dliFailLoadLib:
116+
std::cerr << "failed to load " << pdli->szDll << "\n";
117+
break;
118+
119+
case dliFailGetProc:
120+
std::cerr << "failed to load symbol from " << pdli->szDll << "\n";
121+
break;
122+
123+
default:
124+
return NULL;
125+
}
126+
127+
::exit(1);
128+
}
129+
#endif
130+
109131
} // namespace
110132

133+
#ifdef _WIN32
134+
extern "C" const PfnDliHook __pfnDliFailureHook2 = delay_hook;
135+
#endif
136+
111137
namespace dwarfs {
112138

113139
namespace {

src/universal.cpp

-27
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
#include <folly/gen/String.h>
3232
#include <folly/portability/Windows.h>
3333

34-
#ifdef _WIN32
35-
#include <delayimp.h>
36-
#endif
37-
3834
#include "dwarfs/safe_main.h"
3935
#include "dwarfs/tool.h"
4036
#include "dwarfs/util.h"
@@ -44,25 +40,6 @@ namespace {
4440

4541
using namespace dwarfs;
4642

47-
#ifdef _WIN32
48-
FARPROC WINAPI delay_hook(unsigned dliNotify, PDelayLoadInfo pdli) {
49-
switch (dliNotify) {
50-
case dliFailLoadLib:
51-
std::cerr << "failed to load " << pdli->szDll << "\n";
52-
break;
53-
54-
case dliFailGetProc:
55-
std::cerr << "failed to load symbol from " << pdli->szDll << "\n";
56-
break;
57-
58-
default:
59-
return NULL;
60-
}
61-
62-
::exit(1);
63-
}
64-
#endif
65-
6643
#ifdef _WIN32
6744
#define EXE_EXT ".exe"
6845
#else
@@ -79,10 +56,6 @@ std::map<std::string_view, int (*)(int, sys_char**)> const functions{
7956

8057
} // namespace
8158

82-
#ifdef _WIN32
83-
extern "C" const PfnDliHook __pfnDliFailureHook2 = delay_hook;
84-
#endif
85-
8659
int SYS_MAIN(int argc, sys_char** argv) {
8760
auto path = std::filesystem::path(argv[0]);
8861

0 commit comments

Comments
 (0)