Skip to content

Commit 388f411

Browse files
author
Hubert Badocha
committed
fix(build): remove program headers from first loadable segment
Program headers should not be loaded into kernel as there is no use for them. Previously starting kernel at start of memory region required explicit linker script. JIRA: RTOS-910
1 parent b8de910 commit 388f411

2 files changed

Lines changed: 14 additions & 215 deletions

File tree

Makefile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,22 @@ include log/Makefile
5353
DEPS := $(patsubst %.o, %.c.d, $(OBJS))
5454
-include $(DEPS)
5555

56-
$(PREFIX_PROG)phoenix-$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).elf: $(OBJS)
56+
57+
# By default ld adds program headers to first LOAD segment.
58+
# However, in kernel headers are not used and it is expected that kernel address space starts at _start.
59+
# This target creates linker script that do not add program headers into the first loadable segment.
60+
# 1) Get internal linker script with prefix and suffix containing noise.
61+
# 2) Match only internal linker script which is between two lines of =
62+
# 3) Remove those lines
63+
# 4) Remove "+ SIZEOF_HEADERS", which causes inclusion of program headers.
64+
$(PREFIX_O)$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).ldt:
65+
$(SIL)$(LD) $(LDFLAGS_PREFIX)--verbose 2>/dev/null | sed -n '/^==*$$/,/^==*$$/p' | sed '1,1d; $$d' | sed s/"\s*+\s*SIZEOF_HEADERS"// > "$@"
66+
67+
68+
$(PREFIX_PROG)phoenix-$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).elf: $(OBJS) $(PREFIX_O)$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).ldt
5769
@mkdir -p $(@D)
5870
@(printf "LD %-24s\n" "$(@F)");
59-
ifeq ($(TARGET_FAMILY),sparcv8leon3)
60-
$(SIL)$(LD) $(CFLAGS) $(LDFLAGS) -nostdlib -e _start -Wl,--section-start,.init=$(VADDR_KERNEL_INIT) -o $@ $(OBJS) -lgcc -T ld/sparcv8leon3.ld
61-
else
62-
$(SIL)$(LD) $(CFLAGS) $(LDFLAGS) -nostdlib -e _start -Wl,--section-start,.init=$(VADDR_KERNEL_INIT) -o $@ $(OBJS) -lgcc
63-
endif
71+
$(SIL)$(LD) $(CFLAGS) $(LDFLAGS) -nostdlib -e _start -Wl,--section-start,.init=$(VADDR_KERNEL_INIT) -o $@ $(OBJS) -lgcc -T $(PREFIX_O)$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).ldt
6472

6573
install-headers: $(EXTERNAL_HEADERS)
6674
@printf "Installing kernel headers\n"

ld/sparcv8leon3.ld

Lines changed: 0 additions & 209 deletions
This file was deleted.

0 commit comments

Comments
 (0)