Skip to content

Commit 3fd9c90

Browse files
committed
[lldb][AArch64] Correct top nibble setting in memory tag read tests
Due to a missing cast the << 60 always resulted in zero leaving the top nibble empty. So we weren't actually testing that lldb ignores those bits in addition to the tag bits. Correct that and also set the top nibbles to ascending values so that we can catch if lldb only removes one of the tag bits and top nibble, but not both. In future the tag manager will likely only remove the tag bits and leave non-address bits to the ABI plugin but for now make sure we're testing what we claim to implement.
1 parent edb9175 commit 3fd9c90

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ def test_mte_tag_read(self):
122122
"\[0x[0-9A-Fa-f]+f0, 0x[0-9A-Fa-f]+00\): 0xf \(mismatch\)\n"
123123
"\[0x[0-9A-Fa-f]+00, 0x[0-9A-Fa-f]+10\): 0x0 \(mismatch\)$"])
124124

125-
# Tags in start/end are ignored when creating the range.
126-
# So this is not an error despite start/end having different tags
127-
self.expect("memory tag read mte_buf mte_buf_alt_tag+16",
128-
patterns=["Logical tag: 0x9\n"
125+
# Top byte is ignored when creating the range, not just the 4 tag bits.
126+
# So even though these two pointers have different top bytes
127+
# and the start's is > the end's, this is not an error.
128+
self.expect("memory tag read mte_buf_alt_tag mte_buf+16",
129+
patterns=["Logical tag: 0xa\n"
129130
"Allocation tags:\n"
130131
"\[0x[0-9A-Fa-f]+00, 0x[0-9A-Fa-f]+10\): 0x0 \(mismatch\)$"])
131132

lldb/test/API/linux/aarch64/mte_tag_access/main.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,20 @@ int main(int argc, char const *argv[]) {
6767

6868
// Tag the original pointer with 9
6969
mte_buf = __arm_mte_create_random_tag(mte_buf, ~(1 << 9));
70-
// A different tag so that buf_alt_tag > buf if you don't handle the tag
70+
// A different tag so that mte_buf_alt_tag > mte_buf if you don't handle the
71+
// tag
7172
char *mte_buf_alt_tag = __arm_mte_create_random_tag(mte_buf, ~(1 << 10));
7273

7374
// lldb should be removing the whole top byte, not just the tags.
7475
// So fill 63-60 with something non zero so we'll fail if we only remove tags.
75-
#define SET_TOP_NIBBLE(ptr) (char *)((size_t)(ptr) | (0xA << 60))
76-
mte_buf = SET_TOP_NIBBLE(mte_buf);
77-
mte_buf_alt_tag = SET_TOP_NIBBLE(mte_buf_alt_tag);
78-
mte_buf_2 = SET_TOP_NIBBLE(mte_buf_2);
79-
mte_read_only = SET_TOP_NIBBLE(mte_read_only);
76+
#define SET_TOP_NIBBLE(ptr, value) \
77+
(char *)((size_t)(ptr) | ((size_t)((value)&0xf) << 60))
78+
// mte_buf_alt_tag's nibble > mte_buf to check that lldb isn't just removing
79+
// tag bits but the whole top byte when making ranges.
80+
mte_buf = SET_TOP_NIBBLE(mte_buf, 0xA);
81+
mte_buf_alt_tag = SET_TOP_NIBBLE(mte_buf_alt_tag, 0xB);
82+
mte_buf_2 = SET_TOP_NIBBLE(mte_buf_2, 0xC);
83+
mte_read_only = SET_TOP_NIBBLE(mte_read_only, 0xD);
8084

8185
// Breakpoint here
8286
return 0;

0 commit comments

Comments
 (0)