[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+icZUX93x_vhG-j+H+ktC_vt1d0f-KWZ+0L+hf1dnr=0L9h7g@mail.gmail.com>
Date: Tue, 14 Jul 2020 22:43:11 +0200
From: Sedat Dilek <sedat.dilek@...il.com>
To: Arvind Sankar <nivedita@...m.mit.edu>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>, x86@...nel.org,
Nick Desaulniers <ndesaulniers@...gle.com>,
Fangrui Song <maskray@...gle.com>,
Dmitry Golovin <dima@...ovin.in>,
Clang-Built-Linux ML <clang-built-linux@...glegroups.com>,
Ard Biesheuvel <ardb@...nel.org>,
Masahiro Yamada <masahiroy@...nel.org>,
Daniel Kiper <daniel.kiper@...cle.com>,
Kees Cook <keescook@...omium.org>,
Nathan Chancellor <natechancellor@...il.com>,
Arnd Bergmann <arnd@...db.de>,
"H . J . Lu" <hjl@...rceware.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 0/7] x86/boot: Remove runtime relocations from
compressed kernel
On Tue, Jul 14, 2020 at 10:35 PM Arvind Sankar <nivedita@...m.mit.edu> wrote:
>
> On Tue, Jul 14, 2020 at 10:27:25PM +0200, Sedat Dilek wrote:
> > On Tue, Jul 14, 2020 at 10:24 PM Sedat Dilek <sedat.dilek@...il.com> wrote:
> > >
> > > On Tue, Jul 14, 2020 at 10:21 PM Arvind Sankar <nivedita@...m.mit.edu> wrote:
> > > >
> > > > On Tue, Jul 14, 2020 at 10:08:04PM +0200, Sedat Dilek wrote:
> > > > > > >
> > > > > > > In any case, I think the right fix here would be to add -pie and
> > > > > > > --no-dynamic-linker to LDFLAGS_vmlinux instead of KBUILD_LDFLAGS.
> > > > > >
> > > > > > Hmm, you might be right with moving to LDFLAGS_vmlinux.
> > > > > >
> > > > >
> > > > > We will need the "ifndef CONFIG_LD_IS_LLD" as -r and -pie cannot be
> > > > > used together.
> > > > > Is that the or not the fact when moving to LDFLAGS_vmlinux?
> > > >
> > > > LDFLAGS_vmlinux will only be used to link boot/compressed/vmlinux,
> > > > whereas KBUILD_LDFLAGS is used for all linker invocations, and in
> > > > particular the little link to do the modversions stuff ends up using it.
> > > >
> > > > So once we move -pie --no-dynamic-linker to the more correct
> > > > LDFLAGS_vmlinux and/or stop modversions running, we'll be fine. Being
> > > > able to use -pie with lld is one of the goals of this series.
> > > >
> > >
> > > OK, I am doing a new full kernel build with:
> > >
> > > $ git diff arch/x86/boot/compressed/Makefile
> > > diff --git a/arch/x86/boot/compressed/Makefile
> > > b/arch/x86/boot/compressed/Makefile
> > > index 789d5d14d8b0..056a738e47c6 100644
> > > --- a/arch/x86/boot/compressed/Makefile
> > > +++ b/arch/x86/boot/compressed/Makefile
> > > @@ -51,7 +51,7 @@ UBSAN_SANITIZE :=n
> > > KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
> > > # Compressed kernel should be built as PIE since it may be loaded at any
> > > # address by the bootloader.
> > > -KBUILD_LDFLAGS += -pie $(call ld-option, --no-dynamic-linker)
> > > +LDFLAGS_vmlinux += -pie $(call ld-option, --no-dynamic-linker)
> > > LDFLAGS_vmlinux := -T
> > >
> > > hostprogs := mkpiggy
> > >
> > > - Sedat -
> >
> > Not my day - today.
> >
> > $ git diff arch/x86/boot/compressed/Makefile
> > diff --git a/arch/x86/boot/compressed/Makefile
> > b/arch/x86/boot/compressed/Makefile
> > index 789d5d14d8b0..9784ed37a5d7 100644
> > --- a/arch/x86/boot/compressed/Makefile
> > +++ b/arch/x86/boot/compressed/Makefile
> > @@ -51,8 +51,8 @@ UBSAN_SANITIZE :=n
> > KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
> > # Compressed kernel should be built as PIE since it may be loaded at any
> > # address by the bootloader.
> > -KBUILD_LDFLAGS += -pie $(call ld-option, --no-dynamic-linker)
> > LDFLAGS_vmlinux := -T
> > +LDFLAGS_vmlinux += -pie $(call ld-option, --no-dynamic-linker)
> >
> > hostprogs := mkpiggy
> > HOST_EXTRACFLAGS += -I$(srctree)/tools/include
> >
> > - Sedat -
>
> Nope -- -T needs to be last, since it's (trickily) put together with the
> first prerequisite $(obj)/vmlinux.lds.
Good I read this.
Checked the previous build-log:
ld.lld-11 -m elf_x86_64 -T arch/x86/boot/compressed/vmlinux.lds
arch/x86/boot/compressed/kernel_info.o
arch/x86/boot/compressed/head_64.o arch/x86/boot/compressed/misc.o
arch/x86/boot/compressed/string.o arch/x86/boot/compressed/cmdline.o
arch/x86/boot/compressed/error.o arch/x86/boot/compressed/piggy.o
arch/x86/boot/compressed/cpuflags.o
arch/x86/boot/compressed/early_serial_console.o
arch/x86/boot/compressed/kaslr.o arch/x86/boot/compressed/kaslr_64.o
arch/x86/boot/compressed/mem_encrypt.o
arch/x86/boot/compressed/pgtable_64.o arch/x86/boot/compressed/acpi.o
drivers/firmware/efi/libstub/lib.a
arch/x86/boot/compressed/efi_thunk_64.o -o
arch/x86/boot/compressed/vmlinux
So there is no -r option in this line.
If we move to LDFLAGS_vmlinux we can drop the "call ld-option" as both
linker GNU/ld.bfd and LLVM/lld.ld support this?
Do we need to adjust the comments?
# Compressed kernel should be built as PIE since it may be loaded at any
# address by the bootloader
That's the minimal change needed:
$ git diff arch/x86/boot/compressed/Makefile
diff --git a/arch/x86/boot/compressed/Makefile
b/arch/x86/boot/compressed/Makefile
index 789d5d14d8b0..d0aafcd8cf6c 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -51,8 +51,8 @@ UBSAN_SANITIZE :=n
KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
# Compressed kernel should be built as PIE since it may be loaded at any
# address by the bootloader.
-KBUILD_LDFLAGS += -pie $(call ld-option, --no-dynamic-linker)
-LDFLAGS_vmlinux := -T
+LDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
+LDFLAGS_vmlinux += -T
hostprogs := mkpiggy
HOST_EXTRACFLAGS += -I$(srctree)/tools/include
- Sedat -
Powered by blists - more mailing lists