blob: 26ec1af2f0b09e008c0a0ce5e916f5170dd8e6fe [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
wdenk2262cfe2002-11-18 00:14:45 +00002#
3# (C) Copyright 2000-2002
4# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk2262cfe2002-11-18 00:14:45 +00005
Graeme Russ5c161652010-10-07 20:03:23 +11006PLATFORM_CPPFLAGS += -fomit-frame-pointer
Masahiro Yamadaf6941832014-02-26 14:51:01 +09007PF_CPPFLAGS_X86 := $(call cc-option, -fno-toplevel-reorder, \
Bin Meng9a95f512017-07-27 06:12:34 -07008 $(call cc-option, -fno-unit-at-a-time))
Ben Stoltz3f1c0462015-08-04 12:33:42 -06009
Wolfgang Denkcca4e4a2011-11-01 20:54:02 +000010PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_X86)
Graeme Russa85f53c2011-02-12 15:11:21 +110011PLATFORM_CPPFLAGS += -fno-dwarf2-cfi-asm
Simon Glass3a037032017-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 Glass081dfcf2022-01-04 03:51:16 -070021EFI_IS_32BIT := $(IS_32BIT)
22ifdef CONFIG_EFI_STUB_64BIT
23EFI_IS_32BIT :=
24endif
25
Simon Glass3a037032017-01-16 07:04:26 -070026ifeq ($(IS_32BIT),y)
Vasili Galkadbb72342014-06-10 16:14:56 +030027PLATFORM_CPPFLAGS += -march=i386 -m32
Simon Glass3a037032017-01-16 07:04:26 -070028else
Bin Menga139cc12018-10-13 20:52:01 -070029PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -march=core2 -m64
Bin Mengdd4611d2018-10-13 20:52:02 -070030PLATFORM_CPPFLAGS += -mno-mmx -mno-sse
Simon Glass3a037032017-01-16 07:04:26 -070031endif
Graeme Russd664adb2010-10-07 20:03:20 +110032
Alexander Graf1acbd0e2018-08-20 14:20:51 +020033PLATFORM_RELFLAGS += -fdata-sections -ffunction-sections -fvisibility=hidden
Graeme Russa85f53c2011-02-12 15:11:21 +110034
Tom Rini587e4a42020-03-27 11:46:27 -040035KBUILD_LDFLAGS += -Bsymbolic -Bsymbolic-functions
36KBUILD_LDFLAGS += -m $(if $(IS_32BIT),elf_i386,elf_x86_64)
Graeme Russa85f53c2011-02-12 15:11:21 +110037
Simon Glass476476e2015-08-04 12:33:52 -060038# This is used in the top-level Makefile which does not include
Tom Rini587e4a42020-03-27 11:46:27 -040039# KBUILD_LDFLAGS
Tom Rinid85bc192023-02-14 15:09:32 -050040LDFLAGS_EFI_PAYLOAD := -Bsymbolic -Bsymbolic-functions -shared --no-undefined \
41 -s -zexecstack
Simon Glass476476e2015-08-04 12:33:52 -060042
Ben Stoltz3f1c0462015-08-04 12:33:42 -060043OBJCOPYFLAGS_EFI := -j .text -j .sdata -j .data -j .dynamic -j .dynsym \
Simon Glass8d767442021-09-24 18:30:19 -060044 -j .rel -j .rela -j .reloc --strip-all
Ben Stoltz3f1c0462015-08-04 12:33:42 -060045
Heinrich Schuchardt1598c832021-04-11 11:21:57 +020046# Compiler flags to be added when building UEFI applications
Ben Stoltz3f1c0462015-08-04 12:33:42 -060047CFLAGS_EFI := -fpic -fshort-wchar
Heinrich Schuchardt1598c832021-04-11 11:21:57 +020048# Compiler flags to be removed when building UEFI applications
Joel Peshkin4e9bce12021-04-11 11:21:58 +020049CFLAGS_NON_EFI := -mregparm=3 -fstack-protector-strong
Ben Stoltz3f1c0462015-08-04 12:33:42 -060050
Simon Glass081dfcf2022-01-04 03:51:16 -070051ifeq ($(IS_32BIT),y)
52EFIPAYLOAD_BFDARCH = i386
53else
Simon Glass96a8d402015-08-04 12:33:56 -060054CFLAGS_EFI += $(call cc-option, -mno-red-zone)
Simon Glass081dfcf2022-01-04 03:51:16 -070055EFIPAYLOAD_BFDARCH = x86_64
56endif
57
58ifeq ($(EFI_IS_32BIT),y)
Ben Stoltz3f1c0462015-08-04 12:33:42 -060059EFIARCH = ia32
Simon Glass476476e2015-08-04 12:33:52 -060060EFIPAYLOAD_BFDTARGET = elf32-i386
Simon Glass96a8d402015-08-04 12:33:56 -060061else
62EFIARCH = x86_64
63EFIPAYLOAD_BFDTARGET = elf64-x86-64
64endif
Simon Glass476476e2015-08-04 12:33:52 -060065
Simon Glassd36badf2016-11-07 08:47:13 -070066LDSCRIPT_EFI := $(srctree)/arch/x86/lib/elf_$(EFIARCH)_efi.lds
Simon Glass2dcd4e92016-11-07 08:47:14 -070067EFISTUB := crt0_$(EFIARCH)_efi.o reloc_$(EFIARCH)_efi.o
Ben Stoltz3f1c0462015-08-04 12:33:42 -060068OBJCOPYFLAGS_EFI += --target=efi-app-$(EFIARCH)
69
Simon Glass96a8d402015-08-04 12:33:56 -060070CPPFLAGS_REMOVE_crt0-efi-$(EFIARCH).o += $(CFLAGS_NON_EFI)
71CPPFLAGS_crt0-efi-$(EFIARCH).o += $(CFLAGS_EFI)
72
Ben Stoltz3f1c0462015-08-04 12:33:42 -060073ifeq ($(CONFIG_EFI_APP),y)
74
75PLATFORM_CPPFLAGS += $(CFLAGS_EFI)
Simon Glass8d767442021-09-24 18:30:19 -060076LDFLAGS_FINAL += -znocombreloc -shared
Ben Stoltz3f1c0462015-08-04 12:33:42 -060077LDSCRIPT := $(LDSCRIPT_EFI)
78
79else
80
Heinrich Schuchardt1598c832021-04-11 11:21:57 +020081ifeq ($(IS_32BIT),y)
82PLATFORM_CPPFLAGS += -mregparm=3
83endif
Tom Rini587e4a42020-03-27 11:46:27 -040084KBUILD_LDFLAGS += --emit-relocs
Simon Glass3a037032017-01-16 07:04:26 -070085LDFLAGS_FINAL += --gc-sections $(if $(CONFIG_SPL_BUILD),,-pie)
Ben Stoltz3f1c0462015-08-04 12:33:42 -060086
87endif
Simon Glass5bd828b2016-11-07 08:47:15 -070088
Simon Glass3a037032017-01-16 07:04:26 -070089ifdef CONFIG_X86_64
90ifndef CONFIG_SPL_BUILD
91PLATFORM_CPPFLAGS += -D__x86_64__
92else
93PLATFORM_CPPFLAGS += -D__I386__
94endif
95else
96PLATFORM_CPPFLAGS += -D__I386__
97endif
98
Heinrich Schuchardt508d8562018-05-18 19:12:19 +020099ifdef CONFIG_EFI_STUB
Simon Glass5bd828b2016-11-07 08:47:15 -0700100
Heinrich Schuchardt508d8562018-05-18 19:12:19 +0200101ifdef CONFIG_EFI_STUB_64BIT
Simon Glass5bd828b2016-11-07 08:47:15 -0700102EFI_LDS := elf_x86_64_efi.lds
103EFI_CRT0 := crt0_x86_64_efi.o
104EFI_RELOC := reloc_x86_64_efi.o
Simon Glass5bd828b2016-11-07 08:47:15 -0700105else
106EFI_LDS := elf_ia32_efi.lds
107EFI_CRT0 := crt0_ia32_efi.o
108EFI_RELOC := reloc_ia32_efi.o
Heinrich Schuchardtf4cf1532018-04-06 15:36:31 +0200109endif
110
Heinrich Schuchardt508d8562018-05-18 19:12:19 +0200111else
112
113ifdef CONFIG_X86_64
114EFI_LDS := elf_x86_64_efi.lds
115EFI_CRT0 := crt0_x86_64_efi.o
116EFI_RELOC := reloc_x86_64_efi.o
117else
118EFI_LDS := elf_ia32_efi.lds
119EFI_CRT0 := crt0_ia32_efi.o
120EFI_RELOC := reloc_ia32_efi.o
121endif
122
123endif
124
Heinrich Schuchardtf4cf1532018-04-06 15:36:31 +0200125ifdef CONFIG_X86_64
Simon Glass5bd828b2016-11-07 08:47:15 -0700126EFI_TARGET := --target=efi-app-x86_64
Heinrich Schuchardtf4cf1532018-04-06 15:36:31 +0200127else
128EFI_TARGET := --target=efi-app-ia32
Simon Glass5bd828b2016-11-07 08:47:15 -0700129endif