Skip to content

Commit

Permalink
Exported all additional symbols on macOS.
Browse files Browse the repository at this point in the history
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 <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Jan 4, 2019
1 parent e5aaa2e commit 32da859
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS

#include <string>


template __attribute__((visibility("default"))) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string();
template __attribute__((visibility("default"))) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() noexcept;
template __attribute__((visibility("default"))) std::basic_string<char, std::char_traits<char>, std::allocator<char>>& std::basic_string<char, std::char_traits<char>, std::allocator<char>>::assign(const std::basic_string<char, std::char_traits<char>, std::allocator<char>>::value_type*);
template __attribute__((visibility("default"))) const std::basic_string<char, std::char_traits<char>, std::allocator<char>>::value_type* std::basic_string<char, std::char_traits<char>, std::allocator<char>>::c_str() const noexcept;
template class std::char_traits<char>;
template class std::allocator<char>;
template class std::basic_string<char, std::char_traits<char>, std::allocator<char>>;
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS

#include <string>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS

#include <string>


template __attribute__((visibility("default"))) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string();
template __attribute__((visibility("default"))) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() noexcept;
template __attribute__((visibility("default"))) std::basic_string<char, std::char_traits<char>, std::allocator<char>>& std::basic_string<char, std::char_traits<char>, std::allocator<char>>::assign(const std::basic_string<char, std::char_traits<char>, std::allocator<char>>::value_type*);
template __attribute__((visibility("default"))) const std::basic_string<char, std::char_traits<char>, std::allocator<char>>::value_type* std::basic_string<char, std::char_traits<char>, std::allocator<char>>::c_str() const noexcept;
template class std::char_traits<char>;
template class std::allocator<char>;
template class std::basic_string<char, std::char_traits<char>, std::allocator<char>>;
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS

#include <string>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS

#include <string>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS

#include <string>


Expand Down
12 changes: 5 additions & 7 deletions src/Generator/Passes/SymbolsCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
using CppSharp.Parser;

namespace CppSharp.Passes
{
Expand All @@ -20,6 +19,9 @@ public SymbolsCodeGenerator(BindingContext context, IEnumerable<TranslationUnit>

public override void Process()
{
WriteLine("#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
NewLine();

if (TranslationUnit.Module == Options.SystemModule)
WriteLine("#include <string>");
else
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Types/Std/Stdlib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);");
}
}
Expand Down

0 comments on commit 32da859

Please sign in to comment.