From 5839aeadbdcf08d039eef3a809dc5d78e2c7ba38 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 27 Apr 2018 17:45:23 +0100 Subject: [PATCH] meson: fix symbol export with MSVC and use -fvisibility elsewhere Use newly-added ORC_API decorators to export symbols explicitly. Get rid of orc.map file and the ORC_EXPORT stuff that never did anything anyway (define was unused). --- Makefile.am | 2 +- configure.ac | 2 -- meson.build | 18 ++++++++++++++---- orc-test/meson.build | 12 ++---------- orc-test/orc-test.map | 6 ------ orc-test/orctest.h | 6 ++++-- orc/meson.build | 13 ++----------- orc/orc.h | 4 ---- orc/orc.map | 6 ------ orc/orcutils.h | 17 +++++++++++------ 10 files changed, 34 insertions(+), 52 deletions(-) delete mode 100644 orc-test/orc-test.map delete mode 100644 orc/orc.map diff --git a/Makefile.am b/Makefile.am index bc0db2d..ede9987 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,7 +16,7 @@ DIST_SUBDIRS = orc orc-test tools examples testsuite doc EXTRA_DIST = COPYING RELEASE autogen.sh gtk-doc.make orc.m4 \ $(shell find "$(top_srcdir)" -type f -name meson.build ! -path "$(top_srcdir)/orc-0.4.*" ) \ - meson_options.txt orc/orc.map + meson_options.txt DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc diff --git a/configure.ac b/configure.ac index b630d5c..87ff117 100644 --- a/configure.ac +++ b/configure.ac @@ -230,8 +230,6 @@ AC_ARG_ENABLE(Bsymbolic, enable_Bsymbolic=no) LDFLAGS="${SAVED_LDFLAGS}" LIBS="${SAVED_LIBS}"]) -AC_DEFINE(ORC_EXPORTS, 1, [Defined for compiling internal code]) - ORC_CFLAGS="$ORC_CFLAGS \$(ERROR_CFLAGS) -I\$(top_srcdir) -D_GNU_SOURCE" AC_SUBST(ERROR_CFLAGS) AC_SUBST(ORC_CFLAGS) diff --git a/meson.build b/meson.build index af4f523..e2c6948 100644 --- a/meson.build +++ b/meson.build @@ -19,6 +19,9 @@ orc_inc = include_directories('.') cc = meson.get_compiler('c') +cdata = configuration_data() # config.h +pc_conf = configuration_data() # orc.pc + # -Bsymbolic-functions if meson.version().version_compare('>= 0.46.0') if cc.has_link_argument('-Wl,-Bsymbolic-functions') @@ -26,10 +29,17 @@ if meson.version().version_compare('>= 0.46.0') endif endif -cdata = configuration_data() # config.h -pc_conf = configuration_data() # orc.pc - -cdata.set('ORC_EXPORTS', true) +# Symbol visibility +if cc.get_id() == 'msvc' + export_define = '__declspec(dllexport) extern' +elif cc.has_argument('-fvisibility=hidden') + add_project_arguments('-fvisibility=hidden', language: 'c') + export_define = 'extern __attribute__ ((visibility ("default")))' +else + export_define = 'extern' +endif +# Passing this through the command line would be too messy +cdata.set('ORC_API_EXPORT', export_define) all_backends = ['sse', 'mmx', 'altivec', 'neon', 'mips', 'c64x'] # 'arm' diff --git a/orc-test/meson.build b/orc-test/meson.build index 994f391..d0471e0 100644 --- a/orc-test/meson.build +++ b/orc-test/meson.build @@ -3,27 +3,19 @@ orc_test_sources = ['orctest.c', 'orcarray.c', 'orcrandom.c', 'orcprofile.c'] install_headers(orc_test_headers, subdir : 'orc-' + orc_api + '/orc-test') -if cc.get_id() != 'msvc' - link_args = ['-Wl,--version-script,' + meson.current_source_dir() + '/orc-test.map'] -else - link_args = [] -endif - orc_test_shr = shared_library ('orc-test-' + orc_api, orc_test_sources, version : libversion, soversion : soversion, include_directories : orc_inc, - c_args : [ orc_c_args , '-DORC_ENABLE_UNSTABLE_API' ], + c_args : orc_c_args + ['-DBUILDING_ORC_TEST'], dependencies : [libm, orc_dep], - link_args : link_args, - link_depends : 'orc-test.map', install : true) orc_test_sta = static_library ('orc-test-' + orc_api, objects : orc_test_shr.extract_all_objects(), include_directories : orc_inc, - c_args : [ orc_c_args , '-DORC_ENABLE_UNSTABLE_API' ], + c_args : orc_c_args + ['-DBUILDING_ORC_TEST'], dependencies : [libm, orc_dep], install : true) diff --git a/orc-test/orc-test.map b/orc-test/orc-test.map deleted file mode 100644 index 47f2b25..0000000 --- a/orc-test/orc-test.map +++ /dev/null @@ -1,6 +0,0 @@ -{ -global: - orc_*; -local: - *; -}; diff --git a/orc-test/orctest.h b/orc-test/orctest.h index eddb0c7..6a86835 100644 --- a/orc-test/orctest.h +++ b/orc-test/orctest.h @@ -7,8 +7,10 @@ ORC_BEGIN_DECLS -#ifndef ORC_TEST_API -#define ORC_TEST_API extern +#ifdef BUILDING_ORC_TEST +#define ORC_TEST_API ORC_API_EXPORT /* defined in config.h */ +#else +#define ORC_TEST_API ORC_API_IMPORT #endif typedef enum { diff --git a/orc/meson.build b/orc/meson.build index 138c4d4..541603f 100644 --- a/orc/meson.build +++ b/orc/meson.build @@ -101,28 +101,19 @@ orc_c_args = ['-DORC_ENABLE_UNSTABLE_API', '-D_GNU_SOURCE'] orc_dependencies = [libm, librt, liblog] -# FIXME: Use gcc visibility attributes in ORC_EXPORT -if cc.get_id() != 'msvc' - link_args = ['-Wl,--version-script,' + meson.current_source_dir() + '/orc.map'] -else - link_args = [] -endif - orc_shr = shared_library ('orc-' + orc_api, orc_sources, version : libversion, soversion : soversion, include_directories : orc_inc, - c_args : orc_c_args, + c_args : orc_c_args + ['-DBUILDING_ORC'], dependencies : orc_dependencies, - link_args : link_args, - link_depends : 'orc.map', install : true) orc_sta = static_library ('orc-' + orc_api, objects: orc_shr.extract_all_objects(), include_directories : orc_inc, - c_args : orc_c_args, + c_args : orc_c_args + ['-DBUILDING_ORC'], install : true) if get_option('default_library') == 'static' diff --git a/orc/orc.h b/orc/orc.h index a3e4039..38de15b 100644 --- a/orc/orc.h +++ b/orc/orc.h @@ -2,10 +2,6 @@ #ifndef _ORC_ORC_H_ #define _ORC_ORC_H_ -#ifndef ORC_API -#define ORC_API extern -#endif - #include #include #include diff --git a/orc/orc.map b/orc/orc.map deleted file mode 100644 index 47f2b25..0000000 --- a/orc/orc.map +++ /dev/null @@ -1,6 +0,0 @@ -{ -global: - orc_*; -local: - *; -}; diff --git a/orc/orcutils.h b/orc/orcutils.h index a56f520..a15c75b 100644 --- a/orc/orcutils.h +++ b/orc/orcutils.h @@ -200,14 +200,19 @@ typedef unsigned int orc_bool; #define ORC_END_DECLS #endif -#ifdef _MSC_VER -#ifdef ORC_EXPORTS -#define ORC_EXPORT __declspec(dllexport) extern +/* FIXME: unused, remove */ +#define ORC_EXPORT + +#if defined(_MSC_VER) || defined(_WIN32) +#define ORC_API_IMPORT __declspec(dllimport) extern #else -#define ORC_EXPORT __declspec(dllimport) extern +#define ORC_API_IMPORT extern #endif -#else /* not _MSC_VER */ -#define ORC_EXPORT extern + +#ifdef BUILDING_ORC +#define ORC_API ORC_API_EXPORT /* defined in config.h */ +#else +#define ORC_API ORC_API_IMPORT #endif ORC_BEGIN_DECLS -- 2.7.4