Skip to content

Commit 2594095

Browse files
Replace ArchSpec::PiecewiseCompare() with Triple::operator==() (llvm#82804)
Looking ast the definition of both functions this is *almost* an NFC change, except that Triple also looks at the SubArch (important) and ObjectFormat (less so). This fixes a bug that only manifests with how Xcode uses the SBAPI to attach to a process by name: it guesses the architecture based on the system. If the system is arm64 and the Process is arm64e Target fails to update the triple because it deemed the two to be equivalent. rdar://123338218
1 parent dcf4ca5 commit 2594095

File tree

6 files changed

+33
-29
lines changed

6 files changed

+33
-29
lines changed

lldb/include/lldb/Utility/ArchSpec.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,6 @@ class ArchSpec {
505505

506506
bool IsFullySpecifiedTriple() const;
507507

508-
void PiecewiseTripleCompare(const ArchSpec &other, bool &arch_different,
509-
bool &vendor_different, bool &os_different,
510-
bool &os_version_different,
511-
bool &env_different) const;
512-
513508
/// Detect whether this architecture uses thumb code exclusively
514509
///
515510
/// Some embedded ARM chips (e.g. the ARM Cortex M0-7 line) can only execute

lldb/source/Target/Target.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,14 +1568,8 @@ bool Target::SetArchitecture(const ArchSpec &arch_spec, bool set_platform,
15681568

15691569
if (m_arch.GetSpec().IsCompatibleMatch(other)) {
15701570
compatible_local_arch = true;
1571-
bool arch_changed, vendor_changed, os_changed, os_ver_changed,
1572-
env_changed;
15731571

1574-
m_arch.GetSpec().PiecewiseTripleCompare(other, arch_changed,
1575-
vendor_changed, os_changed,
1576-
os_ver_changed, env_changed);
1577-
1578-
if (!arch_changed && !vendor_changed && !os_changed && !env_changed)
1572+
if (m_arch.GetSpec().GetTriple() == other.GetTriple())
15791573
replace_local_arch = false;
15801574
}
15811575
}

lldb/source/Utility/ArchSpec.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,23 +1421,6 @@ bool ArchSpec::IsFullySpecifiedTriple() const {
14211421
return true;
14221422
}
14231423

1424-
void ArchSpec::PiecewiseTripleCompare(
1425-
const ArchSpec &other, bool &arch_different, bool &vendor_different,
1426-
bool &os_different, bool &os_version_different, bool &env_different) const {
1427-
const llvm::Triple &me(GetTriple());
1428-
const llvm::Triple &them(other.GetTriple());
1429-
1430-
arch_different = (me.getArch() != them.getArch());
1431-
1432-
vendor_different = (me.getVendor() != them.getVendor());
1433-
1434-
os_different = (me.getOS() != them.getOS());
1435-
1436-
os_version_different = (me.getOSMajorVersion() != them.getOSMajorVersion());
1437-
1438-
env_different = (me.getEnvironment() != them.getEnvironment());
1439-
}
1440-
14411424
bool ArchSpec::IsAlwaysThumbInstructions() const {
14421425
std::string Status;
14431426
if (GetTriple().getArch() == llvm::Triple::arm ||
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
C_SOURCES := main.c
2+
include Makefile.rules
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
7+
class TestArm64eAttach(TestBase):
8+
NO_DEBUG_INFO_TESTCASE = True
9+
10+
# On Darwin systems, arch arm64e means ARMv8.3 with ptrauth ABI used.
11+
@skipIf(archs=no_match(["arm64e"]))
12+
def test(self):
13+
# Skip this test if not running on AArch64 target that supports PAC
14+
if not self.isAArch64PAuth():
15+
self.skipTest("Target must support pointer authentication.")
16+
self.build()
17+
popen = self.spawnSubprocess(self.getBuildArtifact(), [])
18+
error = lldb.SBError()
19+
# This simulates how Xcode attaches to a process by pid/name.
20+
target = self.dbg.CreateTarget("", "arm64", "", True, error)
21+
listener = lldb.SBListener("my.attach.listener")
22+
process = target.AttachToProcessWithID(listener, popen.pid, error)
23+
self.assertSuccess(error)
24+
self.assertTrue(process, PROCESS_IS_VALID)
25+
self.assertEqual(target.GetTriple().split('-')[0], "arm64e",
26+
"target triple is updated correctly")
27+
error = process.Kill()
28+
self.assertSuccess(error)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int getchar();
2+
int main() { return getchar(); }

0 commit comments

Comments
 (0)