diff --git a/glibc-Add-a-testcase-to-check-alignment-of-PT_LOAD-segment-2.patch b/glibc-Add-a-testcase-to-check-alignment-of-PT_LOAD-segment-2.patch new file mode 100644 index 0000000..995b35d --- /dev/null +++ b/glibc-Add-a-testcase-to-check-alignment-of-PT_LOAD-segment-2.patch @@ -0,0 +1,146 @@ +From ab887596903b159107e0be6f8b25986a5597cfca Mon Sep 17 00:00:00 2001 +From: "H.J. Lu" +Date: Mon, 7 Feb 2022 10:44:17 -0500 +Subject: [PATCH 2/4] Add a testcase to check alignment of PT_LOAD segment [BZ + #28676] + +Backport from master commit: fc2334a + +Signed-off-by: Rongwei Wang +--- + elf/Makefile | 14 ++++++++++++-- + elf/tst-align3.c | 38 ++++++++++++++++++++++++++++++++++++++ + elf/tst-alignmod3.c | 32 ++++++++++++++++++++++++++++++++ + 3 files changed, 82 insertions(+), 2 deletions(-) + create mode 100644 elf/tst-align3.c + create mode 100644 elf/tst-alignmod3.c + +diff --git a/elf/Makefile b/elf/Makefile +index 2093cefa..0d3366e2 100644 +--- a/elf/Makefile ++++ b/elf/Makefile +@@ -331,6 +331,7 @@ tests += \ + tst-addr1 \ + tst-align \ + tst-align2 \ ++ tst-align3 \ + tst-audit-tlsdesc \ + tst-audit-tlsdesc-dlopen \ + tst-audit1 \ +@@ -467,6 +468,10 @@ test-srcs = \ + tst-pathopt + # tests-srcs + ++ifeq (yes,$(have-fpie)) ++tests-pie += tst-align3 ++endif ++ + selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null) + + ifneq ($(selinux-enabled),1) +@@ -647,6 +652,7 @@ modules-names = \ + tst-absolute-zero-lib \ + tst-alignmod \ + tst-alignmod2 \ ++ tst-alignmod3 \ + tst-array2dep \ + tst-array5dep \ + tst-audit-tlsdesc-mod1 \ +@@ -1669,6 +1675,12 @@ CFLAGS-tst-alignmod2.c += $(stack-align-test-flags) + $(objpfx)tst-align: $(libdl) + $(objpfx)tst-align.out: $(objpfx)tst-alignmod.so + $(objpfx)tst-align2: $(objpfx)tst-alignmod2.so ++ifeq (yes,$(have-fpie)) ++CFLAGS-tst-align3.c += $(PIE-ccflag) ++endif ++LDFLAGS-tst-align3 += -Wl,-z,max-page-size=0x200000 ++LDFLAGS-tst-alignmod3.so += -Wl,-z,max-page-size=0x200000 ++$(objpfx)tst-alignmod3.so: $(libsupport) + + $(objpfx)unload3: $(libdl) + $(objpfx)unload3.out: $(objpfx)unload3mod1.so $(objpfx)unload3mod2.so \ +diff --git a/elf/tst-align3.c b/elf/tst-align3.c +new file mode 100644 +index 00000000..ac86d623 +--- /dev/null ++++ b/elf/tst-align3.c +@@ -0,0 +1,38 @@ ++/* Check alignment of PT_LOAD segment in a shared library. ++ Copyright (C) 2021 Free Software Foundation, Inc. ++ 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 ++ . */ ++ ++#include ++#include ++ ++/* This should cover all possible page sizes we currently support. */ ++#define ALIGN 0x200000 ++ ++int bar __attribute__ ((aligned (ALIGN))) = 1; ++ ++extern int do_load_test (void); ++ ++static int ++do_test (void) ++{ ++ printf ("bar: %p\n", &bar); ++ TEST_VERIFY (is_aligned (&bar, ALIGN) == 0); ++ ++ return do_load_test (); ++} ++ ++#include +diff --git a/elf/tst-alignmod3.c b/elf/tst-alignmod3.c +new file mode 100644 +index 00000000..0d33f237 +--- /dev/null ++++ b/elf/tst-alignmod3.c +@@ -0,0 +1,32 @@ ++/* Check alignment of PT_LOAD segment in a shared library. ++ Copyright (C) 2021 Free Software Foundation, Inc. ++ 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 ++ . */ ++ ++#include ++#include ++ ++/* This should cover all possible page sizes we currently support. */ ++#define ALIGN 0x200000 ++ ++int foo __attribute__ ((aligned (ALIGN))) = 1; ++ ++void ++do_load_test (void) ++{ ++ printf ("foo: %p\n", &foo); ++ TEST_VERIFY (is_aligned (&foo, ALIGN) == 0); ++} +-- +2.18.4 + diff --git a/glibc-Properly-check-stack-alignment-BZ-27901.patch b/glibc-Properly-check-stack-alignment-BZ-27901.patch new file mode 100644 index 0000000..58b6c5f --- /dev/null +++ b/glibc-Properly-check-stack-alignment-BZ-27901.patch @@ -0,0 +1,325 @@ +From 7ae4fdd1783cdfd30bfefdd7c3c3c9430f234406 Mon Sep 17 00:00:00 2001 +From: "H.J. Lu" +Date: Tue, 15 Feb 2022 14:15:50 -0500 +Subject: [PATCH] Properly check stack alignment [BZ #27901] + +1. Replace + +if ((((uintptr_t) &_d) & (__alignof (double) - 1)) != 0) + +which may be optimized out by compiler, with + +int +__attribute__ ((weak, noclone, noinline)) +is_aligned (void *p, int align) +{ + return (((uintptr_t) p) & (align - 1)) != 0; +} + +2. Add TEST_STACK_ALIGN_INIT to TEST_STACK_ALIGN. +3. Add a common TEST_STACK_ALIGN_INIT to check 16-byte stack alignment +for both i386 and x86-64. +4. Update powerpc to use TEST_STACK_ALIGN_INIT. + +Reviewed-by: Carlos O'Donell +Signed-off-by: Rongwei Wang +--- + sysdeps/generic/tst-stack-align.h | 40 ++++++++++++++++--------- + sysdeps/i386/i686/tst-stack-align.h | 44 --------------------------- + sysdeps/i386/tst-stack-align.h | 41 ------------------------- + sysdeps/powerpc/tst-stack-align.h | 27 +++++------------ + sysdeps/x86/tst-stack-align.h | 28 ++++++++++++++++++ + sysdeps/x86_64/tst-stack-align.h | 46 ----------------------------- + 6 files changed, 61 insertions(+), 165 deletions(-) + delete mode 100644 sysdeps/i386/i686/tst-stack-align.h + delete mode 100644 sysdeps/i386/tst-stack-align.h + create mode 100644 sysdeps/x86/tst-stack-align.h + delete mode 100644 sysdeps/x86_64/tst-stack-align.h + +diff --git a/sysdeps/generic/tst-stack-align.h b/sysdeps/generic/tst-stack-align.h +index e5cb3310..e6050901 100644 +--- a/sysdeps/generic/tst-stack-align.h ++++ b/sysdeps/generic/tst-stack-align.h +@@ -1,4 +1,5 @@ +-/* Copyright (C) 2003-2018 Free Software Foundation, Inc. ++/* Check stack alignment. Generic version. ++ Copyright (C) 2003-2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or +@@ -18,17 +19,28 @@ + #include + #include + ++int ++__attribute__ ((weak, noclone, noinline)) ++is_aligned (void *p, int align) ++{ ++ return (((uintptr_t) p) & (align - 1)) != 0; ++} ++ ++#ifndef TEST_STACK_ALIGN_INIT ++# define TEST_STACK_ALIGN_INIT() 0 ++#endif ++ + #define TEST_STACK_ALIGN() \ +- ({ \ +- double _d = 12.0; \ +- long double _ld = 15.0; \ +- int _ret = 0; \ +- printf ("double: %g %p %zu\n", _d, &_d, __alignof (double)); \ +- if ((((uintptr_t) &_d) & (__alignof (double) - 1)) != 0) \ +- _ret = 1; \ +- \ +- printf ("ldouble: %Lg %p %zu\n", _ld, &_ld, __alignof (long double)); \ +- if ((((uintptr_t) &_ld) & (__alignof (long double) - 1)) != 0) \ +- _ret = 1; \ +- _ret; \ +- }) ++ ({ \ ++ double _d = 12.0; \ ++ long double _ld = 15.0; \ ++ int _ret = TEST_STACK_ALIGN_INIT (); \ ++ \ ++ printf ("double: %g %p %zu\n", _d, &_d, __alignof (double)); \ ++ _ret += is_aligned (&_d, __alignof (double)); \ ++ \ ++ printf ("ldouble: %Lg %p %zu\n", _ld, &_ld, \ ++ __alignof (long double)); \ ++ _ret += is_aligned (&_ld, __alignof (long double)); \ ++ _ret; \ ++ }) +diff --git a/sysdeps/i386/i686/tst-stack-align.h b/sysdeps/i386/i686/tst-stack-align.h +deleted file mode 100644 +index 975f26ef..00000000 +--- a/sysdeps/i386/i686/tst-stack-align.h ++++ /dev/null +@@ -1,44 +0,0 @@ +-/* Copyright (C) 2003-2018 Free Software Foundation, Inc. +- 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 +- . */ +- +-#include +-#include +-#ifndef __SSE__ +-#include_next +-#else +-#include +- +-#define TEST_STACK_ALIGN() \ +- ({ \ +- __m128 _m; \ +- double _d = 12.0; \ +- long double _ld = 15.0; \ +- int _ret = 0; \ +- printf ("__m128: %p %zu\n", &_m, __alignof (__m128)); \ +- if ((((uintptr_t) &_m) & (__alignof (__m128) - 1)) != 0) \ +- _ret = 1; \ +- \ +- printf ("double: %g %p %zu\n", _d, &_d, __alignof (double)); \ +- if ((((uintptr_t) &_d) & (__alignof (double) - 1)) != 0) \ +- _ret = 1; \ +- \ +- printf ("ldouble: %Lg %p %zu\n", _ld, &_ld, __alignof (long double)); \ +- if ((((uintptr_t) &_ld) & (__alignof (long double) - 1)) != 0) \ +- _ret = 1; \ +- _ret; \ +- }) +-#endif +diff --git a/sysdeps/i386/tst-stack-align.h b/sysdeps/i386/tst-stack-align.h +deleted file mode 100644 +index 394ff773..00000000 +--- a/sysdeps/i386/tst-stack-align.h ++++ /dev/null +@@ -1,41 +0,0 @@ +-/* Copyright (C) 2004-2018 Free Software Foundation, Inc. +- 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 +- . */ +- +-#include +-#include +- +-typedef struct { int i[4]; } int_al16 __attribute__((aligned (16))); +- +-#define TEST_STACK_ALIGN() \ +- ({ \ +- int_al16 _m; \ +- double _d = 12.0; \ +- long double _ld = 15.0; \ +- int _ret = 0; \ +- printf ("int_al16: %p %zu\n", &_m, __alignof (int_al16)); \ +- if ((((uintptr_t) &_m) & (__alignof (int_al16) - 1)) != 0) \ +- _ret = 1; \ +- \ +- printf ("double: %g %p %zu\n", _d, &_d, __alignof (double)); \ +- if ((((uintptr_t) &_d) & (__alignof (double) - 1)) != 0) \ +- _ret = 1; \ +- \ +- printf ("ldouble: %Lg %p %zu\n", _ld, &_ld, __alignof (long double)); \ +- if ((((uintptr_t) &_ld) & (__alignof (long double) - 1)) != 0) \ +- _ret = 1; \ +- _ret; \ +- }) +diff --git a/sysdeps/powerpc/tst-stack-align.h b/sysdeps/powerpc/tst-stack-align.h +index 7fd7013b..d7400b28 100644 +--- a/sysdeps/powerpc/tst-stack-align.h ++++ b/sysdeps/powerpc/tst-stack-align.h +@@ -1,4 +1,5 @@ +-/* Copyright (C) 2005-2018 Free Software Foundation, Inc. ++/* Check stack alignment. PowerPC version. ++ Copyright (C) 2005-2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or +@@ -15,10 +16,7 @@ + License along with the GNU C Library; if not, see + . */ + +-#include +-#include +- +-#define TEST_STACK_ALIGN() \ ++#define TEST_STACK_ALIGN_INIT() \ + ({ \ + /* Altivec __vector int etc. needs 16byte aligned stack. \ + Instead of using altivec.h here, use aligned attribute instead. */ \ +@@ -27,20 +25,9 @@ + int _i __attribute__((aligned (16))); \ + int _j[3]; \ + } _s = { ._i = 18, ._j[0] = 19, ._j[1] = 20, ._j[2] = 21 }; \ +- double _d = 12.0; \ +- long double _ld = 15.0; \ +- int _ret = 0; \ + printf ("__vector int: { %d, %d, %d, %d } %p %zu\n", _s._i, _s._j[0], \ + _s._j[1], _s._j[2], &_s, __alignof (_s)); \ +- if ((((uintptr_t) &_s) & (__alignof (_s) - 1)) != 0) \ +- _ret = 1; \ +- \ +- printf ("double: %g %p %zu\n", _d, &_d, __alignof (double)); \ +- if ((((uintptr_t) &_d) & (__alignof (double) - 1)) != 0) \ +- _ret = 1; \ +- \ +- printf ("ldouble: %Lg %p %zu\n", _ld, &_ld, __alignof (long double)); \ +- if ((((uintptr_t) &_ld) & (__alignof (long double) - 1)) != 0) \ +- _ret = 1; \ +- _ret; \ +- }) ++ is_aligned (&_s, __alignof (_s)); \ ++ }) ++ ++#include_next +diff --git a/sysdeps/x86/tst-stack-align.h b/sysdeps/x86/tst-stack-align.h +new file mode 100644 +index 00000000..02ecc72d +--- /dev/null ++++ b/sysdeps/x86/tst-stack-align.h +@@ -0,0 +1,28 @@ ++/* Check stack alignment. X86 version. ++ Copyright (C) 2021 Free Software Foundation, Inc. ++ 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 ++ . */ ++ ++typedef struct { int i[16]; } int_al16 __attribute__((aligned (16))); ++ ++#define TEST_STACK_ALIGN_INIT() \ ++ ({ \ ++ int_al16 _m; \ ++ printf ("int_al16: %p %zu\n", &_m, __alignof (int_al16)); \ ++ is_aligned (&_m, __alignof (int_al16)); \ ++ }) ++ ++#include_next +diff --git a/sysdeps/x86_64/tst-stack-align.h b/sysdeps/x86_64/tst-stack-align.h +deleted file mode 100644 +index b2ef77f6..00000000 +--- a/sysdeps/x86_64/tst-stack-align.h ++++ /dev/null +@@ -1,46 +0,0 @@ +-/* Copyright (C) 2003-2018 Free Software Foundation, Inc. +- 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 +- . */ +- +-#include +-#include +- +-#define TEST_STACK_ALIGN() \ +- ({ \ +- /* AMD64 ABI mandates 16byte aligned stack. \ +- Unfortunately, current GCC doesn't support __int128 or __float128 \ +- types, so use aligned attribute instead. */ \ +- struct _S \ +- { \ +- int _i __attribute__((aligned (16))); \ +- int _pad[3]; \ +- } _s = { ._i = 18 }; \ +- double _d = 12.0; \ +- long double _ld = 15.0; \ +- int _ret = 0; \ +- printf ("__int128: %d %p %zu\n", _s._i, &_s, __alignof (_s)); \ +- if ((((uintptr_t) &_s) & (__alignof (_s) - 1)) != 0) \ +- _ret = 1; \ +- \ +- printf ("double: %g %p %zu\n", _d, &_d, __alignof (double)); \ +- if ((((uintptr_t) &_d) & (__alignof (double) - 1)) != 0) \ +- _ret = 1; \ +- \ +- printf ("ldouble: %Lg %p %zu\n", _ld, &_ld, __alignof (long double)); \ +- if ((((uintptr_t) &_ld) & (__alignof (long double) - 1)) != 0) \ +- _ret = 1; \ +- _ret; \ +- }) +-- +2.18.4 + diff --git a/glibc-Support-target-specific-ALIGN-for-variable-alignment-4.patch b/glibc-Support-target-specific-ALIGN-for-variable-alignment-4.patch new file mode 100644 index 0000000..5ac2055 --- /dev/null +++ b/glibc-Support-target-specific-ALIGN-for-variable-alignment-4.patch @@ -0,0 +1,171 @@ +From 9302aaad29363eb1dba30d5b9b588a165395672a Mon Sep 17 00:00:00 2001 +From: "H.J. Lu" +Date: Mon, 7 Feb 2022 10:46:19 -0500 +Subject: [PATCH 4/4] Support target specific ALIGN for variable alignment test + [BZ #28676] + +Add to support target specific ALIGN for variable +alignment test: + +1. Alpha: Use 0x10000. +2. MicroBlaze and Nios II: Use 0x8000. +3. All others: Use 0x200000. + +Backport from master commit: 4435c29 + +Reviewed-by: Adhemerval Zanella +Signed-off-by: Rongwei Wang +--- + elf/tst-align3.c | 4 +--- + elf/tst-alignmod3.c | 4 +--- + sysdeps/alpha/tst-file-align.h | 20 ++++++++++++++++++++ + sysdeps/generic/tst-file-align.h | 20 ++++++++++++++++++++ + sysdeps/microblaze/tst-file-align.h | 20 ++++++++++++++++++++ + sysdeps/nios2/tst-file-align.h | 20 ++++++++++++++++++++ + 6 files changed, 82 insertions(+), 6 deletions(-) + create mode 100644 sysdeps/alpha/tst-file-align.h + create mode 100644 sysdeps/generic/tst-file-align.h + create mode 100644 sysdeps/microblaze/tst-file-align.h + create mode 100644 sysdeps/nios2/tst-file-align.h + +diff --git a/elf/tst-align3.c b/elf/tst-align3.c +index ac86d623..87a8ff81 100644 +--- a/elf/tst-align3.c ++++ b/elf/tst-align3.c +@@ -17,11 +17,9 @@ + . */ + + #include ++#include + #include + +-/* This should cover all possible page sizes we currently support. */ +-#define ALIGN 0x200000 +- + int bar __attribute__ ((aligned (ALIGN))) = 1; + + extern int do_load_test (void); +diff --git a/elf/tst-alignmod3.c b/elf/tst-alignmod3.c +index 0d33f237..9520c352 100644 +--- a/elf/tst-alignmod3.c ++++ b/elf/tst-alignmod3.c +@@ -17,11 +17,9 @@ + . */ + + #include ++#include + #include + +-/* This should cover all possible page sizes we currently support. */ +-#define ALIGN 0x200000 +- + int foo __attribute__ ((aligned (ALIGN))) = 1; + + void +diff --git a/sysdeps/alpha/tst-file-align.h b/sysdeps/alpha/tst-file-align.h +new file mode 100644 +index 00000000..8fc3c940 +--- /dev/null ++++ b/sysdeps/alpha/tst-file-align.h +@@ -0,0 +1,20 @@ ++/* Check file alignment. Alpha version. ++ Copyright (C) 2021 Free Software Foundation, Inc. ++ 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 ++ . */ ++ ++/* This should cover all possible alignments we currently support. */ ++#define ALIGN 0x10000 +diff --git a/sysdeps/generic/tst-file-align.h b/sysdeps/generic/tst-file-align.h +new file mode 100644 +index 00000000..6ee6783a +--- /dev/null ++++ b/sysdeps/generic/tst-file-align.h +@@ -0,0 +1,20 @@ ++/* Check file alignment. Generic version. ++ Copyright (C) 2021 Free Software Foundation, Inc. ++ 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 ++ . */ ++ ++/* This should cover all possible page sizes we currently support. */ ++#define ALIGN 0x200000 +diff --git a/sysdeps/microblaze/tst-file-align.h b/sysdeps/microblaze/tst-file-align.h +new file mode 100644 +index 00000000..43c58b29 +--- /dev/null ++++ b/sysdeps/microblaze/tst-file-align.h +@@ -0,0 +1,20 @@ ++/* Check file alignment. MicroBlaze version. ++ Copyright (C) 2021 Free Software Foundation, Inc. ++ 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 ++ . */ ++ ++/* This should cover all possible alignments we currently support. */ ++#define ALIGN 0x8000 +diff --git a/sysdeps/nios2/tst-file-align.h b/sysdeps/nios2/tst-file-align.h +new file mode 100644 +index 00000000..589a2d5a +--- /dev/null ++++ b/sysdeps/nios2/tst-file-align.h +@@ -0,0 +1,20 @@ ++/* Check file alignment. Nios II version. ++ Copyright (C) 2021 Free Software Foundation, Inc. ++ 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 ++ . */ ++ ++/* This should cover all possible alignments we currently support. */ ++#define ALIGN 0x8000 +-- +2.18.4 + diff --git a/glibc-elf-Align-argument-of-__munmap-to-page-size-BZ-28676-3.patch b/glibc-elf-Align-argument-of-__munmap-to-page-size-BZ-28676-3.patch new file mode 100644 index 0000000..c065572 --- /dev/null +++ b/glibc-elf-Align-argument-of-__munmap-to-page-size-BZ-28676-3.patch @@ -0,0 +1,36 @@ +From a36e3f474b748bec447de3bdd8483b52b09e5804 Mon Sep 17 00:00:00 2001 +From: "H.J. Lu" +Date: Thu, 13 Jan 2022 03:48:36 +0800 +Subject: [PATCH 3/4] 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 +Signed-off-by: Rongwei Wang +--- + 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.18.4 + diff --git a/glibc-elf-Fix-tst-align3.patch b/glibc-elf-Fix-tst-align3.patch new file mode 100644 index 0000000..c170b2c --- /dev/null +++ b/glibc-elf-Fix-tst-align3.patch @@ -0,0 +1,40 @@ +From 716c4027b04db785034b0f67ac552cfaff360463 Mon Sep 17 00:00:00 2001 +From: Adhemerval Zanella +Date: Tue, 18 Jan 2022 14:36:45 -0300 +Subject: [PATCH] elf: Fix tst-align3 + +The elf/tst-align3.c declares the function using a wrong prototype. + +Checked on aarch64-linux-gnu. + +Signed-off-by: Rongwei Wang +--- + elf/tst-align3.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/elf/tst-align3.c b/elf/tst-align3.c +index 4913c26..6853b6e 100644 +--- a/elf/tst-align3.c ++++ b/elf/tst-align3.c +@@ -22,7 +22,7 @@ + + int bar __attribute__ ((aligned (ALIGN))) = 1; + +-extern int do_load_test (void); ++extern void do_load_test (void); + + static int + do_test (void) +@@ -30,7 +30,8 @@ do_test (void) + printf ("bar: %p\n", &bar); + TEST_VERIFY (is_aligned (&bar, ALIGN) == 0); + +- return do_load_test (); ++ do_load_test (); ++ return 0; + } + + #include +-- +1.8.3.1 + diff --git a/glibc-elf-Properly-align-PT_LOAD-segments-BZ-28676-1.patch b/glibc-elf-Properly-align-PT_LOAD-segments-BZ-28676-1.patch new file mode 100644 index 0000000..af6b6a6 --- /dev/null +++ b/glibc-elf-Properly-align-PT_LOAD-segments-BZ-28676-1.patch @@ -0,0 +1,137 @@ +From c61fc02c61a88204a5af47f61c1b7cfb19b61e32 Mon Sep 17 00:00:00 2001 +From: Rongwei Wang +Date: Mon, 7 Feb 2022 10:42:01 -0500 +Subject: [PATCH 1/4] elf: Properly align PT_LOAD segments [BZ #28676] + +When PT_LOAD segment alignment > the page size, allocate enough space to +ensure that the segment can be properly aligned. This change helps code +segments use huge pages become simple and available. + +This fixes [BZ #28676]. + +Backport from master commit: 718fdd8 + +Signed-off-by: Xu Yu +Signed-off-by: Rongwei Wang +--- + elf/dl-load.c | 2 ++ + elf/dl-load.h | 3 ++- + elf/dl-map-segments.h | 50 +++++++++++++++++++++++++++++++++++++++---- + 3 files changed, 50 insertions(+), 5 deletions(-) + +diff --git a/elf/dl-load.c b/elf/dl-load.c +index fee08d78..6785a499 100644 +--- a/elf/dl-load.c ++++ b/elf/dl-load.c +@@ -1,5 +1,6 @@ + /* Map in a shared object's segments from the file. + Copyright (C) 1995-2018 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 +@@ -1107,6 +1108,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, + c->mapend = ALIGN_UP (ph->p_vaddr + ph->p_filesz, GLRO(dl_pagesize)); + c->dataend = ph->p_vaddr + ph->p_filesz; + c->allocend = ph->p_vaddr + ph->p_memsz; ++ c->mapalign = ph->p_align; + c->mapoff = ALIGN_DOWN (ph->p_offset, GLRO(dl_pagesize)); + + /* Determine whether there is a gap between the last segment +diff --git a/elf/dl-load.h b/elf/dl-load.h +index 66ea2e92..d9f648ea 100644 +--- a/elf/dl-load.h ++++ b/elf/dl-load.h +@@ -1,5 +1,6 @@ + /* Map in a shared object's segments from the file. + Copyright (C) 1995-2018 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 +@@ -74,7 +75,7 @@ ELF_PREFERRED_ADDRESS_DATA; + Its details have been expanded out and converted. */ + struct loadcmd + { +- ElfW(Addr) mapstart, mapend, dataend, allocend; ++ ElfW(Addr) mapstart, mapend, dataend, allocend, mapalign; + ElfW(Off) mapoff; + int prot; /* PROT_* bits. */ + }; +diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h +index 084076a2..61ba04cd 100644 +--- a/elf/dl-map-segments.h ++++ b/elf/dl-map-segments.h +@@ -1,5 +1,6 @@ + /* Map in a shared object's segments. Generic version. + Copyright (C) 1995-2018 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 +@@ -18,6 +19,50 @@ + + #include + ++/* Map a segment and align it properly. */ ++ ++static __always_inline ElfW(Addr) ++_dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref, ++ const size_t maplength, int fd) ++{ ++ if (__glibc_likely (c->mapalign <= GLRO(dl_pagesize))) ++ return (ElfW(Addr)) __mmap ((void *) mappref, maplength, c->prot, ++ MAP_COPY|MAP_FILE, fd, c->mapoff); ++ ++ /* If the segment alignment > the page size, allocate enough space to ++ ensure that the segment can be properly aligned. */ ++ ElfW(Addr) maplen = (maplength >= c->mapalign ++ ? (maplength + c->mapalign) ++ : (2 * c->mapalign)); ++ ElfW(Addr) map_start = (ElfW(Addr)) __mmap ((void *) mappref, maplen, ++ PROT_NONE, ++ MAP_ANONYMOUS|MAP_PRIVATE, ++ -1, 0); ++ if (__glibc_unlikely ((void *) map_start == MAP_FAILED)) ++ return map_start; ++ ++ ElfW(Addr) map_start_aligned = ALIGN_UP (map_start, c->mapalign); ++ map_start_aligned = (ElfW(Addr)) __mmap ((void *) map_start_aligned, ++ maplength, c->prot, ++ MAP_COPY|MAP_FILE|MAP_FIXED, ++ fd, c->mapoff); ++ if (__glibc_unlikely ((void *) map_start_aligned == MAP_FAILED)) ++ __munmap ((void *) map_start, maplen); ++ else ++ { ++ /* Unmap the unused regions. */ ++ ElfW(Addr) delta = map_start_aligned - map_start; ++ if (delta) ++ __munmap ((void *) map_start, delta); ++ ElfW(Addr) map_end = map_start_aligned + maplength; ++ delta = map_start + maplen - map_end; ++ if (delta) ++ __munmap ((void *) map_end, delta); ++ } ++ ++ return map_start_aligned; ++} ++ + /* This implementation assumes (as does the corresponding implementation + of _dl_unmap_segments, in dl-unmap-segments.h) that shared objects + are always laid out with all segments contiguous (or with gaps +@@ -53,10 +98,7 @@ _dl_map_segments (struct link_map *l, int fd, + - MAP_BASE_ADDR (l)); + + /* Remember which part of the address space this object uses. */ +- l->l_map_start = (ElfW(Addr)) __mmap ((void *) mappref, maplength, +- c->prot, +- MAP_COPY|MAP_FILE, +- fd, c->mapoff); ++ l->l_map_start = _dl_map_segment (c, mappref, maplength, fd); + if (__glibc_unlikely ((void *) l->l_map_start == MAP_FAILED)) + return DL_MAP_SEGMENTS_ERROR_MAP_SEGMENT; + +-- +2.18.4 + diff --git a/glibc.spec b/glibc.spec index c1e7d19..340ba54 100644 --- a/glibc.spec +++ b/glibc.spec @@ -1,6 +1,7 @@ +%define anolis_release .0.1 %define glibcsrcdir glibc-2.28 %define glibcversion 2.28 -%define glibcrelease 225%{?dist} +%define glibcrelease 225%{anolis_release}%{?dist} # Pre-release tarballs are pulled in from git using a command that is # effectively: # @@ -1032,6 +1033,13 @@ Patch839: glibc-rh2144568.patch Patch840: glibc-rh2154914-1.patch Patch841: glibc-rh2154914-2.patch +Patch1000: glibc-Properly-check-stack-alignment-BZ-27901.patch +Patch1001: glibc-elf-Properly-align-PT_LOAD-segments-BZ-28676-1.patch +Patch1002: glibc-Add-a-testcase-to-check-alignment-of-PT_LOAD-segment-2.patch +Patch1003: glibc-elf-Align-argument-of-__munmap-to-page-size-BZ-28676-3.patch +Patch1004: glibc-Support-target-specific-ALIGN-for-variable-alignment-4.patch +Patch1005: glibc-elf-Fix-tst-align3.patch + ############################################################################## # Continued list of core "glibc" package information: ############################################################################## @@ -2861,6 +2869,9 @@ fi %files -f compat-libpthread-nonshared.filelist -n compat-libpthread-nonshared %changelog +* Thu Jun 15 2023 Rongwei Wang - 2.28-225.0.1 +- elf: Properly align PT_LOAD segments + * Fri Jan 20 2023 Florian Weimer - 2.28-225 - Enforce a specififc internal ordering for tunables (#2154914)