diff options
author | Jean-Philippe Brucker <jean-philippe.brucker@arm.com> | 2015-12-17 14:59:46 +0000 |
---|---|---|
committer | Mark Rutland <mark.rutland@arm.com> | 2016-06-15 10:27:35 +0100 |
commit | 5714dbb8b62ac25f336e5256dcc2fd8fe7c37b1b (patch) | |
tree | b951ea36df5e0977e6bf2e3ee31467d2c5b5fbd4 | |
parent | f730ba47d27c6f56dd9cc2c86cf895303ff0d8d6 (diff) | |
download | boot-wrapper-aarch64-5714dbb8b62ac25f336e5256dcc2fd8fe7c37b1b.tar.gz |
Add GCC library functions
GCC might generate implicit calls to standard functions, for example
memcpy when copying a struct. Implement these functions upfront, to
ensure that GCC never uses some optimized version, which could do
unaligned device memory accesses. We only implement memcpy and memset
for the moment. The others (memmove, memcmp, ...) can be added in the
future if required.
We also add flags "-ffunction-sections", "-fdata-sections" to GCC, and
"--gc-sections" to ld, in order to avoid linking those functions into
the final image when they aren't used.
Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | lib.c | 35 | ||||
-rw-r--r-- | model.lds.S | 2 |
3 files changed, 40 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am index dd36375..70dedc2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -89,8 +89,10 @@ endif CPPFLAGS += $(INITRD_FLAGS) CFLAGS += -Iinclude/ -I$(ARCH_SRC)/include/ CFLAGS += -Wall -fomit-frame-pointer +CFLAGS += -ffunction-sections -fdata-sections +LDFLAGS += --gc-sections -OFILES += boot_common.o ns.o $(GIC) cache.o +OFILES += boot_common.o ns.o $(GIC) cache.o lib.o OFILES += $(addprefix $(ARCH_SRC),boot.o stack.o mmu.o $(BOOTMETHOD) utils.o) all: $(IMAGE) @@ -98,7 +100,7 @@ all: $(IMAGE) CLEANFILES = $(IMAGE) $(OFILES) model.lds fdt.dtb $(IMAGE): $(OFILES) model.lds fdt.dtb $(KERNEL_IMAGE) $(FILESYSTEM) - $(LD) $(OFILES) -o $@ --script=model.lds + $(LD) $(LDFLAGS) $(OFILES) -o $@ --script=model.lds %.o: %.S Makefile $(CC) $(CPPFLAGS) -D__ASSEMBLY__ $(CFLAGS) $(DEFINES) -c -o $@ $< @@ -0,0 +1,35 @@ +/* + * lib.c - Standard utilities that might be needed by GCC + * + * Copyright (C) 2015 ARM Limited. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE.txt file. + */ + +#include <stddef.h> + +void *memcpy(void *dest, const void *src, size_t n) +{ + int i; + char *cdest = dest; + const char *csrc = src; + + for (i = 0; i < n; i++) + cdest[i] = csrc[i]; + + return dest; +} + +void *memset(void *s, int c, size_t n) +{ + int i; + char *cs = s; + + for (i = 0; i < n; i++) + cs[i] = c; + + return s; +} + +/* TODO: memmove and memcmp could also be called */ diff --git a/model.lds.S b/model.lds.S index 235d8c9..973866f 100644 --- a/model.lds.S +++ b/model.lds.S @@ -46,7 +46,7 @@ SECTIONS .boot PHYS_OFFSET: { *(.init) - *(.text .data .rodata* .bss COMMON) + *(.text* .data* .rodata* .bss* COMMON) *(.vectors) *(.stack) *(.pgtables) |