blob: 3ba6c4ef38355351ce7900373a091e8aec91a9a3 [file] [log] [blame]
Patrick Williams8dd68482022-10-04 07:57:18 -05001From ea932656461865ab9ac4036245c756c082aeb3e1 Mon Sep 17 00:00:00 2001
Patrick Williams92b42cb2022-09-03 06:53:57 -05002From: Jerome Forissier <jerome.forissier@linaro.org>
3Date: Tue, 23 Aug 2022 11:41:00 +0000
4Subject: [PATCH] core, ldelf: link: add -z execstack
5
6When building for arm32 with GNU binutils 2.39, the linker outputs
7warnings when generating some TEE core binaries (all_obj.o, init.o,
8unpaged.o and tee.elf) as well as ldelf.elf:
9
10 arm-poky-linux-gnueabi-ld.bfd: warning: atomic_a32.o: missing .note.GNU-stack section implies executable stack
11 arm-poky-linux-gnueabi-ld.bfd: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
12
13The permissions used when mapping the TEE core stacks do not depend on
14any metadata found in the ELF file. Similarly when the TEE core loads
15ldelf it already creates a non-executable stack regardless of ELF
16information. Therefore we can safely ignore the warnings. This is done
17by adding the '-z execstack' option.
18
19Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
20
21Signed-off-by: Anton Antonov <Anton.Antonov@arm.com>
22Upstream-Status: Backport [https://github.com/OP-TEE/optee_os/pull/5499]
23
24---
Patrick Williams8dd68482022-10-04 07:57:18 -050025 core/arch/arm/kernel/link.mk | 13 +++++++++----
26 ldelf/link.mk | 3 +++
27 2 files changed, 12 insertions(+), 4 deletions(-)
28
Patrick Williams92b42cb2022-09-03 06:53:57 -050029diff --git a/core/arch/arm/kernel/link.mk b/core/arch/arm/kernel/link.mk
30index c39d43cb..0e96e606 100644
31--- a/core/arch/arm/kernel/link.mk
32+++ b/core/arch/arm/kernel/link.mk
33@@ -9,6 +9,11 @@ link-script-dep = $(link-out-dir)/.kern.ld.d
34
35 AWK = awk
36
37+link-ldflags-common += $(call ld-option,--no-warn-rwx-segments)
38+ifeq ($(CFG_ARM32_core),y)
39+link-ldflags-common += $(call ld-option,--no-warn-execstack)
40+endif
41+
42 link-ldflags = $(LDFLAGS)
43 ifeq ($(CFG_CORE_ASLR),y)
44 link-ldflags += -pie -Bsymbolic -z norelro $(ldflag-apply-dynamic-relocs)
45@@ -31,7 +36,7 @@ link-ldflags += -T $(link-script-pp) -Map=$(link-out-dir)/tee.map
46 link-ldflags += --sort-section=alignment
47 link-ldflags += --fatal-warnings
48 link-ldflags += --gc-sections
49-link-ldflags += $(call ld-option,--no-warn-rwx-segments)
50+link-ldflags += $(link-ldflags-common)
51
52 link-ldadd = $(LDADD)
53 link-ldadd += $(ldflags-external)
54@@ -56,7 +61,7 @@ link-script-cppflags := \
55 $(cppflagscore))
56
57 ldargs-all_objs := -T $(link-script-dummy) --no-check-sections \
58- $(call ld-option,--no-warn-rwx-segments) \
59+ $(link-ldflags-common) \
60 $(link-objs) $(link-ldadd) $(libgcccore)
61 cleanfiles += $(link-out-dir)/all_objs.o
62 $(link-out-dir)/all_objs.o: $(objs) $(libdeps) $(MAKEFILE_LIST)
63@@ -70,7 +75,7 @@ $(link-out-dir)/unpaged_entries.txt: $(link-out-dir)/all_objs.o
64 $(AWK) '/ ____keep_pager/ { printf "-u%s ", $$3 }' > $@
65
66 unpaged-ldargs := -T $(link-script-dummy) --no-check-sections --gc-sections \
67- $(call ld-option,--no-warn-rwx-segments)
68+ $(link-ldflags-common)
69 unpaged-ldadd := $(objs) $(link-ldadd) $(libgcccore)
70 cleanfiles += $(link-out-dir)/unpaged.o
71 $(link-out-dir)/unpaged.o: $(link-out-dir)/unpaged_entries.txt
72@@ -99,7 +104,7 @@ $(link-out-dir)/init_entries.txt: $(link-out-dir)/all_objs.o
73 $(AWK) '/ ____keep_init/ { printf "-u%s ", $$3 }' > $@
74
75 init-ldargs := -T $(link-script-dummy) --no-check-sections --gc-sections \
76- $(call ld-option,--no-warn-rwx-segments)
77+ $(link-ldflags-common)
78 init-ldadd := $(link-objs-init) $(link-out-dir)/version.o $(link-ldadd) \
79 $(libgcccore)
80 cleanfiles += $(link-out-dir)/init.o
81diff --git a/ldelf/link.mk b/ldelf/link.mk
82index 64c8212a..bd49551e 100644
83--- a/ldelf/link.mk
84+++ b/ldelf/link.mk
85@@ -20,6 +20,9 @@ link-ldflags += -z max-page-size=4096 # OP-TEE always uses 4K alignment
86 ifeq ($(CFG_CORE_BTI),y)
87 link-ldflags += $(call ld-option,-z force-bti) --fatal-warnings
88 endif
89+ifeq ($(CFG_ARM32_$(sm)), y)
90+link-ldflags += $(call ld-option,--no-warn-execstack)
91+endif
92 link-ldflags += $(link-ldflags$(sm))
93
94 link-ldadd = $(addprefix -L,$(libdirs))