On 3/5/26 6:42 AM, Peter Maydell wrote:
On Thu, 5 Mar 2026 at 12:01, Peter Maydell <[email protected]> wrote:
In commit eb3f69cac62670 we removed the dependency of this
mem plugin on the QEMU headers, but in doing that we introduced
undefined behaviour when the plugin accesses unaligned memory.
This shows up if you build with the gcc or clang address
sanitizer and run 'make check-tcg', in numerous warnings like:
This should read "with the gcc or clang undefined behaviour
sanitizer", which then lines up with what the error message
below reports itself as:
../../tests/tcg/plugins/mem.c:167:27: runtime error: load of misaligned address
0x7f1f300354b1 for type 'uint16_t' (aka 'unsigned short'), which requires 2
byte alignment
0x7f1f300354b1: note: pointer points here
00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15
16 17 18 19 1a 1b 1c
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../tests/tcg/plugins/mem.c:167:27
Specifically, I see this with
'../../configure' '--cc=clang' '--cxx=clang++' '--enable-ubsan'
Here's a specific failure;
timeout -s KILL --foreground 120
/home/pm215/qemu/build/clang/qemu-system-aarch64 -monitor none
-display none -chardev file,path=run-plugin-memory-with-libmem.s
o.out,id=output -plugin ../plugins/libmem.so,region-summary=true -d
plugin -D memory-with-libmem.so.pout -M virt -cpu max -display none
-semihosting-config enabl
e=on,target=native,chardev=output -kernel memory
../../tests/tcg/plugins/mem.c:167:27: runtime error: load of
misaligned address 0x754e340357c1 for type 'uint16_t' (aka 'unsigned
short'), which requires 2 byte
alignment
0x754e340357c1: note: pointer points here
00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12
13 14 15 16 17 18 19 1a 1b 1c
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../tests/tcg/plugins/mem.c:167:27
../../tests/tcg/plugins/mem.c:179:27: runtime error: load of
misaligned address 0x754e340357c1 for type 'uint32_t' (aka 'unsigned
int'), which requires 4 byte alignment
0x754e340357c1: note: pointer points here
00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12
13 14 15 16 17 18 19 1a 1b 1c
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../tests/tcg/plugins/mem.c:179:27
../../tests/tcg/plugins/mem.c:191:27: runtime error: load of
misaligned address 0x754e340357c1 for type 'uint64_t' (aka 'unsigned
long'), which requires 8 byte alignment
0x754e340357c1: note: pointer points here
00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12
13 14 15 16 17 18 19 1a 1b 1c
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../tests/tcg/plugins/mem.c:191:27
../../tests/tcg/plugins/mem.c:165:13: runtime error: store to
misaligned address 0x754e340357c1 for type 'uint16_t' (aka 'unsigned
short'), which requires 2 byte alignment
0x754e340357c1: note: pointer points here
00 00 00 00 00 00 00 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12
13 14 15 16 17 18 19 1a 1b 1c
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../tests/tcg/plugins/mem.c:165:13
../../tests/tcg/plugins/mem.c:177:13: runtime error: store to
misaligned address 0x754e340357c1 for type 'uint32_t' (aka 'unsigned
int'), which requires 4 byte alignment
0x754e340357c1: note: pointer points here
00 00 00 00 00 00 00 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12
13 14 15 16 17 18 19 1a 1b 1c
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../tests/tcg/plugins/mem.c:177:13
../../tests/tcg/plugins/mem.c:189:13: runtime error: store to
misaligned address 0x754e340357c1 for type 'uint64_t' (aka 'unsigned
long'), which requires 8 byte alignment
0x754e340357c1: note: pointer points here
00 00 00 00 00 00 00 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12
13 14 15 16 17 18 19 1a 1b 1c
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../tests/tcg/plugins/mem.c:189:13
Similar with i386 and x86-64 targets.
-- PMM
Thanks for fixing it Peter.
It would be nice to run this in CI by default one day.
Reviewed-by: Pierrick Bouvier <[email protected]>