Skip to content

fix: bind stat() to __xstat for pre-2.33 glibc hosts - #278

Open
brainrake wants to merge 1 commit into
masterfrom
fix/glibc-compat-symbols
Open

brainrake wants to merge 1 commit into
masterfrom
fix/glibc-compat-symbols

Conversation

@brainrake

@brainrake brainrake commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Links stat() against __xstat so the module loads on glibc older than 2.33.
Ported patch from supabase/postgres#2523

@brainrake
brainrake force-pushed the fix/glibc-compat-symbols branch from 5e02170 to 60223f0 Compare November 20, 2026 00:46
@brainrake
brainrake marked this pull request as ready for review November 20, 2026 00:46
@brainrake
brainrake requested a review from a team as a code owner November 20, 2026 00:46
@brainrake
brainrake marked this pull request as draft November 20, 2026 00:47
@AndrewJackson2020

Copy link
Copy Markdown
Contributor

Sounds like currently supautils would be incompatible with the rocky8 packaged glibc. IMO this is definitely a problem. I think that we would want at least one CI task that runs on a non bleeding edge glibc. Not sure if the best way of doing that is using an old nixpkgs or just running CI on rocky 8/9 kind of like my PR below in vault.

> podman run -it rockylinux/rockylinux:8.10 dnf list installed glibc
Installed Packages
glibc.aarch64                                   2.28-251.el8_10.2                                   @System

> podman run -it rockylinux/rockylinux:9.7 dnf list installed glibc
Installed Packages
glibc.aarch64                      2.34-231.el9_7.2                       @1d2487d6c976430ead2aae97b9731ea5

[0] supabase/vault#71

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@brainrake
brainrake force-pushed the fix/glibc-compat-symbols branch from 60223f0 to 89c3da9 Compare November 23, 2026 12:40
@brainrake
brainrake marked this pull request as ready for review November 23, 2026 15:17
@AndrewJackson2020

AndrewJackson2020 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Was scoping this out a little bit, like the pg_net libcurl backcompat PR, we will need CI testing over older libc in this PR. It is more complicated than adding testing over 2 different versions of libcurl though. I think that we will need to update xpg in order to accommodate multiple postgres builds in different libc's. Just updating libc here without updating it in xpg leads to compile errors because it sources its CFLAGS from pg_config. This can be overridden for just this extension but I feel like it does not make sense in any real life context to use an extension compiled with a different libc version than the postgres server so I think we just need to support multiple libc compilation in xpg. Also, while on the topic, I think that xpg should provide the build environment (clang, gcc, etc) to the extension instead of just rely on the end user to bring their own build toolchain.

edit: @brainrake btw not saying that you need to do any of the above, just notes for myself and others on the postgres extensions team.

Comment on lines +6 to +22
/* Link against __xstat so the module loads on glibc older than 2.33. */
#if defined(__linux__) && defined(__GLIBC__) && \
(defined(__x86_64__) || defined(__aarch64__))
# if defined(__x86_64__)
# define SUPAUTILS_STAT_COMPAT_VER "GLIBC_2.2.5"
# define SUPAUTILS_STAT_VER 1
# else
# define SUPAUTILS_STAT_COMPAT_VER "GLIBC_2.17"
# define SUPAUTILS_STAT_VER 0
# endif
extern int __xstat(int ver, const char *path, struct stat *buf);
__asm__(".symver __xstat,__xstat@" SUPAUTILS_STAT_COMPAT_VER);
# undef stat
# define stat(path, buf) __xstat(SUPAUTILS_STAT_VER, path, buf)
# undef stat64
# define stat64(path, buf) __xstat(SUPAUTILS_STAT_VER, path, buf)
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite strange. @AndrewJackson2020 Have you seen any other extensions that do this? Is this something that has to be fixed in xpg in some other way maybe?

@AndrewJackson2020 AndrewJackson2020 Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I think first step is that we should get XPG to do postgres builds with non bleeding edge libc so we can experiment with this reproducibly. In the long term I would like to see one CI job for an old libc on all of the supabase extension repos.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only required for supautils because it needs to run on Ubuntu 20.04 but build against latest glibc. Currently we patch it in postgres repo, this PR is to upstream the patch.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This root cause is the way we ship supautils to prod via Salt. We build a single version (one per architecture) which we ship across the fleet. Ideally we should have different versions build for different ubuntu versions requiring appropriate glibc versions.

This is ugly because it depends on glibc internals and the patch would probably grow in size if we start using more symbols from glibc. I'm not sure why it's needed to build supautils in the postgres repo though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have another PR where im trying to implement testing in rockylinux 8, 9, and 10 for the sake of testing our code against various glitch's. I have not been able to get all tests passing in supautils though I think this s because of differential behavior of extension versions used in tests. Either way all generations of rockylinux are able to compile without issues.

#280

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on glibc internals but is forward compatible forever.
We need to maintain this for about a year, until pg 15 is EOL. By that time Ubuntu 20.04 is EOL and Rocky 9 is End of Active Support and we retire all hosts from that era.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a symptom of the bigger problem. We might remove this specific patch but that doesn't fix the underlying cause. We might have to create another similar patch in future as long as we continue to ship supautils as today.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants