Closed vitek-karas closed 1 year ago
Tagging subscribers to this area: @vitek-karas, @agocke See info in area-owners.md if you want to be subscribed.
Hello.
This behavior should be noted for all who test functional that use 'libhostpolicy.so'. For example if you use Google Test, that configured to use 'pthread', that is by default at current version that located at Ubuntu repository, you will success call that functional.
However at deploy version, that usually build without test libraries, you will have a problem described here.
Let see a quick sample that get context and read the properties of host:
extern "C" {
#include "host_fxr.h"
};
#include <gtest/gtest.h>
#include <string>
#include <cstdlib>
#include <cstdint>
#include <fstream>
#include <ostream>
#include <iostream>
#define HOST_FX_RESOLVER_NON_SUCCESS_(RESULT) ((RESULT) < static_cast<int32_t>(host_fxr_Success) || static_cast<int32_t>(host_fxr_Success_DifferentRuntimeProperties) < (RESULT))
std::string create_json_config(const char* tfm, const char* framework_version)
{
std::string content;
content += "{\n";
content += " \"runtimeOptions\": {\n";
content += " \"tfm\": \"";
content += tfm;
content += "\",\n";
content += " \"rollForward\": \"LatestMinor\",\n";
content += " \"framework\": {\n";
content += " \"name\": \"Microsoft.NETCore.App\",\n";
content += " \"version\": \"";
content += framework_version;
content += "\"\n";
content += " }\n";
content += " }\n";
content += "}";
return content;
}
#if defined(_MSC_VER)
GTEST_API_ int wmain(int argc, wchar_t** argv)
#else
GTEST_API_ int main(int argc, char** argv)
#endif
{
testing::InitGoogleTest(&argc, argv);
if (argc < 2)
{
std::cout << "No input data." << std::endl;
return EXIT_FAILURE;
}
{
const auto json_config = create_json_config("netcoreapp5.0", "5.0.0");//"netcoreapp3.1", "3.1.0"
std::ofstream json_config_file("1.json");
json_config_file << json_config;
json_config_file.close();
}
uint8_t ptr_to_host_fxr_object[UINT8_MAX];
const type_of_element* path_to_host_fxr = reinterpret_cast<const type_of_element*>(argv[1]);
#if defined(_MSC_VER)
const type_of_element* runtime_config_path = L"1.json";
#else
const type_of_element* runtime_config_path = reinterpret_cast<const type_of_element*>("1.json");
#endif
if (!host_fx_resolver_load(path_to_host_fxr, ptr_to_host_fxr_object, sizeof(ptr_to_host_fxr_object)))
{
std::cerr << "Failed to load object from '" << path_to_host_fxr << "' " << __LINE__ << std::endl;
return EXIT_FAILURE;
}
const auto function_name = reinterpret_cast<const uint8_t*>("hostfxr_initialize_for_runtime_config");
const uint8_t function_name_length = 37;
if (!host_fx_resolver_is_function_exists(ptr_to_host_fxr_object, function_name, function_name_length))
{
host_fx_resolver_unload(ptr_to_host_fxr_object);
std::cerr << "Host '" << path_to_host_fxr << "' do not have '" << function_name << "' function at line " << __LINE__ << std::endl;
return EXIT_FAILURE;
}
type_of_element* path_to_assembly = nullptr;
type_of_element* path_to_dot_net_root = nullptr;
void* context;
//
int32_t result = host_fxr_initialize_for_runtime_config_parameters_in_parts(ptr_to_host_fxr_object,
runtime_config_path, path_to_assembly, path_to_dot_net_root, &context);
if (HOST_FX_RESOLVER_NON_SUCCESS_(result))
{
host_fx_resolver_unload(ptr_to_host_fxr_object);
std::cerr << "Failed to call '" << function_name << "' function " << result << " at line " << __LINE__ << std::endl;
return EXIT_FAILURE;
}
size_t count = 0;
type_of_element** keys = NULL;
type_of_element** values = NULL;
//
result = host_fxr_get_runtime_properties(ptr_to_host_fxr_object, context, &count, keys, values);
if (static_cast<int32_t>(host_fxr_HostApiBufferTooSmall) != result)
{
result = host_fxr_close(ptr_to_host_fxr_object, context);
if (HOST_FX_RESOLVER_NON_SUCCESS_(result))
{
host_fx_resolver_unload(ptr_to_host_fxr_object);
std::cerr << "Failed to call 'close' function " << result << " at line " << __LINE__ << std::endl;
}
host_fx_resolver_unload(ptr_to_host_fxr_object);
std::cerr << "Failed to call 'host_fxr_get_runtime_properties' function " << result << " at line " << __LINE__ << std::endl;
return EXIT_FAILURE;
}
std::string data(2 * count * sizeof(type_of_element*), '\0');
keys = reinterpret_cast<type_of_element**>(&data[0]);
values = reinterpret_cast<type_of_element**>(&data[0] + count * sizeof(type_of_element*));
//
result = host_fxr_get_runtime_properties(ptr_to_host_fxr_object, context, &count, keys, values);
if (HOST_FX_RESOLVER_NON_SUCCESS_(result))
{
result = host_fxr_close(ptr_to_host_fxr_object, context);
if (HOST_FX_RESOLVER_NON_SUCCESS_(result))
{
host_fx_resolver_unload(ptr_to_host_fxr_object);
std::cerr << "Failed to call 'close' function " << result << " at line " << __LINE__ << std::endl;
}
host_fx_resolver_unload(ptr_to_host_fxr_object);
std::cerr << "Failed to call 'host_fxr_get_runtime_properties' function " << result << " at line " << __LINE__ << std::endl;
return EXIT_FAILURE;
}
#if defined(_MSC_VER)
std::wstring key(INT8_MAX, L'\0');
std::wstring value(INT16_MAX, L'\0');
#else
std::string key(INT8_MAX, '\0');
std::string value(INT16_MAX, '\0');
#endif
for (size_t i = 0; i < count; ++i)
{
key.clear();
value.clear();
#if defined(_MSC_VER)
key += keys[i];
value += values[i];
//
std::wcout << i << std::endl <<
L"PROPERTY NAME: '" << key << L"'" << std::endl <<
L"PROPERTY VALUE: '" << value << L"'" << std::endl;
#else
key += reinterpret_cast<const char*>(keys[i]);
value += reinterpret_cast<const char*>(values[i]);
//
std::cout << i << std::endl <<
"PROPERTY NAME: '" << key << "'" << std::endl <<
"PROPERTY VALUE: '" << value << "'" << std::endl;
#endif
}
result = host_fxr_close(ptr_to_host_fxr_object, context);
if (HOST_FX_RESOLVER_NON_SUCCESS_(result))
{
host_fx_resolver_unload(ptr_to_host_fxr_object);
std::cerr << "Failed to call 'close' function " << result << " at line " << __LINE__ << std::endl;
return EXIT_FAILURE;
}
host_fx_resolver_unload(ptr_to_host_fxr_object);
return EXIT_SUCCESS;
}
If you will remove call of 'testing::InitGoogleTest(&argc, argv);' function, code will fail and you got
root@7c078117f286:# ./tests /usr/share/dotnet/host/fxr/5.0.3/libhostfxr.so Failed to load /usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/libhostpolicy.so, error: /usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/libhostpolicy.so: undefined symbol: pthread_create An error occurred while loading required library libhostpolicy.so from [/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3] Failed to initialize context for config: 1.json. Error code: 0x80008082 Failed to call 'hostfxr_initialize_for_runtime_config' function -2147450750 at line 96
However without that remove, code success output required data:
root@7c078117f286:# ./tests /usr/share/dotnet/host/fxr/5.0.3/libhostfxr.so 0 PROPERTY NAME: 'RUNTIME_IDENTIFIER' PROPERTY VALUE: 'ubuntu.20.04-x64' 1 PROPERTY NAME: 'FX_DEPS_FILE' PROPERTY VALUE: '/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/Microsoft.NETCore.App.deps.json' 2 PROPERTY NAME: 'APP_CONTEXT_DEPS_FILES' PROPERTY VALUE: '/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/Microsoft.NETCore.App.deps.json' 3 PROPERTY NAME: 'APP_CONTEXT_BASE_DIRECTORY' PROPERTY VALUE: '' 4 PROPERTY NAME: 'PLATFORM_RESOURCE_ROOTS' PROPERTY VALUE: ':' 5 PROPERTY NAME: 'PROBING_DIRECTORIES' PROPERTY VALUE: '' 6 PROPERTY NAME: 'NATIVE_DLL_SEARCH_DIRECTORIES' PROPERTY VALUE: ':/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3:' 7 PROPERTY NAME: 'TRUSTED_PLATFORM_ASSEMBLIES' PROPERTY VALUE: '/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/netstandard.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/WindowsBase.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Xml.XmlDocument.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Xml.XPath.XDocument.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Xml.XDocument.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Xml.ReaderWriter.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Web.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Web.HttpUtility.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Xml.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.ValueTuple.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Transactions.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Xml.XmlSerializer.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Transactions.Local.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Threading.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Threading.Thread.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Threading.Tasks.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Threading.Tasks.Extensions.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Threading.ThreadPool.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Threading.Tasks.Dataflow.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Text.RegularExpressions.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Text.Json.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Text.Encoding.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Text.Encoding.Extensions.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Text.Encoding.CodePages.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Threading.Timer.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Threading.Tasks.Parallel.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Linq.Parallel.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Diagnostics.DiagnosticSource.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Numerics.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.FileSystem.Primitives.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.Compression.FileSystem.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.Compression.Brotli.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Diagnostics.Process.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Globalization.Calendars.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.FileSystem.DriveInfo.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.NameResolution.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Formats.Asn1.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Dynamic.Runtime.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.FileSystem.AccessControl.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Drawing.Primitives.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.ComponentModel.DataAnnotations.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Linq.Queryable.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Linq.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.Serialization.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.MemoryMappedFiles.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Diagnostics.TraceSource.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.InteropServices.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/Microsoft.CSharp.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Globalization.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.ComponentModel.Annotations.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.Serialization.Primitives.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.FileSystem.Watcher.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Diagnostics.Tracing.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.ServicePoint.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Collections.Concurrent.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Collections.Immutable.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Drawing.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Resources.ResourceManager.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Diagnostics.Debug.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Xml.Linq.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Collections.Specialized.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Collections.NonGeneric.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Data.Common.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.AppContext.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.ServiceModel.Web.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.UnmanagedMemoryStream.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/Microsoft.Win32.Registry.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Buffers.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/Microsoft.Win32.Primitives.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.Compression.ZipFile.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Core.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/Microsoft.VisualBasic.Core.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Private.Uri.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Windows.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.FileSystem.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.Pipes.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.Http.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Reflection.Emit.Lightweight.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Threading.Overlapped.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Collections.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Diagnostics.StackTrace.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.Serialization.Formatters.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.Compression.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Diagnostics.TextWriterTraceListener.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.ComponentModel.TypeConverter.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.ComponentModel.EventBasedAsync.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.ComponentModel.Primitives.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Data.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/mscorlib.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Configuration.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.AccessControl.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.Cryptography.Cng.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/Microsoft.VisualBasic.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.ComponentModel.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Globalization.Extensions.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Private.DataContractSerialization.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Diagnostics.Contracts.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.Handles.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Console.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Diagnostics.Tools.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.InteropServices.RuntimeInformation.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Data.DataSetExtensions.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Diagnostics.FileVersionInfo.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.Serialization.Json.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Memory.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.Http.Json.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Reflection.DispatchProxy.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.HttpListener.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.Ping.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.Mail.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.NetworkInformation.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.Requests.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.Primitives.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.Security.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.Sockets.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.WebClient.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.WebHeaderCollection.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.WebSockets.Client.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.WebSockets.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Numerics.Vectors.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Private.Xml.Linq.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Private.Xml.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Threading.Channels.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Reflection.Emit.ILGeneration.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.CompilerServices.VisualC.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.Intrinsics.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Reflection.Emit.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.ServiceProcess.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Reflection.Extensions.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Reflection.Metadata.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Reflection.TypeExtensions.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.CompilerServices.Unsafe.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Text.Encodings.Web.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Net.WebProxy.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Reflection.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Resources.Reader.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Linq.Expressions.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Resources.Writer.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.Extensions.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Xml.XPath.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.Cryptography.OpenSsl.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.Loader.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.Numerics.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.Pipes.AccessControl.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.Serialization.Xml.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Xml.Serialization.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.Claims.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.Cryptography.Algorithms.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.Cryptography.Csp.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.IO.IsolatedStorage.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.Cryptography.Encoding.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.Cryptography.Primitives.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.Principal.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.Cryptography.X509Certificates.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.Principal.Windows.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.SecureString.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.ObjectModel.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Reflection.Primitives.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Security.dll:/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.3/System.Private.CoreLib.dll'
Full source code can be found here. Two runs of GitHub actions, with different results, can be view here: FAILED (no call InitGoogleTest) SUCCESS (call InitGoogleTest) (commit that made this possible).
That also can be used as workaround way, of course do not use Google Test library, but by directly loading of 'pthread' library into process that required to use 'libhostpolicy.so'.
Cheers.
Hello @vitek-karas
Hope you are doing well. I wanted to know if a solution has been made available for this? Or if you can suggest how to work our way around this. I have run into the same problem on CentOS7
with .net core 5.0
. I have tried loading the pthread
library using dlopen
but it doesn't solve my problem. If possible, it would be great if you can share some code reference on how to navigate my way around this.
Please let me know if you need any specific details from my side.
Regards Abhishek
I don't have an answer right now, nobody from our side actually looked into this yet. @VSadov might have some additional ideas.
@vitek-karas @agocke @elinor-fung Users of DNNE are hitting this issue now. See this issue, linked above. I was able to fix it by linking against the pthreads lib, but only if the native lib exporting the .NET function was also passed to the linker. If users are using dlopen
to dynamically reference and load the native library, finding the export via dlsym
, passing pthread
to the linker does nothing because it isn't being used in any of the translation units and is thus not linked against.
https://github.com/dotnet/runtime/issues/86940 also mentiond potential need for libdl.so
@elinor-fung could you please look what it would take to fix this? Maybe it's simple enough...
Why can't I directly add a -lpthread -ldl @vitek-karas
Why can't I directly add a -lpthread -ldl
To what - to the build of hostfxr
? It's very possible that it's that simple, I just don't trust my very limited knowledge of the linux build in runtime repo to answer that - hopefully @elinor-fung will be able to do so.
Interestingly, the deb packaging build emits warnings about this exact issue, but generally we don't try to keep that portion of the build warning-clean. Probably would have caught this earlier if we used more standard tooling and had better validation of that space.
Huh - that is good to know. Also lets me confirm that the warning no longer shows up in https://github.com/dotnet/runtime/pull/87042.
On Linux in .NET 5
libhostpolicy.so
requires symbolpthread_create
, but it doesn't include it, so if used the calling code must provide this dependency. This is effectively breaking change from .NET Core 3.1 wherelibhostpolicy.do
didn't require this symbol.Repro: Get a local close of the HostingWithHostFxr sample. It targets 3.1 - so running
dotnet run
from the root of the sample should just work (prints out some sample output). Retargetting the projects to .NET 5 (modifyDotNetLib.csproj
andNativeHost.csproj
to targetnet5.0
) and runningdotnet run
again (using .NET 5 RC2) will fail with:Looking into the make files the
apphost
will be built with-pthread
but no library will be built that way. So any hosting which is not going throughapphost
(ordotnet
) will potentially run into this problem. https://github.com/dotnet/runtime/blob/f1e131a4bef5bd5373a3dab65523851b54a94306/src/installer/corehost/cli/common.cmake#L46-L53If we have a hard dependency on pthread from hostpolicy, then hostpolicy should be built with it.