
On Tue, Apr 21, 2020 at 7:28 AM mhorne@freebsd.org wrote:
From: Mitchell Horne mhorne@FreeBSD.org
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 mhorne@FreeBSD.org
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
I think we need put .data before return_addr: to make it clearer.
.align 8 .long 0
#else #error No support for this arch! #endif
.data
And changing these symbols should be a separate patch.
.globl syscall_ptr
syscall_ptr: .align 8
Regards, Bin