diff mbox series

[boot-wrapper,v2,1/9] Makefile: Avoid .got section creation

Message ID 20211222181607.1203191-2-andre.przywara@arm.com (mailing list archive)
State New, archived
Headers show
Series Various (build system) fixes | expand

Commit Message

Andre Przywara Dec. 22, 2021, 6:15 p.m. UTC
At the moment we build the boot-wrapper with the default toolchain
settings, which has issues if that is a toolchain targeted to Linux
userland, for instance. Since boot-wrapper is rather simple, we get away
with this, *mostly*, but there is at least one case where this breaks:
Many distributions enable PIE builds by default when building GCC, so by
just calling "gcc" we build the .o files for PIE (although we don't link
them accordingly, since we use "ld" directly).
When we moved the PSCI code from assembly to C, we also introduced
global variables, which a PIE enabled GCC will put into a .got section
(global offset table), to be able to easily relocate them at runtime
(if needed). This section happens to be outside of the memory region
we reserve, so can (and will be) overwritten by Linux at some point.
Doing PSCI calls afterwards does not end well then. "memtest=1" is one
way to trigger this.

To avoid the (in our case pointless) creation of the GOT, we specify
-fno-pic and -fno-pie, to override any potential toolchain default.

This fixes boot-wrapper builds on many distro compilers, for instance
as provided by Ubuntu and Arch Linux.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 Makefile.am | 1 +
 1 file changed, 1 insertion(+)

Comments

Mark Rutland Jan. 7, 2022, 1:49 p.m. UTC | #1
On Wed, Dec 22, 2021 at 06:15:59PM +0000, Andre Przywara wrote:
> At the moment we build the boot-wrapper with the default toolchain
> settings, which has issues if that is a toolchain targeted to Linux
> userland, for instance. Since boot-wrapper is rather simple, we get away
> with this, *mostly*, but there is at least one case where this breaks:
> Many distributions enable PIE builds by default when building GCC, so by
> just calling "gcc" we build the .o files for PIE (although we don't link
> them accordingly, since we use "ld" directly).
> When we moved the PSCI code from assembly to C, we also introduced
> global variables, which a PIE enabled GCC will put into a .got section
> (global offset table), to be able to easily relocate them at runtime
> (if needed). This section happens to be outside of the memory region
> we reserve, so can (and will be) overwritten by Linux at some point.
> Doing PSCI calls afterwards does not end well then. "memtest=1" is one
> way to trigger this.
> 
> To avoid the (in our case pointless) creation of the GOT, we specify
> -fno-pic and -fno-pie, to override any potential toolchain default.
> 
> This fixes boot-wrapper builds on many distro compilers, for instance
> as provided by Ubuntu and Arch Linux.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>

Thanks; applied.

Mark.

> ---
>  Makefile.am | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Makefile.am b/Makefile.am
> index d0a68df..3e970a3 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -126,6 +126,7 @@ CPPFLAGS	+= $(INITRD_FLAGS)
>  CFLAGS		+= -I$(top_srcdir)/include/ -I$(top_srcdir)/$(ARCH_SRC)/include/
>  CFLAGS		+= -Wall -fomit-frame-pointer
>  CFLAGS		+= -ffunction-sections -fdata-sections
> +CFLAGS		+= -fno-pic -fno-pie
>  LDFLAGS		+= --gc-sections
>  
>  OBJ		:= $(addprefix $(ARCH_SRC),$(ARCH_OBJ)) $(addprefix $(COMMON_SRC),$(COMMON_OBJ))
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/Makefile.am b/Makefile.am
index d0a68df..3e970a3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -126,6 +126,7 @@  CPPFLAGS	+= $(INITRD_FLAGS)
 CFLAGS		+= -I$(top_srcdir)/include/ -I$(top_srcdir)/$(ARCH_SRC)/include/
 CFLAGS		+= -Wall -fomit-frame-pointer
 CFLAGS		+= -ffunction-sections -fdata-sections
+CFLAGS		+= -fno-pic -fno-pie
 LDFLAGS		+= --gc-sections
 
 OBJ		:= $(addprefix $(ARCH_SRC),$(ARCH_OBJ)) $(addprefix $(COMMON_SRC),$(COMMON_OBJ))