Add test case for 'link_early_args' parameter.

Test to make sure using --defsym in the link_early_args parameter is
passed in the correct position in the linker command line.

Both C and C++ tests validate that the link_early_args values are
processed before objects and libraries by making sure that linking
redirects from a symbol not defined by the library to a symbol that is
defined by the library.

Signed-off-by: Keith Packard <keithp@keithp.com>
pull/14004/head
Keith Packard 3 months ago
parent 8044c95557
commit 2e2e59824e
  1. 10
      test cases/common/281 link-early-args/cpplib.cpp
  2. 13
      test cases/common/281 link-early-args/cpplib.h
  3. 5
      test cases/common/281 link-early-args/cppmain.cpp
  4. 14
      test cases/common/281 link-early-args/libfile.c
  5. 12
      test cases/common/281 link-early-args/main.c
  6. 27
      test cases/common/281 link-early-args/meson.build
  7. 2
      test cases/common/281 link-early-args/test.json

@ -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;
}

@ -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);

@ -0,0 +1,5 @@
#include "cpplib.h"
int main(void) {
return cppfunc_sym() != 42;
}

@ -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;
}

@ -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();
}

@ -0,0 +1,27 @@
project('link_early_args linking test', ['c', 'cpp'])
message('host_machine ' + host_machine.system() + ' build_machine ' + build_machine.system())
if host_machine.system() == 'linux'
c_link_early_args = '-Wl,--defsym=func_sym=func'
cpp_link_early_args = '-Wl,--defsym=_Z11cppfunc_symv=_Z7cppfuncv'
else
message('unsupported on ' + host_machine.system())
c_link_early_args = ''
cpp_link_early_args = ''
endif
if c_link_early_args != ''
lib = static_library('mylib', 'libfile.c', install : false)
exe = executable('prog', 'main.c',
link_early_args : c_link_early_args,
link_with : lib)
test('runtest', exe)
cpplib = static_library('mycpplib', 'cpplib.cpp')
cppexe = executable('cppprog', 'cppmain.cpp',
link_early_args : cpp_link_early_args,
link_with : cpplib)
test('cpptest', cppexe)
endif
Loading…
Cancel
Save