From bf126f79dff0370d1e52ef8193da7fd593c37833 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 19 Jul 2023 23:10:48 +0800
Subject: [PATCH 4/6] elf: Align argument of __munmap to page size [BZ #28676]

On Linux/x86-64, for elf/tst-align3, we now get

munmap(0x7f88f9401000, 1126424)         = 0

instead of

munmap(0x7f1615200018, 544768)          = -1 EINVAL (Invalid argument)

Backport from master commit: fd6062e

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Rongwei Wang <rongwei.wang@linux.alibaba.com>
---
 elf/dl-map-segments.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h
index 61ba04cd..f1f7ad88 100644
--- a/elf/dl-map-segments.h
+++ b/elf/dl-map-segments.h
@@ -55,6 +55,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
       if (delta)
 	__munmap ((void *) map_start, delta);
       ElfW(Addr) map_end = map_start_aligned + maplength;
+      map_end = ALIGN_UP (map_end, GLRO(dl_pagesize));
       delta = map_start + maplen - map_end;
       if (delta)
 	__munmap ((void *) map_end, delta);
-- 
2.27.0

