Fixes, tweaks and improvements for Linux support

This commit is contained in:
Wojtek Figat
2021-02-16 20:21:23 +01:00
parent 6fd1580d67
commit bcc3b2bd59
3 changed files with 35 additions and 29 deletions

View File

@@ -2140,7 +2140,12 @@ int32 LinuxPlatform::RunProcess(const StringView& cmdLine, const StringView& wor
void* LinuxPlatform::LoadLibrary(const Char* filename)
{
const StringAsANSI<> filenameANSI(filename);
return dlopen(filenameANSI.Get(), RTLD_LAZY);
void* result = dlopen(filenameANSI.Get(), RTLD_LAZY | RTLD_LOCAL);
if (!result)
{
LOG(Error, "Failed to load {0} because {1}", filename, String(dlerror()));
}
return result;
}
void LinuxPlatform::FreeLibrary(void* handle)

View File

@@ -43,8 +43,22 @@ namespace Flax.Build.Platforms
{
base.SetupCompileCppFilesArgs(graph, options, args, outputPath);
// Hide all symbols by default
args.Add("-fvisibility-inlines-hidden");
args.Add("-fvisibility-ms-compat");
args.Add(string.Format("-target {0}", ArchitectureName));
args.Add(string.Format("--sysroot=\"{0}\"", ToolsetRoot.Replace('\\', '/')));
if (Architecture == TargetArchitecture.x64)
{
args.Add("-mssse3");
}
if (options.Target.OutputType == TargetOutputType.Library)
{
args.Add("-fPIC");
}
}
/// <inheritdoc />
@@ -53,8 +67,6 @@ namespace Flax.Build.Platforms
base.SetupLinkFilesArgs(graph, options, args, outputFilePath);
args.Add("-Wl,-rpath,\"\\$ORIGIN\"");
// Speed up build
//args.Add("-Wl,--as-needed");
args.Add("-Wl,--hash-style=gnu");
//args.Add("-Wl,--build-id");
@@ -62,7 +74,7 @@ namespace Flax.Build.Platforms
if (options.LinkEnv.Output == LinkerOutput.SharedLibrary)
{
args.Add("-shared");
args.Add(string.Format("-soname=\"{0}\"", Path.GetFileNameWithoutExtension(outputFilePath)));
args.Add(string.Format("-Wl,-soname=\"{0}\"", Path.GetFileNameWithoutExtension(outputFilePath)));
}
args.Add(string.Format("-target {0}", ArchitectureName));

View File

@@ -255,12 +255,8 @@ namespace Flax.Build.Platforms
var commonArgs = new List<string>();
SetupCompileCppFilesArgs(graph, options, commonArgs, outputPath);
{
// Don't link, only compile code
commonArgs.Add("-c");
commonArgs.Add("-pipe");
// C++ compile flags
commonArgs.Add("-x");
commonArgs.Add("c++");
commonArgs.Add("-std=c++14");
@@ -280,25 +276,6 @@ namespace Flax.Build.Platforms
if (compileEnvironment.TreatWarningsAsErrors)
commonArgs.Add("-Wall -Werror");
/*
if (ShouldUseLibcxx(CompileEnvironment.Architecture))
{
commonArgs.Add("-nostdinc++");
commonArgs.Add("-I" + "ThirdParty/Linux/LibCxx/include/");
commonArgs.Add("-I" + "ThirdParty/Linux/LibCxx/include/c++/v1");
}
*/
/*
if (Options.HasFlag(LinuxToolChainOptions.EnableAddressSanitizer))
commonArgs.Add("-fsanitize=address");
if (Options.HasFlag(LinuxToolChainOptions.EnableThreadSanitizer))
commonArgs.Add("-fsanitize=thread");
if (Options.HasFlag(LinuxToolChainOptions.EnableUndefinedBehaviorSanitizer))
commonArgs.Add("-fsanitize=undefined");
*/
// TODO: compileEnvironment.IntrinsicFunctions
// TODO: compileEnvironment.FunctionLevelLinking
// TODO: compileEnvironment.FavorSizeOrSpeed
@@ -469,12 +446,18 @@ namespace Flax.Build.Platforms
foreach (var library in linkEnvironment.InputLibraries)
{
var dir = Path.GetDirectoryName(library);
var ext = Path.GetExtension(library);
if (string.IsNullOrEmpty(dir))
{
args.Add(string.Format("\"-l{0}\"", library));
}
else if (library.EndsWith(".so"))
else if (string.IsNullOrEmpty(ext))
{
// Skip executable
}
else if (ext == ".so")
{
// Link against dynamic library
task.PrerequisiteFiles.Add(library);
libraryPaths.Add(dir);
args.Add(string.Format("\"-l{0}\"", GetLibName(library)));
@@ -488,12 +471,18 @@ namespace Flax.Build.Platforms
foreach (var library in options.Libraries)
{
var dir = Path.GetDirectoryName(library);
var ext = Path.GetExtension(library);
if (string.IsNullOrEmpty(dir))
{
args.Add(string.Format("\"-l{0}\"", library));
}
else if (library.EndsWith(".so"))
else if (string.IsNullOrEmpty(ext))
{
// Skip executable
}
else if (ext == ".so")
{
// Link against dynamic library
task.PrerequisiteFiles.Add(library);
libraryPaths.Add(dir);
args.Add(string.Format("\"-l{0}\"", GetLibName(library)));