Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on startup if bad glibc version is detected. #2998

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Robust.Client/GameController/GameController.Standalone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static void Start(string[] args, GameControllerOptions options, bool cont
throw new InvalidOperationException("Cannot start twice!");
}

GlibcBug.Check();

_hasStarted = true;

if (CommandLineArgs.TryParse(args, out var parsed))
Expand Down
3 changes: 3 additions & 0 deletions Robust.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Robust.Shared.Log;
using Robust.Shared.Asynchronous;
using Robust.Shared.Reflection;
using Robust.Shared.Utility;

namespace Robust.Server
{
Expand All @@ -31,6 +32,8 @@ internal static void Start(string[] args, ServerOptions options, bool contentSta
throw new InvalidOperationException("Cannot start twice!");
}

GlibcBug.Check();

_hasStarted = true;

if (!CommandLineArgs.TryParse(args, out var parsed))
Expand Down
40 changes: 40 additions & 0 deletions Robust.Shared/Utility/GlibcBug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Runtime.InteropServices;
using C = System.Console;

namespace Robust.Shared.Utility;

internal static unsafe class GlibcBug
{
/// <summary>
/// Check for the glibc 2.35 DSO bug and log a warning if necessary.
/// </summary>
public static void Check()
{
if (!OperatingSystem.IsLinux())
return;

try
{
var versionString = Marshal.PtrToStringUTF8((IntPtr) gnu_get_libc_version());
var version = Version.Parse(versionString!);
var badVersion = new Version(2, 35);
if (version >= badVersion)
{
C.ForegroundColor = ConsoleColor.Yellow;
C.WriteLine($"!!!WARNING!!!: glibc {badVersion} or higher detected (you have {version}).");
C.WriteLine("If anything misbehaves (weird native crashes, library load failures), try setting GLIBC_TUNABLES=glibc.rtld.dynamic_sort=1 as environment variable.");
C.WriteLine("This is a severe glibc bug introduced in glibc 2.35. See https://github.com/space-wizards/RobustToolbox/issues/2563 for details");
C.ResetColor();
}
}
catch
{
// Couldn't figure out glibc version, whatever.
// Hell maybe you're not even using glibc.
}
}

[DllImport("libc.so.6")]
private static extern byte* gnu_get_libc_version();
}