Skip to content

Commit 480252e

Browse files
committed
[lldb] Add ability to detect darwin host linker version to xfail tests
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.
1 parent ac783ad commit 480252e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lldb/packages/Python/lldbsuite/test/lldbplatformutil.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
# System modules
55
import itertools
6+
import json
67
import re
78
import subprocess
89
import sys
@@ -16,6 +17,7 @@
1617
from . import lldbtest_config
1718
import lldbsuite.test.lldbplatform as lldbplatform
1819
from lldbsuite.test.builders import get_builder
20+
from lldbsuite.test.lldbutil import is_exe
1921

2022

2123
def check_first_register_readable(test_case):
@@ -333,3 +335,41 @@ def expectedCompiler(compilers):
333335
return True
334336

335337
return False
338+
339+
340+
# This is a helper function to determine if a specific version of Xcode's linker
341+
# contains a TLS bug. We want to skip TLS tests if they contain this bug, but
342+
# adding a linker/linker_version conditions to a decorator is challenging due to
343+
# the number of ways linkers can enter the build process.
344+
def darwinLinkerHasTLSBug():
345+
"""Returns true iff a test is running on a darwin platform and the host linker is between versions 1000 and 1109."""
346+
darwin_platforms = lldbplatform.translate(lldbplatform.darwin_all)
347+
if getPlatform() not in darwin_platforms:
348+
return False
349+
350+
linker_path = (
351+
subprocess.check_output(["xcrun", "--find", "ld"]).rstrip().decode("utf-8")
352+
)
353+
if not is_exe(linker_path):
354+
return False
355+
356+
raw_linker_info = (
357+
subprocess.check_output([linker_path, "-version_details"])
358+
.rstrip()
359+
.decode("utf-8")
360+
)
361+
parsed_linker_info = json.loads(raw_linker_info)
362+
if "version" not in parsed_linker_info:
363+
return False
364+
365+
raw_version = parsed_linker_info["version"]
366+
version = None
367+
try:
368+
version = int(raw_version)
369+
except:
370+
return False
371+
372+
if version is None:
373+
return False
374+
375+
return 1000 <= version and version <= 1109

lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def setUp(self):
4040
@skipIfWindows
4141
@skipIf(oslist=["linux"], archs=["arm", "aarch64"])
4242
@skipIf(oslist=no_match([lldbplatformutil.getDarwinOSTriples(), "linux"]))
43+
@expectedFailureIf(lldbplatformutil.darwinLinkerHasTLSBug())
4344
def test(self):
4445
"""Test thread-local storage."""
4546
self.build()

0 commit comments

Comments
 (0)