From e8a0c8633e969ad45eef82b40460df6552e6e550 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Fri, 2 Dec 2022 14:58:21 +0700
Subject: [PATCH v2 1/2] Align loadable segments to 2MB boundaries on Linux

Prerequsite for using huge pages for the .text section
on that platform.

TODO: autoconf support

Andres Freund and John Naylor
---
 meson.build | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/meson.build b/meson.build
index 16b2e86646..32af8bf5c3 100644
--- a/meson.build
+++ b/meson.build
@@ -248,6 +248,13 @@ elif host_system == 'freebsd'
 elif host_system == 'linux'
   sema_kind = 'unnamed_posix'
   cppflags += '-D_GNU_SOURCE'
+  # Align the loadable segments to 2MB boundaries to support remapping to
+  # huge pages.
+  ldflags += cc.get_supported_link_arguments([
+    '-Wl,-zmax-page-size=0x200000',
+    '-Wl,-zcommon-page-size=0x200000',
+    '-Wl,-zseparate-loadable-segments'
+  ])
 
 elif host_system == 'netbsd'
   # We must resolve all dynamic linking in the core server at program start.
-- 
2.40.1

