1link-script$(sm) = ldelf/ldelf.ld.S
2link-script-pp$(sm) = $(link-out-dir$(sm))/ldelf.lds
3link-script-dep$(sm) = $(link-out-dir$(sm))/.ldelf.ld.d
4
5.PHONY: ldelf
6ldelf: $(link-out-dir$(sm))/ldelf.dmp
7ldelf: $(link-out-dir$(sm))/ldelf.elf
8all: ldelf
9
10cleanfiles += $(link-out-dir$(sm))/ldelf.dmp
11cleanfiles += $(link-out-dir$(sm))/ldelf.map
12cleanfiles += $(link-out-dir$(sm))/ldelf.elf
13cleanfiles += $(link-script-pp$(sm)) $(link-script-dep$(sm))
14
15link-ldflags  = -pie -static --gc-sections
16link-ldflags += -T $(link-script-pp$(sm))
17link-ldflags += -Map=$(link-out-dir$(sm))/ldelf.map
18link-ldflags += --sort-section=alignment
19link-ldflags += -z max-page-size=4096 # OP-TEE always uses 4K alignment
20ifeq ($(CFG_CORE_BTI),y)
21link-ldflags += $(call ld-option,-z force-bti) --fatal-warnings
22endif
23ifeq ($(CFG_ARM32_$(sm)), y)
24link-ldflags += $(call ld-option,--no-warn-execstack)
25endif
26link-ldflags += $(link-ldflags$(sm))
27
28link-ldadd  = $(addprefix -L,$(libdirs))
29link-ldadd += --start-group $(addprefix -l,$(libnames)) --end-group
30ldargs-ldelf.elf := $(link-ldflags) $(objs) $(link-ldadd) $(libgcc$(sm))
31
32link-script-cppflags-$(sm) := \
33	$(filter-out $(CPPFLAGS_REMOVE) $(cppflags-remove), \
34		$(nostdinc$(sm)) $(CPPFLAGS) \
35		$(addprefix -I,$(incdirs$(sm)) $(link-out-dir$(sm))) \
36		$(cppflags$(sm)))
37
38-include $(link-script-dep$(sm))
39
40link-script-pp-makefiles$(sm) = $(filter-out %.d %.cmd,$(MAKEFILE_LIST))
41
42define gen-link-t
43$(link-script-pp$(sm)): $(link-script$(sm)) $(conf-file) \
44			$(link-script-pp-makefiles$(sm))
45	@$(cmd-echo-silent) '  CPP     $$@'
46	$(q)mkdir -p $$(dir $$@)
47	$(q)$(CPP$(sm)) -P -MT $$@ -MD -MF $(link-script-dep$(sm)) \
48		$(link-script-cppflags-$(sm)) $$< -o $$@
49
50$(link-out-dir$(sm))/ldelf.elf: $(objs) $(libdeps) $(link-script-pp$(sm))
51	@$(cmd-echo-silent) '  LD      $$@'
52	$(q)$(LD$(sm)) $(ldargs-ldelf.elf) -o $$@
53
54$(link-out-dir$(sm))/ldelf.dmp: $(link-out-dir$(sm))/ldelf.elf
55	@$(cmd-echo-silent) '  OBJDUMP $$@'
56	$(q)$(OBJDUMP$(sm)) -l -x -d $$< > $$@
57endef
58
59$(eval $(call gen-link-t))
60