Make fuse_main_real() not symboled
authorBernd Schubert <bernd@bsbernd.com>
Sat, 4 Jan 2025 22:18:14 +0000 (23:18 +0100)
committerBernd Schubert <bernd@bsbernd.com>
Mon, 10 Feb 2025 15:56:45 +0000 (16:56 +0100)
Addresses https://github.com/libfuse/libfuse/issues/1092

We actually don't need to make fuse_main_real() symboled, as it
is not part of the official API.

The inlined function now always calls into fuse_main_real_317
and the compat ABI function (which should also be available
for dlopen/dlsym) is now always compiled, independent if the
compiler/linker support versioned symbols.

Additionally, fuse_main_real() is also declared as inlined
function and a warning message is created when that function
is called.

Signed-off-by: Bernd Schubert <bernd@bsbernd.com>
include/fuse.h
lib/compat.c
lib/fuse_versionscript
lib/helper.c

index c3add843aefad7ecf2d44ff72134c5607c7ccffb..969ed97855f96fc02972d6342f207db39a5de70a 100644 (file)
@@ -877,21 +877,32 @@ struct fuse_context {
        mode_t umask;
 };
 
-#if (defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS))
 /**
  * The real main function
  *
  * Do not call this directly, use fuse_main()
  */
-int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
-                  size_t op_size, struct libfuse_version *version,
-                  void *user_data);
-#else
-int fuse_main_real_317(int argc, char *argv[], const struct fuse_operations *op,
-                  size_t op_size, struct libfuse_version *version, void *user_data);
-#define fuse_main_real(argc, argv, op, op_size, version, user_data) \
-       fuse_main_real_317(argc, argv, op, op_size, version, user_data);
-#endif
+static inline int fuse_main_real(int argc, char *argv[],
+                                const struct fuse_operations *op,
+                                size_t op_size, void *user_data)
+{
+       struct libfuse_version version = { .major = FUSE_MAJOR_VERSION,
+                                          .minor = FUSE_MINOR_VERSION,
+                                          .hotfix = FUSE_HOTFIX_VERSION,
+                                          .padding = 0 };
+
+       fuse_log(FUSE_LOG_ERR,
+                "%s is a libfuse internal function, please use fuse_main()\n",
+                __func__);
+
+       /* not declared globally, to restrict usage of this function */
+       int fuse_main_real_317(int argc, char *argv[],
+                              const struct fuse_operations *op, size_t op_size,
+                              struct libfuse_version *version,
+                              void *user_data);
+
+       return fuse_main_real_317(argc, argv, op, op_size, &version, user_data);
+}
 
 /**
  * Main function of FUSE.
@@ -957,8 +968,14 @@ fuse_main(int argc, char *argv[], const struct fuse_operations *op,
                .hotfix = FUSE_HOTFIX_VERSION,
                .padding = 0
        };
-       return fuse_main_real(argc, argv, op, sizeof(*(op)), &version,
-                             user_data);
+
+       /* not declared globally, to restrict usage of this function */
+       int fuse_main_real_317(int argc, char *argv[],
+                              const struct fuse_operations *op, size_t op_size,
+                              struct libfuse_version *version,
+                              void *user_data);
+       return fuse_main_real_317(argc, argv, op, sizeof(*(op)), &version,
+                                 user_data);
 }
 
 /* ----------------------------------------------------------- *
index ce8a93399affdc8ef44abbaead0a7cb9deabb455..685229920265af9240098f79cf52daf38d46879e 100644 (file)
@@ -18,6 +18,7 @@
 #include "libfuse_config.h"
 
 #include <stddef.h>
+#include <stdint.h>
 
 struct fuse_args;
 struct fuse_cmdline_opts;
@@ -59,16 +60,6 @@ int fuse_session_custom_io(struct fuse_session *se,
        return fuse_session_custom_io_30(se, io, fd);
 }
 
-int fuse_main_real_30(int argc, char *argv[], const struct fuse_operations *op,
-                     size_t op_size, void *user_data);
-int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
-                  size_t op_size, void *user_data);
-int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
-                  size_t op_size, void *user_data)
-{
-       return fuse_main_real_30(argc, argv, op, op_size, user_data);
-}
-
 struct fuse_session *fuse_session_new_30(struct fuse_args *args,
                                         const struct fuse_lowlevel_ops *op,
                                         size_t op_size, void *userdata);
@@ -82,6 +73,14 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
        return fuse_session_new_30(args, op, op_size, userdata);
 }
 
-#endif
-
+#endif /* LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS */
 
+int fuse_main_real_30(int argc, char *argv[], const struct fuse_operations *op,
+                     size_t op_size, void *user_data);
+int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
+                  size_t op_size, void *user_data);
+int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
+                  size_t op_size, void *user_data)
+{
+       return fuse_main_real_30(argc, argv, op, op_size, user_data);
+}
index f20e2b43eb5dd80795fc0ab62166a8a1615b614d..78df3f0296e9c18d956b331da3fedc90ffc87e20 100644 (file)
@@ -189,10 +189,10 @@ FUSE_3.12 {
 
 FUSE_3.17 {
        global:
+               fuse_main_real_317;
 #if !defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS)
                _fuse_session_new_317;
                _fuse_new_317;
-               fuse_main_real_317;
 #endif
                fuse_passthrough_open;
                fuse_passthrough_close;
index 2794e66bb2c97c0f3f7d702716f81614dee2c914..660f029cd8ed84ded92dc9f5d2770d1f425e6f04 100644 (file)
@@ -304,9 +304,10 @@ int fuse_daemonize(int foreground)
        return 0;
 }
 
+/* Not symboled, as not part of the official API */
 int fuse_main_real_317(int argc, char *argv[], const struct fuse_operations *op,
-                  size_t op_size, struct libfuse_version *version, void *user_data);
-FUSE_SYMVER("fuse_main_real_317", "fuse_main_real@@FUSE_3.17")
+                      size_t op_size, struct libfuse_version *version,
+                      void *user_data);
 int fuse_main_real_317(int argc, char *argv[], const struct fuse_operations *op,
                   size_t op_size, struct libfuse_version *version, void *user_data)
 {
@@ -400,14 +401,13 @@ out1:
        return res;
 }
 
+/* Not symboled, as not part of the official API */
 int fuse_main_real_30(int argc, char *argv[], const struct fuse_operations *op,
                      size_t op_size, void *user_data);
-FUSE_SYMVER("fuse_main_real_30", "fuse_main_real@FUSE_3.0")
 int fuse_main_real_30(int argc, char *argv[], const struct fuse_operations *op,
                      size_t op_size, void *user_data)
 {
        struct libfuse_version version = { 0 };
-
        return fuse_main_real_317(argc, argv, op, op_size, &version, user_data);
 }