Re: Making type Datum be 8 bytes everywhere

From: Tomas Vondra <tomas(at)vondra(dot)me>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: Joe Conway <mail(at)joeconway(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: Making type Datum be 8 bytes everywhere
Date: 2025-09-10 20:27:57
Message-ID: 87036018-8d70-40ad-a0ac-192b07bd7b04@vondra.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While testing a different patch, I tried running with address sanitizer
on rpi5, running the 32-bit OS (which AFAIK is 64-bit kernel and 32-bit
user space). With that, stats_ext regression tests fail like this:

extended_stats.c:1082:27: runtime error: store to misaligned address
0x036671dc for type 'Datum', which requires 8 byte alignment
0x036671dc: note: pointer points here
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7e
7f 08 00 00 00 7f 7f 7f 7f
^

This happens because build_sorted_items() does palloc(), and then
accesses the pointer as array of structs, with a Datum field. And it
apparently expects the pointer to be a multiple of 8 bytes. Isn't that a
bit strange, with 32-bit user space? The pointer is indeed a multiple of
4B, so maybe the expected alignment is wrong?

I did try this on REL_18_STABLE, and that works just fine, so I believe
it's about this commit. I also tried this on a i386 debian environment
(more precisely, it's 32-bit chroot on 64-bit system, created using
debootstrap). And that seems to work fine too ...

It's entirely possible this is a rpi5-specific issue, or maybe a kernel
issue. The last time we saw something similar weirdness, it turned out
to be a long-standing kernel bug in move_pages(). But that affected the
x86 systems too.

FWIW this is how I run with address sanitizer:

./configure --enable-debug --enable-cassert \
CPPFLAGS="-O0 -fsanitize=alignment -fno-sanitize-recover=all -latomic" \
LDFLAGS="-fsanitize=alignment -latomic"

regards

--
Tomas Vondra

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-09-10 20:35:42 Re: Making type Datum be 8 bytes everywhere
Previous Message Bharath Rupireddy 2025-09-10 20:10:24 Re: Proposal: GUC to control starting/stopping logical subscription workers