From 32da8597118439bc815fe07d26a71f1dda713859 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 --- .../CSharp/i686-apple-darwin12.4.0/Std-symbols.cpp | 9 +++++---- .../CSharp/i686-pc-win32-msvc/Std-symbols.cpp | 2 ++ .../CSharp/x86_64-apple-darwin12.4.0/Std-symbols.cpp | 9 +++++---- .../CSharp/x86_64-linux-gnu-cxx11abi/Std-symbols.cpp | 2 ++ .../Bindings/CSharp/x86_64-linux-gnu/Std-symbols.cpp | 2 ++ .../CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp | 2 ++ src/Generator/Passes/SymbolsCodeGenerator.cs | 12 +++++------- src/Generator/Types/Std/Stdlib.cs | 2 +- 8 files changed, 24 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..372816f0cf 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,8 @@ +#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS + #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..b5cedff851 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,5 @@ +#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS + #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..372816f0cf 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,8 @@ +#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS + #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..372816f0cf 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,5 @@ +#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS + #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..372816f0cf 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,5 @@ +#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS + #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..b5cedff851 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,5 @@ +#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS + #include diff --git a/src/Generator/Passes/SymbolsCodeGenerator.cs b/src/Generator/Passes/SymbolsCodeGenerator.cs index 12b723fad6..f2c689248b 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,9 @@ public SymbolsCodeGenerator(BindingContext context, IEnumerable public override void Process() { + WriteLine("#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS"); + NewLine(); + if (TranslationUnit.Module == Options.SystemModule) WriteLine("#include "); else @@ -62,12 +64,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);"); } }