-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for 'link_syms' parameter.
Test to make sure using --defsym in the link_syms parameter causes correct linker behavior between object files and static libraries for both C and C++. The C test validates that linking redirects from a symbol not defined by the library to a symbol that is defined by the library. The C++ test validates that linking redirects from one defined symbol to another defined symbol. Signed-off-by: Keith Packard <keithp@keithp.com>
- Loading branch information
1 parent
2b3a3b9
commit a06972a
Showing
7 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "cpplib.h" | ||
|
||
int main(void) { | ||
return cppfunc_sym() != 42; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
project('link_syms linking test', ['c', 'cpp']) | ||
|
||
c_compiler = meson.get_compiler('c') | ||
|
||
has_link_defsym = c_compiler.has_link_argument('-Wl,--defsym=start=0') | ||
|
||
if has_link_defsym | ||
c_link_syms = '-Wl,--defsym=func_sym=func' | ||
cpp_link_syms = '-Wl,--defsym=_Z11cppfunc_symv=_Z7cppfuncv' | ||
else | ||
message(c_compiler.get_linker_id() + ' does not support --defsym so skipping.') | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |