Re: [PATCH v3] x86/vmlinux: Fix vmlinux.lds.S with pre-2.23 binutils

From: Arvind Sankar
Date: Mon Jan 13 2020 - 18:06:48 EST


On Mon, Jan 13, 2020 at 03:46:04PM -0600, Tom Lendacky wrote:
> > @@ -372,7 +374,7 @@ SECTIONS
> > * explicitly reserved using memblock_reserve() or it will be discarded
> > * and treated as available memory.
> > */
> > - __end_of_kernel_reserve = .;
> > + __end_of_kernel_reserve = __bss_stop;
>
> The only thing I worry about is if someone inserts a section between
> the bss section and here and doesn't update this value.
>
> Thanks,
> Tom

Could do something like this, or maybe with just the comment?

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index bad4e22384dc..25aa1b30068e 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -373,9 +373,16 @@ SECTIONS
* automatically reserved in setup_arch(). Anything after here must be
* explicitly reserved using memblock_reserve() or it will be discarded
* and treated as available memory.
+ *
+ * Note that this is defined to use __bss_stop rather than dot for
+ * compatibility with binutils <2.23, so the definition MUST be updated
+ * if another section is added after .bss.
*/
__end_of_kernel_reserve = __bss_stop;

+ /* Used for build-time check that __end_of_kernel_reserve is correct */
+ __end_of_kernel_reserve_check = .;
+
. = ALIGN(PAGE_SIZE);
.brk : AT(ADDR(.brk) - LOAD_OFFSET) {
__brk_base = .;
@@ -451,6 +458,9 @@ INIT_PER_CPU(irq_stack_backing_store);

#endif /* CONFIG_X86_32 */

+. = ASSERT(__end_of_kernel_reserve == __end_of_kernel_reserve_check,
+ "__end_of_kernel_reserve is incorrectly defined");
+
#ifdef CONFIG_KEXEC_CORE
#include <asm/kexec.h>