[glibc] elf: Introduce _dl_map_segment_align hook for segment alignment tuning

Wilco Dijkstra via Glibc-cvs <[email protected]>
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=88c3f481de92808499464fa7e2ac1e9fce9d649c

commit 88c3f481de92808499464fa7e2ac1e9fce9d649c
Author: WANG Rui <[email protected]>
Date:   Tue Apr 14 15:16:07 2026 +0000

    elf: Introduce _dl_map_segment_align hook for segment alignment tuning
    
    Introduce a new helper function, _dl_map_segment_align, to allow
    architecture-specific adjustment of ELF load segment alignment during
    object mapping.
    
    The generic ELF loader now calls this hook when determining the maximum
    segment alignment.  The generic implementation is a no-op and preserves
    existing behavior.
    
    This provides a well-defined extension point for architectures that
    need to adjust segment alignment policies (for example, to improve
    mapping efficiency or enable platform-specific optimizations) without
    embedding such logic directly in the generic loader.
    
    Reviewed-by: Wilco Dijkstra  <[email protected]>
    Signed-off-by: WANG Rui <[email protected]>

Diff:
---
 elf/dl-load.c                          |  4 ++++
 sysdeps/generic/dl-map-segment-align.h | 26 ++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index a5693a3a66..48575fff06 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -71,6 +71,7 @@ struct filebuf
 #include <dl-dst.h>
 #include <dl-load.h>
 #include <dl-map-segments.h>
+#include <dl-map-segment-align.h>
 #include <dl-unmap-segments.h>
 #include <dl-machine-reject-phdr.h>
 #include <dl-prop.h>
@@ -1171,6 +1172,9 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
 
 	  /* Optimize a common case.  */
 	  c->prot = pf_to_prot (ph->p_flags);
+
+	  /* Architecture-specific adjustment of segment alignment. */
+	  p_align_max = _dl_map_segment_align (c, p_align_max);
 	  break;
 
 	case PT_TLS:
diff --git a/sysdeps/generic/dl-map-segment-align.h b/sysdeps/generic/dl-map-segment-align.h
new file mode 100644
index 0000000000..f4a671f25f
--- /dev/null
+++ b/sysdeps/generic/dl-map-segment-align.h
@@ -0,0 +1,26 @@
+/* _dl_map_segment_align.  Generic version.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+   Copyright The GNU Toolchain Authors.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <dl-load.h>
+
+static inline ElfW(Addr)
+_dl_map_segment_align (const struct loadcmd *c, ElfW(Addr) p_align_max)
+{
+  return p_align_max;
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.