Skip to content

Commit 542e2ca

Browse files
author
git apple-llvm automerger
committed
Merge commit '4077e66432a1' from llvm.org/main into next
2 parents f96fa35 + 4077e66 commit 542e2ca

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

lldb/source/Expression/IRExecutionUnit.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,9 @@ class LoadAddressResolver {
776776
// If that didn't work, try the function.
777777
if (load_address == LLDB_INVALID_ADDRESS && candidate_sc.function) {
778778
Address addr = candidate_sc.function->GetAddress();
779-
load_address = m_target.GetProcessSP() ? addr.GetLoadAddress(&m_target)
780-
: addr.GetFileAddress();
779+
load_address = m_target.GetProcessSP()
780+
? addr.GetCallableLoadAddress(&m_target)
781+
: addr.GetFileAddress();
781782
}
782783

783784
// We found a load address.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C_SOURCES := main.c
2+
3+
include Makefile.rules
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Test that addresses of functions compiled for Arm Thumb include the Thumb mode
3+
bit (bit 0 of the address) when resolved and used in expressions.
4+
"""
5+
6+
import lldb
7+
from lldbsuite.test.decorators import *
8+
from lldbsuite.test.lldbtest import *
9+
from lldbsuite.test import lldbutil
10+
11+
12+
class TestThumbFunctionAddr(TestBase):
13+
def do_thumb_function_test(self, language):
14+
self.build(dictionary={"CFLAGS_EXTRAS": f"-x {language} -mthumb"})
15+
16+
exe = self.getBuildArtifact("a.out")
17+
line = line_number("main.c", "// Set break point at this line.")
18+
self.runCmd("target create %s" % exe)
19+
bpid = lldbutil.run_break_set_by_file_and_line(self, "main.c", line)
20+
21+
self.runCmd("run")
22+
self.assertIsNotNone(
23+
lldbutil.get_one_thread_stopped_at_breakpoint_id(self.process(), bpid),
24+
"Process is not stopped at breakpoint",
25+
)
26+
27+
# The compiler set this, so the mode bit will be included here.
28+
a_function_addr_var = (
29+
self.thread().GetFrameAtIndex(0).FindVariable("a_function_addr")
30+
)
31+
self.assertTrue(a_function_addr_var.IsValid())
32+
a_function_addr = a_function_addr_var.GetValueAsUnsigned()
33+
self.assertTrue(a_function_addr & 1)
34+
35+
self.expect("p/x a_function_addr", substrs=[f"0x{a_function_addr:08x}"])
36+
# If lldb did not pay attention to the mode bit this would SIGILL trying
37+
# to execute Thumb encodings in Arm mode.
38+
self.expect("expression -- a_function()", substrs=["= 123"])
39+
40+
# We cannot call GetCallableLoadAdress via. the API, so we expect this
41+
# to not have the bit set as it's treating it as a non-function symbol.
42+
found_function = self.target().FindFunctions("a_function")[0]
43+
self.assertTrue(found_function.IsValid())
44+
found_function = found_function.GetFunction()
45+
self.assertTrue(found_function.IsValid())
46+
found_function_addr = found_function.GetStartAddress()
47+
a_function_load_addr = found_function_addr.GetLoadAddress(self.target())
48+
self.assertEqual(a_function_load_addr, a_function_addr & ~1)
49+
50+
# image lookup should not include the mode bit.
51+
a_function_file_addr = found_function_addr.GetFileAddress()
52+
self.expect(
53+
"image lookup -n a_function", substrs=[f"0x{a_function_file_addr:08x}"]
54+
)
55+
56+
# This test is run for C and C++ because the two will take different paths
57+
# trying to resolve the function's address.
58+
59+
@skipIf(archs=no_match(["arm$"]))
60+
@skipIf(archs=["arm64"])
61+
def test_function_addr_c(self):
62+
self.do_thumb_function_test("c")
63+
64+
@skipIf(archs=no_match(["arm$"]))
65+
@skipIf(archs=["arm64"])
66+
def test_function_addr_cpp(self):
67+
self.do_thumb_function_test("c++")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdint.h>
2+
3+
int a_function() { return 123; }
4+
5+
int main() {
6+
const uintptr_t a_function_addr = (uintptr_t)a_function;
7+
// Set break point at this line.
8+
return a_function();
9+
}

0 commit comments

Comments
 (0)