diff --git a/test cases/common/281 link-syms/cpplib.cpp b/test cases/common/281 link-syms/cpplib.cpp new file mode 100644 index 000000000000..c337a5270ccd --- /dev/null +++ b/test cases/common/281 link-syms/cpplib.cpp @@ -0,0 +1,10 @@ +#define BUILDING_DLL +#include "cpplib.h" + +int DLL_PUBLIC cppfunc(void) { + return 42; +} + +int DLL_PUBLIC cppfunc_sym(void) { + return 43; +} diff --git a/test cases/common/281 link-syms/cpplib.h b/test cases/common/281 link-syms/cpplib.h new file mode 100644 index 000000000000..4b000780b7ae --- /dev/null +++ b/test cases/common/281 link-syms/cpplib.h @@ -0,0 +1,13 @@ +/* See http://gcc.gnu.org/wiki/Visibility#How_to_use_the_new_C.2B-.2B-_visibility_support */ +#if defined(_WIN32) || defined(__CYGWIN__) + #ifdef BUILDING_DLL + #define DLL_PUBLIC __declspec(dllexport) + #else + #define DLL_PUBLIC __declspec(dllimport) + #endif +#else + #define DLL_PUBLIC __attribute__ ((visibility ("default"))) +#endif + +int DLL_PUBLIC cppfunc_sym(void); +int DLL_PUBLIC cppfunc(void); diff --git a/test cases/common/281 link-syms/cppmain.cpp b/test cases/common/281 link-syms/cppmain.cpp new file mode 100644 index 000000000000..602b66231c04 --- /dev/null +++ b/test cases/common/281 link-syms/cppmain.cpp @@ -0,0 +1,5 @@ +#include "cpplib.h" + +int main(void) { + return cppfunc_sym() != 42; +} diff --git a/test cases/common/281 link-syms/libfile.c b/test cases/common/281 link-syms/libfile.c new file mode 100644 index 000000000000..91489b287928 --- /dev/null +++ b/test cases/common/281 link-syms/libfile.c @@ -0,0 +1,14 @@ +#if defined _WIN32 || defined __CYGWIN__ + #define DLL_PUBLIC __declspec(dllexport) +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +int DLL_PUBLIC func(void) { + return 0; +} diff --git a/test cases/common/281 link-syms/main.c b/test cases/common/281 link-syms/main.c new file mode 100644 index 000000000000..90f6e9decc69 --- /dev/null +++ b/test cases/common/281 link-syms/main.c @@ -0,0 +1,12 @@ +#if defined _WIN32 || defined __CYGWIN__ + #define DLL_IMPORT __declspec(dllimport) +#else + #define DLL_IMPORT +#endif + +int DLL_IMPORT func_sym(void); +int DLL_IMPORT func(void); + +int main(void) { + return func_sym(); +} diff --git a/test cases/common/281 link-syms/meson.build b/test cases/common/281 link-syms/meson.build new file mode 100644 index 000000000000..63db21e6f3f1 --- /dev/null +++ b/test cases/common/281 link-syms/meson.build @@ -0,0 +1,25 @@ +project('link_syms linking test', ['c', 'cpp']) + +if build_machine.system() == 'linux' + c_link_syms = '-Wl,--defsym=func_sym=func' + cpp_link_syms = '-Wl,--defsym=_Z11cppfunc_symv=_Z7cppfuncv' +else + message('unsupported on ' + build_machine.system()) + c_link_syms = '' + cpp_link_syms = '' +endif + +if c_link_syms != '' + lib = static_library('mylib', 'libfile.c', install : false) + exe = executable('prog', 'main.c', + link_syms : c_link_syms, + link_with : lib) + + test('runtest', exe) + + cpplib = static_library('mycpplib', 'cpplib.cpp') + cppexe = executable('cppprog', 'cppmain.cpp', + link_syms : cpp_link_syms, + link_with : cpplib) + test('cpptest', cppexe) +endif diff --git a/test cases/common/281 link-syms/test.json b/test cases/common/281 link-syms/test.json new file mode 100644 index 000000000000..2c63c0851048 --- /dev/null +++ b/test cases/common/281 link-syms/test.json @@ -0,0 +1,2 @@ +{ +}