From patchwork Mon Apr 20 22:34:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Horne X-Patchwork-Id: 238136 List-Id: U-Boot discussion From: mhorne at FreeBSD.org (mhorne at FreeBSD.org) Date: Mon, 20 Apr 2020 18:34:14 -0400 Subject: [PATCH 3/7] examples: add a linker script for the API demo In-Reply-To: <20200420223418.117186-1-mhorne@FreeBSD.org> References: <20200420223418.117186-1-mhorne@FreeBSD.org> Message-ID: <20200420223418.117186-4-mhorne@FreeBSD.org> From: Mitchell Horne When compiling the API demo program, the first object file in the linker arguments is crt0.o, which contains the _start routine. This is done with the hope that it will appear first in the .text section, but the linker doesn't guarantee this behaviour. Add a simple linker script that ensures this ordering. This fixes execution of the API demo binary for cases where _start was placed elsewhere in the .text section. Signed-off-by: Mitchell Horne --- examples/api/Makefile | 4 +++- examples/api/crt0.S | 2 ++ examples/api/demo.lds | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 examples/api/demo.lds diff --git a/examples/api/Makefile b/examples/api/Makefile index 9ff793206f..8fa9c04118 100644 --- a/examples/api/Makefile +++ b/examples/api/Makefile @@ -48,10 +48,12 @@ OBJS := $(OBJ-y) $(notdir $(EXT_COBJ-y) $(EXT_SOBJ-y)) targets += $(OBJS) OBJS := $(addprefix $(obj)/,$(OBJS)) +LDS = $(obj)/demo.lds ######################################################################### quiet_cmd_link_demo = LD $@ -cmd_link_demo = $(LD) --gc-sections -Ttext $(LOAD_ADDR) -o $@ $(filter-out $(PHONY), $^) $(PLATFORM_LIBS) +cmd_link_demo = $(LD) --gc-sections -Ttext $(LOAD_ADDR) -T $(LDS) \ + -o $@ $(filter-out $(PHONY), $^) $(PLATFORM_LIBS) $(obj)/demo: $(OBJS) FORCE $(call if_changed,link_demo) diff --git a/examples/api/crt0.S b/examples/api/crt0.S index 2f75f5a036..658bc59a82 100644 --- a/examples/api/crt0.S +++ b/examples/api/crt0.S @@ -62,12 +62,14 @@ syscall: .end syscall return_addr: + .data .align 8 .long 0 #else #error No support for this arch! #endif + .data .globl syscall_ptr syscall_ptr: .align 8 diff --git a/examples/api/demo.lds b/examples/api/demo.lds new file mode 100644 index 0000000000..a6b88dedef --- /dev/null +++ b/examples/api/demo.lds @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2020 Mitchell Horne + */ + +ENTRY(_start) +SECTIONS +{ + .text : + { + *crt0.S(.text*) + *(.text*) + } +}