From 83f682385543d949e4ee5e1271a96beddaa9a23b Mon Sep 17 00:00:00 2001 From: Tom Callaway Date: Fri, 11 Sep 2020 05:15:43 -0400 Subject: [PATCH] Implement GCC 10 style symbol versioning (#545) --- .travis.yml | 4 +++- lib/fuse.c | 8 ++++---- lib/fuse_loop_mt.c | 4 ++-- lib/fuse_misc.h | 8 ++++++-- meson.build | 17 +++++++++++++++++ test/travis-build.sh | 7 ++++++- 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb1fbf9..48a92ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ sudo: required -dist: xenial +dist: bionic language: - c @@ -13,8 +13,10 @@ addons: - valgrind - clang - libstdc++-7-dev + - libstdc++-10-dev - gcc - gcc-7 + - gcc-10 - python3-pip - python3-setuptools - ninja-build diff --git a/lib/fuse.c b/lib/fuse.c index b0f5b30..70299ef 100755 --- a/lib/fuse.c +++ b/lib/fuse.c @@ -4569,7 +4569,7 @@ int fuse_loop(struct fuse *f) return fuse_session_loop(f->se); } -FUSE_SYMVER(".symver fuse_loop_mt_32,fuse_loop_mt@@FUSE_3.2"); +FUSE_SYMVER("fuse_loop_mt_32", "fuse_loop_mt@@FUSE_3.2") int fuse_loop_mt_32(struct fuse *f, struct fuse_loop_config *config) { if (f == NULL) @@ -4585,7 +4585,7 @@ int fuse_loop_mt_32(struct fuse *f, struct fuse_loop_config *config) } int fuse_loop_mt_31(struct fuse *f, int clone_fd); -FUSE_SYMVER(".symver fuse_loop_mt_31,fuse_loop_mt@FUSE_3.0"); +FUSE_SYMVER("fuse_loop_mt_31", "fuse_loop_mt@FUSE_3.0") int fuse_loop_mt_31(struct fuse *f, int clone_fd) { struct fuse_loop_config config; @@ -4870,7 +4870,7 @@ void fuse_stop_cleanup_thread(struct fuse *f) } -FUSE_SYMVER(".symver fuse_new_31,fuse_new@@FUSE_3.1"); +FUSE_SYMVER("fuse_new_31", "fuse_new@@FUSE_3.1") struct fuse *fuse_new_31(struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *user_data) @@ -5024,7 +5024,7 @@ out: /* Emulates 3.0-style fuse_new(), which processes --help */ struct fuse *fuse_new_30(struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *private_data); -FUSE_SYMVER(".symver fuse_new_30,fuse_new@FUSE_3.0"); +FUSE_SYMVER("fuse_new_30", "fuse_new@FUSE_3.0") struct fuse *fuse_new_30(struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *user_data) diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c index 445e9a0..0c6a5b7 100644 --- a/lib/fuse_loop_mt.c +++ b/lib/fuse_loop_mt.c @@ -304,7 +304,7 @@ static void fuse_join_worker(struct fuse_mt *mt, struct fuse_worker *w) free(w); } -FUSE_SYMVER(".symver fuse_session_loop_mt_32,fuse_session_loop_mt@@FUSE_3.2"); +FUSE_SYMVER("fuse_session_loop_mt_32", "fuse_session_loop_mt@@FUSE_3.2") int fuse_session_loop_mt_32(struct fuse_session *se, struct fuse_loop_config *config) { int err; @@ -352,7 +352,7 @@ int fuse_session_loop_mt_32(struct fuse_session *se, struct fuse_loop_config *co } int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd); -FUSE_SYMVER(".symver fuse_session_loop_mt_31,fuse_session_loop_mt@FUSE_3.0"); +FUSE_SYMVER("fuse_session_loop_mt_31", "fuse_session_loop_mt@FUSE_3.0") int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd) { struct fuse_loop_config config; diff --git a/lib/fuse_misc.h b/lib/fuse_misc.h index 2f6663e..a8b5961 100644 --- a/lib/fuse_misc.h +++ b/lib/fuse_misc.h @@ -14,9 +14,13 @@ - not supported on MacOSX (in MachO binary format) */ #if (!defined(__UCLIBC__) && !defined(__APPLE__)) -#define FUSE_SYMVER(x) __asm__(x) +# if HAVE_SYMVER_ATTRIBUTE +# define FUSE_SYMVER(sym1, sym2) __attribute__ ((symver (sym2))) +# else +# define FUSE_SYMVER(sym1, sym2) __asm__("\t.symver " sym1 "," sym2); +# endif #else -#define FUSE_SYMVER(x) +#define FUSE_SYMVER(sym1, sym2) #endif #ifndef USE_UCLIBC diff --git a/meson.build b/meson.build index dbef8ab..e17ebb0 100644 --- a/meson.build +++ b/meson.build @@ -87,6 +87,23 @@ if not cc.compiles(code, args: [ '-O0', '-Werror=unused-result' ]) add_project_arguments('-Wno-unused-result', language: 'c') endif +# gcc-10 and newer support the symver attribute which we need to use if we +# want to support LTO +code = ''' +__attribute__((symver ("get@@TEST_0"))) int get_4() { + return 4; +} +int main(void) { + (void) get_4(); + return 0; +}''' +if cc.compiles(code, args: [ '-O0', '-c']) + message('Compiler supports symver attribute') + add_project_arguments('-DHAVE_SYMVER_ATTRIBUTE', language: 'c') +else + message('Compiler does not support symver attribute') +endif + # '.' will refer to current build directory, which contains config.h include_dirs = include_directories('include', 'lib', '.') diff --git a/test/travis-build.sh b/test/travis-build.sh index b2f3610..6e2afd5 100755 --- a/test/travis-build.sh +++ b/test/travis-build.sh @@ -25,7 +25,7 @@ chmod 0755 "${TEST_DIR}" cd "${TEST_DIR}" # Standard build -for CC in gcc gcc-7 clang; do +for CC in gcc gcc-7 gcc-10 clang; do mkdir build-${CC}; cd build-${CC} if [ "${CC}" == "clang" ]; then export CXX="clang++" @@ -35,6 +35,11 @@ for CC in gcc gcc-7 clang; do else build_opts='' fi + if [ ${CC} == 'gcc-10' ]; then + build_opts='-Dc_args="-flto=auto -ffat-lto-objects"' + else + build_opts='' + fi meson -D werror=true ${build_opts} "${SOURCE_DIR}" || (cat meson-logs/meson-log.txt; false) ninja -- 2.30.2