[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-07 Thread Alex Langford via lldb-commits

https://github.com/bulbazord closed 
https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-07 Thread Dave Lee via lldb-commits

https://github.com/kastiglione approved this pull request.

looks good

https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-07 Thread Alex Langford via lldb-commits

https://github.com/bulbazord updated 
https://github.com/llvm/llvm-project/pull/83941

>From 89d1c201636403bb26f12cf9681cbaf86b5c943b Mon Sep 17 00:00:00 2001
From: Alex Langford 
Date: Mon, 4 Mar 2024 14:17:20 -0800
Subject: [PATCH] [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.
---
 .../Python/lldbsuite/test/lldbplatformutil.py | 27 +++
 .../API/lang/c/tls_globals/TestTlsGlobals.py  |  1 +
 2 files changed, 28 insertions(+)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index c4d063d3cc77ef..187d16aa1baa68 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,28 @@ 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 xcode15LinkerBug():
+"""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
+
+try:
+raw_version_details = subprocess.check_output(
+("xcrun", "ld", "-version_details")
+)
+version_details = json.loads(raw_version_details)
+version = version_details.get("version", "0")
+version_tuple = tuple(int(x) for x in version.split("."))
+if (1000,) <= version_tuple <= (1109,):
+return True
+except:
+pass
+
+return False
diff --git a/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py 
b/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
index dfe29b451df0a6..2bffd2eea123a6 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.xcode15LinkerBug())
 def test(self):
 """Test thread-local storage."""
 self.build()

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-07 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
a41226b05510a6f40d99fc622d78853460dc5599...a72d9d259b441c338399340d630ed7a64c1e228a
 lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
``





View the diff from darker here.


``diff
--- packages/Python/lldbsuite/test/lldbplatformutil.py  2024-03-07 
21:07:47.00 +
+++ packages/Python/lldbsuite/test/lldbplatformutil.py  2024-03-07 
21:10:29.730620 +
@@ -346,11 +346,13 @@
 darwin_platforms = lldbplatform.translate(lldbplatform.darwin_all)
 if getPlatform() not in darwin_platforms:
 return False
 
 try:
-raw_version_details = subprocess.check_output(("xcrun", "ld", 
"-version_details"))
+raw_version_details = subprocess.check_output(
+("xcrun", "ld", "-version_details")
+)
 version_details = json.loads(raw_version_details)
 version = version_details.get("version", "0")
 version_tuple = tuple(int(x) for x in version.split("."))
 if (1000,) <= version_tuple <= (1109,):
 return True

``




https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-07 Thread Alex Langford via lldb-commits

https://github.com/bulbazord updated 
https://github.com/llvm/llvm-project/pull/83941

>From a72d9d259b441c338399340d630ed7a64c1e228a Mon Sep 17 00:00:00 2001
From: Alex Langford 
Date: Mon, 4 Mar 2024 14:17:20 -0800
Subject: [PATCH] [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.
---
 .../Python/lldbsuite/test/lldbplatformutil.py | 25 +++
 .../API/lang/c/tls_globals/TestTlsGlobals.py  |  1 +
 2 files changed, 26 insertions(+)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index c4d063d3cc77ef..03e28fe6ba7795 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,26 @@ 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 xcode15LinkerBug():
+"""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
+
+try:
+raw_version_details = subprocess.check_output(("xcrun", "ld", 
"-version_details"))
+version_details = json.loads(raw_version_details)
+version = version_details.get("version", "0")
+version_tuple = tuple(int(x) for x in version.split("."))
+if (1000,) <= version_tuple <= (1109,):
+return True
+except:
+pass
+
+return False
diff --git a/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py 
b/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
index dfe29b451df0a6..2bffd2eea123a6 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.xcode15LinkerBug())
 def test(self):
 """Test thread-local storage."""
 self.build()

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-07 Thread Dave Lee via lldb-commits


@@ -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)

kastiglione wrote:

`float` also isn't sufficient, since some versions can contain 3 separate 
numbers (ie `100.5.8`).

In my related PR, I used this:

```py
version_tuple = tuple(int(x) for x in version.split("."))
if (1000,) <= version_tuple <= (1109,):
# handle bug
```

Comparisons of tuples appear to behave as desired.

https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-06 Thread Alex Langford via lldb-commits

bulbazord wrote:

> 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. 

https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-06 Thread Dave Lee via lldb-commits

kastiglione wrote:

To start with option #​1 I created 
https://github.com/llvm/llvm-project/pull/84246

https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-06 Thread Dave Lee via lldb-commits

kastiglione wrote:

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?

https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-05 Thread Dave Lee via lldb-commits

https://github.com/kastiglione edited 
https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-05 Thread Dave Lee via lldb-commits

https://github.com/kastiglione edited 
https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-05 Thread Dave Lee via lldb-commits


@@ -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"]

kastiglione wrote:

```suggestion
raw_version = parsed_linker_info.get("version")
```

https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-05 Thread Dave Lee via lldb-commits


@@ -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

kastiglione wrote:

```suggestion
try:
version = int(raw_version)
return 1000 <= version <= 1109
except:
return False
```

https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-05 Thread Dave Lee via lldb-commits


@@ -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():

kastiglione wrote:

should there be two functions here? A generic function that can check for 
arbitrary version ranges, and then a specific `darwinLinkerHasTLSBug` which is 
implemented as:

```py
def darwinLinkerHasTLSBug():
return 1000 <= checkDarwinLinkerVersion() <= 1109
```

https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-05 Thread Dave Lee via lldb-commits


@@ -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)

kastiglione wrote:

this this guaranteed to always be an integer? Note that `ld -ld_classic 
-version_details` has a version of "954.7" on my machine. Were there any 
releases with decimals in the range that has the bug?

https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-05 Thread Dave Lee via lldb-commits


@@ -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")

kastiglione wrote:

I believe this is more conventional:

```suggestion
subprocess.check_output(["xcrun", "--find", "ld"], text=True).rstrip()
```

https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-04 Thread via lldb-commits

llvmbot wrote:




@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
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()

``




https://github.com/llvm/llvm-project/pull/83941
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add ability to detect darwin host linker version to xfail tests (PR #83941)

2024-03-04 Thread Alex Langford via lldb-commits

https://github.com/bulbazord created 
https://github.com/llvm/llvm-project/pull/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.

>From 480252e4b0eba8f631568b6da4e48f657c516576 Mon Sep 17 00:00:00 2001
From: Alex Langford 
Date: Mon, 4 Mar 2024 14:17:20 -0800
Subject: [PATCH] [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.
---
 .../Python/lldbsuite/test/lldbplatformutil.py | 40 +++
 .../API/lang/c/tls_globals/TestTlsGlobals.py  |  1 +
 2 files changed, 41 insertions(+)

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