Fix LTO test on Cygwin

This partially reverts commit add502c648.

In 'linkshared' test, annotate cppfunc() as imported, so an indirection
through an import stub is generated, avoiding a relocation size error
when building using gcc for Cygwin with LTO on.

Align with the example of how to write this portably in [1].

The 'c' language part of that test already gets this right.

[1] http://gcc.gnu.org/wiki/Visibility
pull/8786/head
Jon Turney 4 years ago
parent 91aeae558d
commit f76c6b8d0a
No known key found for this signature in database
GPG Key ID: C7C86F0370285C81
  1. 2
      run_unittests.py
  2. 7
      test cases/common/6 linkshared/cpplib.cpp
  3. 12
      test cases/common/6 linkshared/cpplib.h
  4. 2
      test cases/common/6 linkshared/cppmain.cpp

@ -3075,8 +3075,6 @@ class AllPlatformTests(BasePlatformTests):
@skip_if_not_base_option('b_lto_threads')
def test_lto_threads(self):
if is_cygwin():
raise unittest.SkipTest('LTO is broken on Cygwin.')
testdir = os.path.join(self.common_test_dir, '6 linkshared')
env = get_fake_env(testdir, self.builddir, self.prefix)

@ -1,8 +1,5 @@
#if defined _WIN32
#define DLL_PUBLIC __declspec(dllexport)
#else
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
#endif
#define BUILDING_DLL
#include "cpplib.h"
int DLL_PUBLIC cppfunc(void) {
return 42;

@ -0,0 +1,12 @@
/* 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(void);

@ -1,4 +1,4 @@
int cppfunc(void);
#include "cpplib.h"
int main(void) {
return cppfunc() != 42;

Loading…
Cancel
Save