]> xenbits.xensource.com Git - people/julieng/boot-wrapper-aarch64.git/commitdiff
Add GCC library functions
authorJean-Philippe Brucker <jean-philippe.brucker@arm.com>
Thu, 17 Dec 2015 14:59:46 +0000 (14:59 +0000)
committerMark Rutland <mark.rutland@arm.com>
Wed, 15 Jun 2016 09:27:35 +0000 (10:27 +0100)
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>
Makefile.am
lib.c [new file with mode: 0644]
model.lds.S

index dd36375e6e44a8c50ed406511b9f670fc939bec1..70dedc22d042d0f3231a7d9d190063abe70e4138 100644 (file)
@@ -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 $@ $<
diff --git a/lib.c b/lib.c
new file mode 100644 (file)
index 0000000..fcf5f69
--- /dev/null
+++ b/lib.c
@@ -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 */
index 235d8c99021be9585f84b2460689a0e7dfc042d4..973866f46fb6460704b8615510074625aad3237c 100644 (file)
@@ -46,7 +46,7 @@ SECTIONS
 
        .boot PHYS_OFFSET: {
                *(.init)
-               *(.text .data .rodata* .bss COMMON)
+               *(.text* .data* .rodata* .bss* COMMON)
                *(.vectors)
                *(.stack)
                *(.pgtables)