Skip to content

[lldb] Add ability to detect darwin host linker version to xfail tests #83941

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

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

bulbazord
Copy link
Member

When Apple released its new linker, it had a subtle bug that caused LLDB's TLS tests to fail. Unfortunately this means that TLS tests are not going to work on machines that have affected versions of the linker, so we should annotate the tests so that they only work when we are confident the linker has the required fix.

I'm not completely satisfied with this implementation. That being said, I believe that adding suport for linker versions in general is a non-trivial change that would require far more thought. There are a few challenges involved:

  • LLDB's testing infra takes an argument to change the compiler, but there's no way to switch out the linker.
  • There's no standard way to ask a compiler what linker it will use.
  • There's no standard way to ask a linker what its version is. Many platforms have the same name for their linker (ld).
  • Some platforms automatically switch out the linker underneath you. We do this for Windows tests (where we use LLD no matter what).

Given that this is affecting the tests on our CI, I think this is an acceptable solution in the interim.

@bulbazord bulbazord requested a review from JDevlieghere as a code owner March 5, 2024 01:44
@llvmbot llvmbot added the lldb label Mar 5, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 5, 2024

@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)

Changes

When Apple released its new linker, it had a subtle bug that caused LLDB's TLS tests to fail. Unfortunately this means that TLS tests are not going to work on machines that have affected versions of the linker, so we should annotate the tests so that they only work when we are confident the linker has the required fix.

I'm not completely satisfied with this implementation. That being said, I believe that adding suport for linker versions in general is a non-trivial change that would require far more thought. There are a few challenges involved:

  • LLDB's testing infra takes an argument to change the compiler, but there's no way to switch out the linker.
  • There's no standard way to ask a compiler what linker it will use.
  • There's no standard way to ask a linker what its version is. Many platforms have the same name for their linker (ld).
  • Some platforms automatically switch out the linker underneath you. We do this for Windows tests (where we use LLD no matter what).

Given that this is affecting the tests on our CI, I think this is an acceptable solution in the interim.


Full diff: https://github.com/llvm/llvm-project/pull/83941.diff

2 Files Affected:

  • (modified) lldb/packages/Python/lldbsuite/test/lldbplatformutil.py (+40)
  • (modified) lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py (+1)
diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index c4d063d3cc77ef..acb1a801e7f638 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -3,6 +3,7 @@
 
 # System modules
 import itertools
+import json
 import re
 import subprocess
 import sys
@@ -16,6 +17,7 @@
 from . import lldbtest_config
 import lldbsuite.test.lldbplatform as lldbplatform
 from lldbsuite.test.builders import get_builder
+from lldbsuite.test.lldbutil import is_exe
 
 
 def check_first_register_readable(test_case):
@@ -333,3 +335,41 @@ def expectedCompiler(compilers):
             return True
 
     return False
+
+
+# This is a helper function to determine if a specific version of Xcode's linker
+# contains a TLS bug. We want to skip TLS tests if they contain this bug, but
+# adding a linker/linker_version conditions to a decorator is challenging due to
+# the number of ways linkers can enter the build process.
+def darwinLinkerHasTLSBug():
+    """Returns true iff a test is running on a darwin platform and the host linker is between versions 1000 and 1109."""
+    darwin_platforms = lldbplatform.translate(lldbplatform.darwin_all)
+    if getPlatform() not in darwin_platforms:
+        return False
+
+    linker_path = (
+        subprocess.check_output(["xcrun", "--find", "ld"]).rstrip().decode("utf-8")
+    )
+    if not is_exe(linker_path):
+        return False
+
+    raw_linker_info = (
+        subprocess.check_output([linker_path, "-version_details"])
+        .rstrip()
+        .decode("utf-8")
+    )
+    parsed_linker_info = json.loads(raw_linker_info)
+    if "version" not in parsed_linker_info:
+        return False
+
+    raw_version = parsed_linker_info["version"]
+    version = None
+    try:
+        version = int(raw_version)
+    except:
+        return False
+
+    if version is None:
+        return False
+
+    return 1000 <= version and version <= 1109
diff --git a/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py b/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
index dfe29b451df0a6..526e49b68162f3 100644
--- a/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
+++ b/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
@@ -40,6 +40,7 @@ def setUp(self):
     @skipIfWindows
     @skipIf(oslist=["linux"], archs=["arm", "aarch64"])
     @skipIf(oslist=no_match([lldbplatformutil.getDarwinOSTriples(), "linux"]))
+    @expectedFailureIf(lldbplatformutil.darwinLinkerHasTLSBug())
     def test(self):
         """Test thread-local storage."""
         self.build()

@bulbazord bulbazord requested a review from adrian-prantl March 5, 2024 01:46
@kastiglione
Copy link
Contributor

We're going to need this logic in a couple from shell tests too.

Should we:

  1. Duplicate the logic into lit.cfg.py?
  2. Import lldbplatformutil.py into lit.cfg.py? (are there any python structure/layout issues that would complicate this?)
  3. Put the logic in an independent location and have both lit.cfg.py and lldbplatformutil.py import that?

@kastiglione
Copy link
Contributor

kastiglione commented Mar 6, 2024

To start with option #​1, I created #84246

@bulbazord
Copy link
Member Author

To start with option #​1, I created #84246

Just took a look, thanks for taking care of that. I'll address your feedback (or just look at what you did in the other PR) and update this tomorrow.

kastiglione added a commit that referenced this pull request Mar 7, 2024
Equivalent to the changes made in #83941, 
except to support shell tests.
@bulbazord bulbazord force-pushed the workaround-linker-tls-bug branch from 480252e to a72d9d2 Compare March 7, 2024 21:08
Copy link

github-actions bot commented Mar 7, 2024

✅ With the latest revision this PR passed the Python code formatter.

When Apple released its new linker, it had a subtle bug that caused
LLDB's TLS tests to fail. Unfortunately this means that TLS tests
are not going to work on machines that have affected versions of the
linker, so we should annotate the tests so that they only work when we
are confident the linker has the required fix.

I'm not completely satisfied with this implementation. That being said,
I believe that adding suport for linker versions in general is a
non-trivial change that would require far more thought. There are a few
challenges involved:
- LLDB's testing infra takes an argument to change the compiler, but
  there's no way to switch out the linker.
- There's no standard way to ask a compiler what linker it will use.
- There's no standard way to ask a linker what its version is. Many
  platforms have the same name for their linker (ld).
- Some platforms automatically switch out the linker underneath you. We
  do this for Windows tests (where we use LLD no matter what).

Given that this is affecting the tests on our CI, I think this is an
acceptable solution in the interim.
@bulbazord bulbazord force-pushed the workaround-linker-tls-bug branch from a72d9d2 to 89d1c20 Compare March 7, 2024 21:11
Copy link
Contributor

@kastiglione kastiglione left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@bulbazord bulbazord merged commit d93a126 into llvm:main Mar 7, 2024
@bulbazord bulbazord deleted the workaround-linker-tls-bug branch March 7, 2024 23:04
kastiglione added a commit to swiftlang/llvm-project that referenced this pull request Apr 24, 2024
Equivalent to the changes made in llvm#83941,
except to support shell tests.

(cherry picked from commit ecf7db8)
kastiglione pushed a commit to swiftlang/llvm-project that referenced this pull request Apr 24, 2024
llvm#83941)

When Apple released its new linker, it had a subtle bug that caused
LLDB's TLS tests to fail. Unfortunately this means that TLS tests are
not going to work on machines that have affected versions of the linker,
so we should annotate the tests so that they only work when we are
confident the linker has the required fix.

I'm not completely satisfied with this implementation. That being said,
I believe that adding suport for linker versions in general is a
non-trivial change that would require far more thought. There are a few
challenges involved:
- LLDB's testing infra takes an argument to change the compiler, but
there's no way to switch out the linker.
- There's no standard way to ask a compiler what linker it will use.
- There's no standard way to ask a linker what its version is. Many
platforms have the same name for their linker (ld).
- Some platforms automatically switch out the linker underneath you. We
do this for Windows tests (where we use LLD no matter what).

Given that this is affecting the tests on our CI, I think this is an
acceptable solution in the interim.

(cherry picked from commit d93a126)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants