blob: 2e3a7119e798b2068d7df74711cb3eca3991eefd [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
wdenk591dda52002-11-18 00:14:45 +00002#
3# (C) Copyright 2000-2002
4# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk591dda52002-11-18 00:14:45 +00005
Graeme Russbed10fa2010-10-07 20:03:23 +11006PLATFORM_CPPFLAGS += -fomit-frame-pointer
Masahiro Yamada4fad1492014-02-26 14:51:01 +09007PF_CPPFLAGS_X86 := $(call cc-option, -fno-toplevel-reorder, \
Bin Meng20358f62017-07-27 06:12:34 -07008 $(call cc-option, -fno-unit-at-a-time))
Ben Stoltzc24aae52015-08-04 12:33:42 -06009
Wolfgang Denk9209ed52011-11-01 20:54:02 +000010PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_X86)
Graeme Russ9381c8a2011-02-12 15:11:21 +110011PLATFORM_CPPFLAGS += -fno-dwarf2-cfi-asm
Simon Glass5aa58752017-01-16 07:04:26 -070012
13ifdef CONFIG_SPL_BUILD
14IS_32BIT := y
15else
16ifndef CONFIG_X86_64
17IS_32BIT := y
18endif
19endif
20
Simon Glass95826f32022-01-04 03:51:16 -070021EFI_IS_32BIT := $(IS_32BIT)
22ifdef CONFIG_EFI_STUB_64BIT
23EFI_IS_32BIT :=
24endif
25
Simon Glass5aa58752017-01-16 07:04:26 -070026ifeq ($(IS_32BIT),y)
Vasili Galka37215b72014-06-10 16:14:56 +030027PLATFORM_CPPFLAGS += -march=i386 -m32
Simon Glass5aa58752017-01-16 07:04:26 -070028else
Bin Mengf50b17c2018-10-13 20:52:01 -070029PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -march=core2 -m64
Simon Glass0b226042024-01-04 08:10:39 -070030
31ifndef CONFIG_X86_HARDFP
Bin Meng58d4bc62018-10-13 20:52:02 -070032PLATFORM_CPPFLAGS += -mno-mmx -mno-sse
Simon Glass5aa58752017-01-16 07:04:26 -070033endif
Graeme Russ9381c8a2011-02-12 15:11:21 +110034
Simon Glass0b226042024-01-04 08:10:39 -070035endif # IS_32BIT
36
Alexander Graf86642972018-08-20 14:20:51 +020037PLATFORM_RELFLAGS += -fdata-sections -ffunction-sections -fvisibility=hidden
Graeme Russ9381c8a2011-02-12 15:11:21 +110038
Tom Rini5d4ecf22020-03-27 11:46:27 -040039KBUILD_LDFLAGS += -Bsymbolic -Bsymbolic-functions
40KBUILD_LDFLAGS += -m $(if $(IS_32BIT),elf_i386,elf_x86_64)
Graeme Russ9381c8a2011-02-12 15:11:21 +110041
Simon Glass63f581f2015-08-04 12:33:52 -060042# This is used in the top-level Makefile which does not include
Tom Rini5d4ecf22020-03-27 11:46:27 -040043# KBUILD_LDFLAGS
Tom Rinie189adf2023-02-14 15:09:32 -050044LDFLAGS_EFI_PAYLOAD := -Bsymbolic -Bsymbolic-functions -shared --no-undefined \
45 -s -zexecstack
Simon Glass63f581f2015-08-04 12:33:52 -060046
Ben Stoltzc24aae52015-08-04 12:33:42 -060047OBJCOPYFLAGS_EFI := -j .text -j .sdata -j .data -j .dynamic -j .dynsym \
Simon Glass408cf262021-09-24 18:30:19 -060048 -j .rel -j .rela -j .reloc --strip-all
Ben Stoltzc24aae52015-08-04 12:33:42 -060049
Heinrich Schuchardteccd86f2021-04-11 11:21:57 +020050# Compiler flags to be added when building UEFI applications
Ben Stoltzc24aae52015-08-04 12:33:42 -060051CFLAGS_EFI := -fpic -fshort-wchar
Heinrich Schuchardteccd86f2021-04-11 11:21:57 +020052# Compiler flags to be removed when building UEFI applications
Joel Peshkin369d87a2021-04-11 11:21:58 +020053CFLAGS_NON_EFI := -mregparm=3 -fstack-protector-strong
Ben Stoltzc24aae52015-08-04 12:33:42 -060054
Simon Glass95826f32022-01-04 03:51:16 -070055ifeq ($(IS_32BIT),y)
56EFIPAYLOAD_BFDARCH = i386
57else
Simon Glassce62a252015-08-04 12:33:56 -060058CFLAGS_EFI += $(call cc-option, -mno-red-zone)
Simon Glass95826f32022-01-04 03:51:16 -070059EFIPAYLOAD_BFDARCH = x86_64
60endif
61
62ifeq ($(EFI_IS_32BIT),y)
Ben Stoltzc24aae52015-08-04 12:33:42 -060063EFIARCH = ia32
Simon Glass63f581f2015-08-04 12:33:52 -060064EFIPAYLOAD_BFDTARGET = elf32-i386
Simon Glassce62a252015-08-04 12:33:56 -060065else
66EFIARCH = x86_64
67EFIPAYLOAD_BFDTARGET = elf64-x86-64
68endif
Simon Glass63f581f2015-08-04 12:33:52 -060069
Simon Glassb776fc02016-11-07 08:47:13 -070070LDSCRIPT_EFI := $(srctree)/arch/x86/lib/elf_$(EFIARCH)_efi.lds
Simon Glass6f4b08a2016-11-07 08:47:14 -070071EFISTUB := crt0_$(EFIARCH)_efi.o reloc_$(EFIARCH)_efi.o
Ben Stoltzc24aae52015-08-04 12:33:42 -060072OBJCOPYFLAGS_EFI += --target=efi-app-$(EFIARCH)
73
Simon Glassce62a252015-08-04 12:33:56 -060074CPPFLAGS_REMOVE_crt0-efi-$(EFIARCH).o += $(CFLAGS_NON_EFI)
75CPPFLAGS_crt0-efi-$(EFIARCH).o += $(CFLAGS_EFI)
76
Ben Stoltzc24aae52015-08-04 12:33:42 -060077ifeq ($(CONFIG_EFI_APP),y)
78
79PLATFORM_CPPFLAGS += $(CFLAGS_EFI)
Simon Glass408cf262021-09-24 18:30:19 -060080LDFLAGS_FINAL += -znocombreloc -shared
Ben Stoltzc24aae52015-08-04 12:33:42 -060081LDSCRIPT := $(LDSCRIPT_EFI)
82
83else
84
Heinrich Schuchardteccd86f2021-04-11 11:21:57 +020085ifeq ($(IS_32BIT),y)
86PLATFORM_CPPFLAGS += -mregparm=3
87endif
Tom Rini5d4ecf22020-03-27 11:46:27 -040088KBUILD_LDFLAGS += --emit-relocs
Simon Glass5aa58752017-01-16 07:04:26 -070089LDFLAGS_FINAL += --gc-sections $(if $(CONFIG_SPL_BUILD),,-pie)
90
91endif
Ben Stoltzc24aae52015-08-04 12:33:42 -060092
Simon Glass5aa58752017-01-16 07:04:26 -070093ifdef CONFIG_X86_64
94ifndef CONFIG_SPL_BUILD
95PLATFORM_CPPFLAGS += -D__x86_64__
96else
97PLATFORM_CPPFLAGS += -D__I386__
98endif
99else
100PLATFORM_CPPFLAGS += -D__I386__
Ben Stoltzc24aae52015-08-04 12:33:42 -0600101endif
Simon Glass105c9362016-11-07 08:47:15 -0700102
Heinrich Schuchardte2425b62018-05-18 19:12:19 +0200103ifdef CONFIG_EFI_STUB
Simon Glass105c9362016-11-07 08:47:15 -0700104
Heinrich Schuchardte2425b62018-05-18 19:12:19 +0200105ifdef CONFIG_EFI_STUB_64BIT
Simon Glass105c9362016-11-07 08:47:15 -0700106EFI_LDS := elf_x86_64_efi.lds
107EFI_CRT0 := crt0_x86_64_efi.o
108EFI_RELOC := reloc_x86_64_efi.o
Simon Glass105c9362016-11-07 08:47:15 -0700109else
110EFI_LDS := elf_ia32_efi.lds
111EFI_CRT0 := crt0_ia32_efi.o
112EFI_RELOC := reloc_ia32_efi.o
Heinrich Schuchardt82182892018-04-06 15:36:31 +0200113endif
114
Heinrich Schuchardte2425b62018-05-18 19:12:19 +0200115else
116
Heinrich Schuchardt82182892018-04-06 15:36:31 +0200117ifdef CONFIG_X86_64
Heinrich Schuchardte2425b62018-05-18 19:12:19 +0200118EFI_LDS := elf_x86_64_efi.lds
119EFI_CRT0 := crt0_x86_64_efi.o
120EFI_RELOC := reloc_x86_64_efi.o
Heinrich Schuchardt82182892018-04-06 15:36:31 +0200121else
Heinrich Schuchardte2425b62018-05-18 19:12:19 +0200122EFI_LDS := elf_ia32_efi.lds
123EFI_CRT0 := crt0_ia32_efi.o
124EFI_RELOC := reloc_ia32_efi.o
125endif
126
Simon Glass105c9362016-11-07 08:47:15 -0700127endif
128
Heinrich Schuchardte2425b62018-05-18 19:12:19 +0200129ifdef CONFIG_X86_64
130EFI_TARGET := --target=efi-app-x86_64
131else
132EFI_TARGET := --target=efi-app-ia32
Simon Glass105c9362016-11-07 08:47:15 -0700133endif