Bug 251192 - databases/postgresql13-server: fix crashes related to LLVM JIT
Summary: databases/postgresql13-server: fix crashes related to LLVM JIT
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: pgsql
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-16 19:18 UTC by Dmitry Marakasov
Modified: 2020-12-15 20:51 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (pgsql)


Attachments
Patch (1.59 KB, patch)
2020-11-16 19:18 UTC, Dmitry Marakasov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Marakasov freebsd_committer freebsd_triage 2020-11-16 19:18:42 UTC
Created attachment 219740 [details]
Patch

I've ran into reproducible postgresql13 crash with LLVM enabled.

Can be reproduced with the following query:

SET jit_above_cost = 0;
SET jit_inline_above_cost = 0;
SET jit_optimize_above_cost = 0;
SELECT (jsonb_array_elements('[true]'::jsonb)->>0)::boolean;

Problem summary: thread local storage access from code inlined by LLVM JIT instantly crashes (llvm11 also reports an error about unsupported relocation). On FreeBSD TLS accesses are quite common as functions like isspace() (used in boolin and input functions for many other commonly used postgresql types) involve caching of locale specific data in TLS. 

Upstream bug including details, investigation and a workaround:

https://www.postgresql.org/message-id/flat/16696-29d944a33801fbfe%40postgresql.org#e010f0f56325aac5de96f8d0bb77dec0

For now, I suggest to apply the attached patch which disables inlining of functions which access TLS. Alternative would be to disable LLVM completely and mark it BROKEN, but IMO that'd be an overkill.
Comment 1 Dmitry Marakasov freebsd_committer freebsd_triage 2020-12-08 22:56:04 UTC
Ping. Let me remind that postgresql13 with LLVM is currently broken.
Comment 2 Palle Girgensohn freebsd_committer freebsd_triage 2020-12-15 20:50:26 UTC
Committed. Thanks!
Comment 3 commit-hook freebsd_committer freebsd_triage 2020-12-15 20:51:11 UTC
A commit references this bug:

Author: girgen
Date: Tue Dec 15 20:50:11 UTC 2020
New revision: 558181
URL: https://svnweb.freebsd.org/changeset/ports/558181

Log:
  Patch to mitigate a crash with LLVM JIT

  PR:	251192 (Submitted by Dmitry Marakasov)

Changes:
  head/databases/postgresql13-server/Makefile
  head/databases/postgresql13-server/files/patch-disable-llvm-jit-inlining-with-tls