When I try to compile I get this error: boot.s:18: multiple definition of `_start';

0

I'm trying to create my own OS for the raspberry pi but whenever I try to compile it using the ARM win32 Cross Compiler using a make file I get this error:

c:/superpi/superpios/build/gcc-arm-none-eabi-10-2020-q4-major-win32/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: objects/boot.o: in function `_start':
C:\SuperPi\SuperPiOS\build/../src/kernel/boot.s:18: multiple definition of `_start'; objects/boot.o:C:\SuperPi\SuperPiOS\build/../src/kernel/boot.s:18: first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:54: build] Error 1

I've tried to fix it by removing the: .globl _start But that didn't seem to work it just gave me another error saying:

gcc-arm-none-eabi-10-2020-q4-major-win32/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: cannot find entry symbol _start; defaulting to 00008000

Here's the boot.s script:

.equ KERNEL_STACK_SIZE, 4096
// To keep this in the first portion of the binary.

.section ".text.boot"
// Make _start global.

// Entry point for the kernel.
// r15 -> should begin execution at 0x8000.
// r0 -> 0x00000000
// r1 -> 0x00000C42
// r2 -> 0x00000100 - start of ATAGS
// preserve these registers as argument for kernel_main
.globl _start
_start:
    // This set of instructions sets 3 of the 4 cores to go to halt.
    // Model 1 only has 1 cpu and does not have this instruction, so don't include it if building for model 1
#ifndef MODEL_1
    mrc p15, #0, r1, c0, c0, #5
    and r1, r1, #3
    cmp r1, #0
    bne halt
#endif
    // Setup the stack.  Stack will be 32 KB above kernel image
    ldr sp, =__end
    mov r4, #(KERNEL_STACK_SIZE)
    add sp, sp, r4

    // Clear out bss.
    ldr r4, =__bss_start
    ldr r9, =__bss_end
    mov r5, #0
    mov r6, #0
    mov r7, #0
    mov r8, #0
    b       2f

1:
    // store multiple at r4.
    stmia r4!, {r5-r8}

// If we are still below bss_end, loop.
2:
    cmp r4, r9
    blo 1b

    // Call kernel_main
    mov r2, #0x100
    bl kernel_main
    b halt

// halt
halt:
    wfe
    b halt

Oh and here's the makefile:

# Don't use normal gcc, use the arm cross compiler
TOOLCHAIN = ./gcc-arm-none-eabi-10-2020-q4-major-win32/bin/arm-none-eabi
CC = $(TOOLCHAIN)-gcc
OBJCOPY = $(TOOLCHAIN)-objcopy
GDB = $(TOOLCHAIN)-gdb


# Set any constants based on the raspberry pi model.  Version 1 has some differences to 2 and 3
ifeq ($(RASPI_MODEL),4)
    CPU = arm1176jzf-s
    DIRECTIVES = -D MODEL_4
    ARCHDIR = model4
else
    CPU = cortex-a7
    ARCHDIR = model2
endif

CFLAGS= -mcpu=$(CPU) -fpic -ffreestanding $(DIRECTIVES) -g
CXXFLAGS= -ggdb3 -O0
CSRCFLAGS= -O2 -Wall -Wextra
LFLAGS= -ffreestanding -O2 -nostdlib
ASMCFLAGS= -f elf32 -F dwarf -g -w+all
ASM= -s

# Location of the files
KER_SRC = ../src/kernel
KER_MENU_SRC = ../src/kernel/menu
KER_HEAD = ../include
COMMON_SRC = ../src/common
UI_IMAGES = ..images/ui
OBJ_DIR = objects
ASMSOURCES = $(wildcard $(KER_SRC)/*.s)
KERSOURCES = $(wildcard $(KER_SRC)/*.c)
#KERSOURCES = $(wildcard $(KER_SRC)/$(ARCHDIR)/*.c)
COMMONSOURCES = $(wildcard $(COMMON_SRC)/*.c)
KERSOURCESCPP = $(wildcard $(KER_SRC)/*.cpp)
#KERSOURCESCPP = $(wildcard $(KER_SRC)/$(ARCHDIR)/*.cpp)
#KERMENUSOURCESC = $(wildcard $(KER_MENU_SRC)/*.c)
#KERMENUSOURCESCPP = $(wildcard $(KER_MENU_SRC)/*.cpp)
UISOURCES = $(wildcard $(UI_IMAGES)/*.png)
OBJECTS = $(patsubst $(KER_SRC)/%.s, $(OBJ_DIR)/%.o, $(ASMSOURCES))
OBJECTS += $(patsubst $(KER_SRC)/%.s, $(OBJ_DIR)/%.o, $(ASMSOURCES))
OBJECTS += $(patsubst $(KER_SRC)/%.c, $(OBJ_DIR)/%.o, $(KERSOURCES))
OBJECTS += $(patsubst $(KER_SRC)/%.cpp, $(OBJ_DIR)/%.o, $(KERSOURCESCPP))
OBJECTS += $(patsubst $(COMMON_SRC)/%.c, $(OBJ_DIR)/%.o, $(COMMONSOURCES))
#OBJECTS += $(patsubst $(KER_MENU_SRC)/%.c, $(OBJ_DIR)/%.o, $(KERMENUSOURCESC))
#OBJECTS += $(patsubst $(KER_MENU_SRC)/%.cpp, $(OBJ_DIR)/%.o, $(KERMENUSOURCESCPP))
OBJECTS += $(patsubst $(UI_IMAGES)/%.png, $(OBJ_DIR)/%.o, $(UISOURCES))
HEADERS = $(wildcard $(KER_HEAD)/*.h)

IMG_NAME=SuperPiOS

build: $(OBJECTS) $(HEADERS)
    $(CC) -T linker.ld -o $(IMG_NAME).elf $(LFLAGS) $(OBJECTS)
    $(OBJCOPY) $(IMG_NAME).elf -O binary $(IMG_NAME).img

$(OBJ_DIR)/%.o: $(KER_SRC)/%.s
    mkdir -p $(@D)
    $(CC) $(CFLAGS) -I$(KER_SRC) -c $< -o $@

$(OBJ_DIR)/%.o: $(KER_SRC)/%.c
    mkdir -p $(@D)
    $(CC) $(CFLAGS) -I$(KER_SRC) -I$(KER_HEAD) -c $< -o $@ $(CSRCFLAGS)

$(OBJ_DIR)/%.o: $(KER_SRC)/$(ARCHDIR)/%.c
    mkdir -p $(@D)
    $(CC) $(CFLAGS) -I$(KER_SRC) -I$(KER_HEAD) -c $< -o $@ $(CSRCFLAGS)

$(OBJ_DIR)/%.o: $(KER_SRC)/%.cpp
    mkdir -p $(@D)
    $(CC) $(CXXFLAGS) -I$(KER_SRC) -I$(KER_HEAD) -c $< -o $@ $(CSRCFLAGS)

$(OBJ_DIR)/%.o: $(KER_SRC)/$(ARCHDIR)/%.cpp
    mkdir -p $(@D)
    $(CC) $(CXXFLAGS) -I$(KER_SRC) -I$(KER_HEAD) -c $< -o $@ $(CSRCFLAGS)

$(OBJ_DIR)/%.o: $(COMMON_SRC)/%.c
    mkdir -p $(@D)
    $(CC) $(CFLAGS) -I$(KER_SRC) -I$(KER_HEAD) -c $< -o $@ $(CSRCFLAGS)

#$(OBJ_DIR)/%.o: $(KER_MENU_SRC)/%.c
#   mkdir -p $(@D)
#   $(CC) $(CFLAGS) -I$(KER_SRC) -I$(KER_HEAD) -c $< -o $@ $(CSRCFLAGS)

#$(OBJ_DIR)/%.o: $(KER_MENU_SRC)/%.cpp
#   mkdir -p $(@D)
#   $(CC) $(CXXFLAGS) -I$(KER_SRC) -I$(KER_HEAD) -c $< -o $@ $(CSRCFLAGS)

clean:
    rm -rf $(OBJ_DIR)
    rm $(IMG_NAME).elf
    rm $(IMG_NAME).img

run: build
    qemu-system-arm -m 128 -no-reboot -M raspi4 -serial stdio -kernel kernel.elf

dbg:
    $(GDB) kernel.elf
dbgrun: build gdbinit
    qemu-system-arm -m 128 -no-reboot -M raspi4 -serial stdio -kernel kernel.elf -S -s

.PHONY: gdbinit
gdbinit:
    echo "target remote localhost:1234" > .gdbinit
    echo "break kernel_main" >> .gdbinit
assembly
raspberry-pi
operating-system
cross-compiling
asked on Stack Overflow Apr 30, 2021 by Sammyueru • edited Apr 30, 2021 by Sammyueru

1 Answer

1

So the problem was that I had linked the asm files twice so I commented out the second one Before:

OBJECTS = $(patsubst $(KER_SRC)/%.s, $(OBJ_DIR)/%.o, $(ASMSOURCES))
OBJECTS += $(patsubst $(KER_SRC)/%.s, $(OBJ_DIR)/%.o, $(ASMSOURCES))

After:

OBJECTS = $(patsubst $(KER_SRC)/%.s, $(OBJ_DIR)/%.o, $(ASMSOURCES))
#OBJECTS += $(patsubst $(KER_SRC)/%.s, $(OBJ_DIR)/%.o, $(ASMSOURCES))
answered on Stack Overflow Apr 30, 2021 by Sammyueru

User contributions licensed under CC BY-SA 3.0