Repository: godot
Issue: Building Mono version with LLVM-MinGW crashed at linking stage with LTO enabled
Labels: bug,platform:windows,topic:buildsystem,topic:dotnet

**Godot version:**
[a8cf045](https://github.com/godotengine/godot/commit/a8cf045fd0c17dab73f648d0815d22677a252c77)


**OS/device including version:**
Windows 10 / Nvidia GeForce GTX 1080 Ti (457.30) / Vulkan
[Compiler used](https://github.com/mstorsjo/llvm-mingw)

**Issue description:**
Building Mono version with [LLVM-MinGW](https://github.com/mstorsjo/llvm-mingw) crashes at linking stage with LTO / ThinLTO enabled.
<details>
<summary>Error:</summary>

>[100%] Linking Program        ==> bin\godot.windows.tools.64.mono.exe
=====
b'lld-link: error: undefined symbol: thread-local initialization routine for GDMonoUtils::current_invoke_count\r\n>>> referenced by modules\\mono\\csharp_script.cpp\r\n>>>               libmodule_mono.windows.tools.64.a(csharp_script.windows.tools.64.o)\r\n>>> referenced by modules\\mono\\mono_gd\\gd_mono_marshal.cpp\r\n>>>               libmodule_mono.windows.tools.64.a(gd_mono_marshal.windows.tools.64.o)\r\n>>> referenced by modules\\mono\\signal_awaiter_utils.cpp\r\n>>>               libmodule_mono.windows.tools.64.a(signal_awaiter_utils.windows.tools.64.o)\r\nclang-11: error: linker command failed with exit code 1 (use -v to see invocation)\r\n'
=====
scons: *** [bin\godot.windows.tools.64.mono.exe] Error 1
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\GLTFLight.cs(163,23): warning CS0108: 'GLTFLight.GetType()' hides inherited member 'object.GetType()'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\Button.cs(81,38): warning CS0108: 'Button.TextDirection' hides inherited member 'Control.TextDirection'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\ArrayMesh.cs(89,36): warning CS0108: 'ArrayMesh.BlendShapeMode' hides inherited member 'Mesh.BlendShapeMode'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\Label.cs(77,38): warning CS0108: 'Label.TextDirection' hides inherited member 'Control.TextDirection'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\TextEdit.cs(188,38): warning CS0108: 'TextEdit.TextDirection' hides inherited member 'Control.TextDirection'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\RichTextLabel.cs(340,38): warning CS0108: 'RichTextLabel.TextDirection' hides inherited member 'Control.TextDirection'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\LineEdit.cs(428,38): warning CS0108: 'LineEdit.TextDirection' hides inherited member 'Control.TextDirection'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\GraphNode.cs(54,38): warning CS0108: 'GraphNode.TextDirection' hides inherited member 'Control.TextDirection'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\LinkButton.cs(53,38): warning CS0108: 'LinkButton.TextDirection' hides inherited member 'Control.TextDirection'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\GLTFAccessor.cs(351,20): warning CS0108: 'GLTFAccessor.GetType()' hides inherited member 'object.GetType()'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Core\StringExtensions.cs(452,26): warning CS1572: XML comment has a param tag for 'bytes', but there is no parameter by that name [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Core\StringExtensions.cs(454,52): warning CS1573: Parameter 'b' has no matching param tag in the XML comment for 'StringExtensions.HexEncode(byte)' (but other parameters do) [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\ImageTexture.cs(30,359): warning CS1574: XML comment has cref attribute 'EditorImportPlugin' that could not be resolved [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\Node3D.cs(188,101): warning CS1574: XML comment has cref attribute 'EditorNode3DGizmo' that could not be resolved [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
E:\godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\ResourceFormatLoader.cs(12,52): warning CS1574: XML comment has cref attribute 'EditorImportPlugin' that could not be resolved [E:\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
  GodotSharp -> E:\godot\modules\mono\glue\GodotSharp\GodotSharp\bin\Debug\GodotSharp.dll
E:\godot\modules\mono\glue\GodotSharp\GodotSharpEditor\Generated\GodotObjects\EditorNode3DGizmoPlugin.cs(74,31): warning CS0108: 'EditorNode3DGizmoPlugin.GetName()' hides inherited member 'Resource.GetName()'. Use the new keyword if hiding was intended. [E:\godot\modules\mono\glue\GodotSharp\GodotSharpEditor\GodotSharpEditor.csproj]
  GodotSharpEditor -> E:\godot\modules\mono\glue\GodotSharp\GodotSharpEditor\bin\Debug\GodotSharpEditor.dll
scons: building terminated because of errors.

</details>

Without LTO / ThinLTO engine compiles just fine, as well as without Mono enabled.




**Steps to reproduce:**
Compile engine with following parameters:
`scons -j24 use_mingw=yes use_llvm=yes use_lto=yes use_thinlto=yes target=release_debug tools=yes module_mono_enabled=yes`


**Minimal reproduction project:**
N/A