diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-10-07 19:56:04 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-10-08 01:02:16 +0530 |
commit | ce1393609f0f870ffa1b0634f561613b7b627f0b (patch) | |
tree | ef7a2f23341f93370784cd9efc38a7441733af9a | |
parent | ee8b3b12a067c52efcfb7c05c638023fbe0495c8 (diff) | |
download | meson-ce1393609f0f870ffa1b0634f561613b7b627f0b.zip meson-ce1393609f0f870ffa1b0634f561613b7b627f0b.tar.gz meson-ce1393609f0f870ffa1b0634f561613b7b627f0b.tar.bz2 |
Error out if shared lib links to static lib without PIC
This is only needed on Linux and BSD. So, we always unconditionally
enable self.pic for Windows and OS X.
-rw-r--r-- | mesonbuild/build.py | 14 | ||||
-rw-r--r-- | test cases/failing/33 exe static shared/meson.build | 11 | ||||
-rw-r--r-- | test cases/failing/33 exe static shared/prog.c | 10 | ||||
-rw-r--r-- | test cases/failing/33 exe static shared/shlib2.c | 16 | ||||
-rw-r--r-- | test cases/failing/33 exe static shared/stat.c | 3 |
5 files changed, 51 insertions, 3 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index a532509..3d41cda 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -524,9 +524,15 @@ class BuildTarget(): raise InvalidArguments('Name suffix must be a string.') self.suffix = name_suffix if isinstance(self, StaticLibrary): - self.pic = kwargs.get('pic', False) - if not isinstance(self.pic, bool): - raise InvalidArguments('Argument pic must be boolean') + # You can't disable PIC on OS X. The compiler ignores -fno-PIC. + # PIC is always on for Windows (all code is position-independent + # since library loading is done differently) + if for_darwin(self.is_cross, self.environment) or for_windows(self.is_cross, self.environment): + self.pic = True + else: + self.pic = kwargs.get('pic', False) + if not isinstance(self.pic, bool): + raise InvalidArguments('Argument pic must be boolean') def get_subdir(self): return self.subdir @@ -629,6 +635,8 @@ by calling get_variable() on the subproject object.''') t = t.held_object if not isinstance(t, (StaticLibrary, SharedLibrary)): raise InvalidArguments('Link target is not library.') + if isinstance(self, SharedLibrary) and isinstance(t, StaticLibrary) and not t.pic: + raise InvalidArguments("Can't link a non-PIC static library into a shared library") if self.is_cross != t.is_cross: raise InvalidArguments('Tried to mix cross built and native libraries in target %s.' % self.name) self.link_targets.append(t) diff --git a/test cases/failing/33 exe static shared/meson.build b/test cases/failing/33 exe static shared/meson.build new file mode 100644 index 0000000..b102764 --- /dev/null +++ b/test cases/failing/33 exe static shared/meson.build @@ -0,0 +1,11 @@ +project('statchain', 'c') + +host_system = host_machine.system() +if host_system == 'windows' or host_system == 'darwin' + error('Test only fails on Linux and BSD') +endif + +statlib = static_library('stat', 'stat.c', pic : false) +shlib2 = shared_library('shr2', 'shlib2.c', link_with : statlib) +exe = executable('prog', 'prog.c', link_with : shlib2) +test('runtest', exe) diff --git a/test cases/failing/33 exe static shared/prog.c b/test cases/failing/33 exe static shared/prog.c new file mode 100644 index 0000000..26603b6 --- /dev/null +++ b/test cases/failing/33 exe static shared/prog.c @@ -0,0 +1,10 @@ +int shlibfunc2(); +int statlibfunc(); + +int main(int argc, char **argv) { + if (statlibfunc() != 42) + return 1; + if (shlibfunc2() != 24) + return 1; + return 0; +} diff --git a/test cases/failing/33 exe static shared/shlib2.c b/test cases/failing/33 exe static shared/shlib2.c new file mode 100644 index 0000000..5b68843 --- /dev/null +++ b/test cases/failing/33 exe static shared/shlib2.c @@ -0,0 +1,16 @@ +#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 statlibfunc(void); + +int DLL_PUBLIC shlibfunc2(void) { + return 24; +} diff --git a/test cases/failing/33 exe static shared/stat.c b/test cases/failing/33 exe static shared/stat.c new file mode 100644 index 0000000..56ec66c --- /dev/null +++ b/test cases/failing/33 exe static shared/stat.c @@ -0,0 +1,3 @@ +int statlibfunc() { + return 42; +} |