aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--support/ld/common.inc32
-rw-r--r--support/make/build-rules.mk13
-rw-r--r--wirish/start.S6
-rw-r--r--wirish/start_c.c13
5 files changed, 44 insertions, 22 deletions
diff --git a/Makefile b/Makefile
index 3c36bec..b1f970c 100644
--- a/Makefile
+++ b/Makefile
@@ -58,7 +58,7 @@ GLOBAL_CFLAGS := -Os -g3 -gdwarf-2 -mcpu=cortex-m3 -mthumb -march=armv7-m \
GLOBAL_CXXFLAGS := -fno-rtti -fno-exceptions -Wall $(TARGET_FLAGS)
GLOBAL_ASFLAGS := -mcpu=cortex-m3 -march=armv7-m -mthumb \
-x assembler-with-cpp $(TARGET_FLAGS)
-LDFLAGS = $(TARGET_LDFLAGS) -mcpu=cortex-m3 -mthumb \
+LDFLAGS = $(TARGET_LDFLAGS) $(TOOLCHAIN_LDFLAGS) -mcpu=cortex-m3 -mthumb \
-Xlinker --gc-sections \
-Xassembler --march=armv7-m -Wall
# -Xlinker --print-gc-sections \
diff --git a/support/ld/common.inc b/support/ld/common.inc
index f749b19..f5a0f5b 100644
--- a/support/ld/common.inc
+++ b/support/ld/common.inc
@@ -5,12 +5,20 @@
*/
OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
-ENTRY(_start)
/*
- * Link against libgcc, libc, and libm
+ * Configure other libraries we want in the link.
+ *
+ * libgcc, libc, and libm are common across supported toolchains.
+ * However, some toolchains require additional archives which aren't
+ * present everywhere (e.g. ARM's gcc-arm-embedded releases).
+ *
+ * To hack around this, we let the build system specify additional
+ * archives by putting the right extra_libs.inc (in a directory under
+ * toolchains/) in our search path.
*/
GROUP(libgcc.a libc.a libm.a)
+INCLUDE extra_libs.inc
/*
* These force the linker to search for vector table symbols.
@@ -35,8 +43,9 @@ EXTERN(__msp_init)
PROVIDE(__msp_init = ORIGIN(ram) + LENGTH(ram));
/* Reset vector and chip reset entry point */
-EXTERN(_start)
-PROVIDE(__exc_reset = _start);
+EXTERN(__start__)
+ENTRY(__start__)
+PROVIDE(__exc_reset = __start__);
/* Heap boundaries, for libmaple */
EXTERN(_lm_heap_start);
@@ -44,10 +53,9 @@ EXTERN(_lm_heap_end);
SECTIONS
{
- /* TODO pull out rodata and stick into separate sections */
.text :
{
- _text = .;
+ __text_start__ = .;
/*
* STM32 vector table. Leave this here. Yes, really.
*/
@@ -107,7 +115,7 @@ SECTIONS
.text.align :
{
. = ALIGN(8);
- _etext = .;
+ __text_end__ = .;
} > REGION_TEXT
/*
@@ -126,13 +134,13 @@ SECTIONS
.data :
{
. = ALIGN(8);
- _data = .;
+ __data_start__ = .;
*(.got.plt) *(.got)
*(.data .data.* .gnu.linkonce.d.*)
. = ALIGN(8);
- _edata = .;
+ __data_end__ = .;
} > REGION_DATA AT> REGION_RODATA
/*
@@ -166,12 +174,12 @@ SECTIONS
.bss :
{
. = ALIGN(8);
- _bss = .;
+ __bss_start__ = .;
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN (8);
- _ebss = .;
- _end = _ebss;
+ __bss_end__ = .;
+ _end = __bss_end__;
} > REGION_BSS
/*
diff --git a/support/make/build-rules.mk b/support/make/build-rules.mk
index 3d541ba..d180c89 100644
--- a/support/make/build-rules.mk
+++ b/support/make/build-rules.mk
@@ -22,6 +22,8 @@ ifndef V
SILENT_OBJDUMP = @echo ' [OBJDUMP] ' $(OBJDUMP);
endif
+# Extra build configuration
+
BUILDDIRS :=
TGT_BIN :=
@@ -29,6 +31,17 @@ CFLAGS = $(GLOBAL_CFLAGS) $(TGT_CFLAGS)
CXXFLAGS = $(GLOBAL_CXXFLAGS) $(TGT_CXXFLAGS)
ASFLAGS = $(GLOBAL_ASFLAGS) $(TGT_ASFLAGS)
+# Hacks to determine extra libraries we need to link against based on
+# the toolchain. The default specifies no extra libraries, but it can
+# be overridden.
+LD_TOOLCHAIN_PATH := $(LDDIR)/toolchains/generic
+ifneq ($(findstring ARM/embedded,$(shell $(CC) --version)),)
+# GCC ARM Embedded, https://launchpad.net/gcc-arm-embedded/
+LD_TOOLCHAIN_PATH := $(LDDIR)/toolchains/gcc-arm-embedded
+endif
+# Add toolchain directory to LD search path
+TOOLCHAIN_LDFLAGS := -L $(LD_TOOLCHAIN_PATH)
+
# General directory independent build rules, generate dependency information
$(BUILD_PATH)/%.o: %.c
$(SILENT_CC) $(CC) $(CFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $<
diff --git a/wirish/start.S b/wirish/start.S
index 2488895..8b181aa 100644
--- a/wirish/start.S
+++ b/wirish/start.S
@@ -44,9 +44,9 @@
.code 16
.thumb_func
- .globl _start
- .type _start, %function
-_start:
+ .globl __start__
+ .type __start__, %function
+__start__:
.fnstart
ldr r1,=__msp_init
mov sp,r1
diff --git a/wirish/start_c.c b/wirish/start_c.c
index 301565c..655fefb 100644
--- a/wirish/start_c.c
+++ b/wirish/start_c.c
@@ -50,8 +50,9 @@ extern int main(int, char**, char**);
extern void exit(int) __attribute__((noreturn, weak));
-extern char _data, _edata;
-extern char _bss, _ebss;
+/* The linker must ensure that these are at least 4-byte aligned. */
+extern char __data_start__, __data_end__;
+extern char __bss_start__, __bss_end__;
struct rom_img_cfg {
int *img_start;
@@ -62,20 +63,20 @@ extern char _lm_rom_img_cfgp;
void __attribute__((noreturn)) start_c(void) {
struct rom_img_cfg *img_cfg = (struct rom_img_cfg*)&_lm_rom_img_cfgp;
int *src = img_cfg->img_start;
- int *dst = (int*)&_data;
+ int *dst = (int*)&__data_start__;
int exit_code;
/* Initialize .data, if necessary. */
if (src != dst) {
- int *end = (int*)&_edata;
+ int *end = (int*)&__data_end__;
while (dst < end) {
*dst++ = *src++;
}
}
/* Zero .bss. */
- dst = (int*)&_bss;
- while (dst < (int*)&_ebss) {
+ dst = (int*)&__bss_start__;
+ while (dst < (int*)&__bss_end__) {
*dst++ = 0;
}