From 91e219cc15c8325d144936515461c6c6a479b5c9 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 4 Jan 2019 21:47:12 +0200 Subject: [PATCH] Exported all additional symbols on macOS. Many functions in libc++ are marked with _LIBCPP_INLINE_VISIBILITY. This means they are only exported when actually used. This is why exporting just the templates themselves failed to export their functions but listing the functions themselves worked. We need to define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS to have the functions always exported. We use _LIBCPP_VERSION to detect if we use libc++ i.e. Clang's standard C++ library. Signed-off-by: Dimitar Dobrev --- .../i686-apple-darwin12.4.0/Std-symbols.cpp | 13 +++++++++---- .../CSharp/i686-pc-win32-msvc/Std-symbols.cpp | 6 ++++++ .../x86_64-apple-darwin12.4.0/Std-symbols.cpp | 13 +++++++++---- .../x86_64-linux-gnu-cxx11abi/Std-symbols.cpp | 6 ++++++ .../CSharp/x86_64-linux-gnu/Std-symbols.cpp | 6 ++++++ .../x86_64-pc-win32-msvc/Std-symbols.cpp | 6 ++++++ src/Generator/Passes/SymbolsCodeGenerator.cs | 19 ++++++++++++------- src/Generator/Types/Std/Stdlib.cs | 2 +- 8 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std-symbols.cpp b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std-symbols.cpp index a924cc9790..513a804659 100644 --- a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std-symbols.cpp +++ b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std-symbols.cpp @@ -1,7 +1,12 @@ +#include + +#ifdef _LIBCPP_VERSION + #define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#endif + #include -template __attribute__((visibility("default"))) std::basic_string, std::allocator>::basic_string(); -template __attribute__((visibility("default"))) std::basic_string, std::allocator>::~basic_string() noexcept; -template __attribute__((visibility("default"))) std::basic_string, std::allocator>& std::basic_string, std::allocator>::assign(const std::basic_string, std::allocator>::value_type*); -template __attribute__((visibility("default"))) const std::basic_string, std::allocator>::value_type* std::basic_string, std::allocator>::c_str() const noexcept; +template class std::char_traits; +template class std::allocator; +template class std::basic_string, std::allocator>; diff --git a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std-symbols.cpp b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std-symbols.cpp index 37da19155c..eed819e70f 100644 --- a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std-symbols.cpp +++ b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std-symbols.cpp @@ -1,3 +1,9 @@ +#include + +#ifdef _LIBCPP_VERSION + #define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#endif + #include diff --git a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std-symbols.cpp b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std-symbols.cpp index a924cc9790..513a804659 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std-symbols.cpp +++ b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std-symbols.cpp @@ -1,7 +1,12 @@ +#include + +#ifdef _LIBCPP_VERSION + #define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#endif + #include -template __attribute__((visibility("default"))) std::basic_string, std::allocator>::basic_string(); -template __attribute__((visibility("default"))) std::basic_string, std::allocator>::~basic_string() noexcept; -template __attribute__((visibility("default"))) std::basic_string, std::allocator>& std::basic_string, std::allocator>::assign(const std::basic_string, std::allocator>::value_type*); -template __attribute__((visibility("default"))) const std::basic_string, std::allocator>::value_type* std::basic_string, std::allocator>::c_str() const noexcept; +template class std::char_traits; +template class std::allocator; +template class std::basic_string, std::allocator>; diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std-symbols.cpp b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std-symbols.cpp index 41119deaa9..513a804659 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std-symbols.cpp +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std-symbols.cpp @@ -1,3 +1,9 @@ +#include + +#ifdef _LIBCPP_VERSION + #define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#endif + #include diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std-symbols.cpp b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std-symbols.cpp index 41119deaa9..513a804659 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std-symbols.cpp +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std-symbols.cpp @@ -1,3 +1,9 @@ +#include + +#ifdef _LIBCPP_VERSION + #define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#endif + #include diff --git a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp index 37da19155c..eed819e70f 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp +++ b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp @@ -1,3 +1,9 @@ +#include + +#ifdef _LIBCPP_VERSION + #define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#endif + #include diff --git a/src/Generator/Passes/SymbolsCodeGenerator.cs b/src/Generator/Passes/SymbolsCodeGenerator.cs index 12b723fad6..5bf507bb7a 100644 --- a/src/Generator/Passes/SymbolsCodeGenerator.cs +++ b/src/Generator/Passes/SymbolsCodeGenerator.cs @@ -5,7 +5,6 @@ using CppSharp.AST; using CppSharp.AST.Extensions; using CppSharp.Generators; -using CppSharp.Parser; namespace CppSharp.Passes { @@ -20,6 +19,16 @@ public SymbolsCodeGenerator(BindingContext context, IEnumerable public override void Process() { + WriteLine("#include "); + NewLine(); + + // check if we use the Clang standard C++ lib and if so, + // make sure we export all symbols marked with _LIBCPP_INLINE_VISIBILITY + WriteLine("#ifdef _LIBCPP_VERSION"); + WriteLine(" #define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS"); + WriteLine("#endif"); + NewLine(); + if (TranslationUnit.Module == Options.SystemModule) WriteLine("#include "); else @@ -62,12 +71,8 @@ public override bool VisitFunctionDecl(Function function) private string GetExporting() { - var exporting = string.Empty; - if (Context.ParserOptions.IsMicrosoftAbi) - exporting = "__declspec(dllexport) "; - else if (TargetTriple.IsMacOS(Context.ParserOptions.TargetTriple)) - exporting = "__attribute__((visibility(\"default\"))) "; - return exporting; + return Context.ParserOptions.IsMicrosoftAbi ? + "__declspec(dllexport) " : string.Empty; } private string GetWrapper(Module module) diff --git a/src/Generator/Types/Std/Stdlib.cs b/src/Generator/Types/Std/Stdlib.cs index dfb7fabb62..e89f7e69ae 100644 --- a/src/Generator/Types/Std/Stdlib.cs +++ b/src/Generator/Types/Std/Stdlib.cs @@ -137,7 +137,7 @@ public override void CSharpMarshalToNative(CSharpMarshalContext ctx) ctx.Before.WriteLine($@"{qualifiedBasicString}Extensions.{ assign.Name}({varBasicString}, {ctx.Parameter.Name});"); ctx.Return.Write($"{varBasicString}.{Helpers.InstanceIdentifier}"); - if (!type.IsAddress()) + if (!type.IsPointer()) ctx.Cleanup.WriteLine($"{varBasicString}.Dispose(false);"); } }