From 94ba4f6406957ab4cc68b1239910b66ca01e0188 Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Wed, 10 Apr 2019 16:11:42 +0200 Subject: [PATCH] sparc: fix bootloader executable format - The entry point has to be at the start of the text section - Use the correct formqt ("impure") for the a.out file - Strip all symbols (the bootloader isn't relocatable) Change-Id: I2b973c39eaf1416f874bf1b2668b1e3090eb5f7b Reviewed-on: https://review.haiku-os.org/c/1468 Reviewed-by: waddlesplash --- src/system/boot/Jamfile | 2 +- src/system/boot/platform/openfirmware/start.cpp | 8 +++++++- src/system/ldscripts/sparc/boot_loader_openfirmware.ld | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/system/boot/Jamfile b/src/system/boot/Jamfile index 3541e65466..b89309dc16 100644 --- a/src/system/boot/Jamfile +++ b/src/system/boot/Jamfile @@ -38,7 +38,7 @@ rule BuildAoutLoader { actions BuildAoutLoader { rm -f $(1) - $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O $(AOUT_FORMAT) $(2) $(1) + $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O $(AOUT_FORMAT) --impure -S $(2) $(1) } diff --git a/src/system/boot/platform/openfirmware/start.cpp b/src/system/boot/platform/openfirmware/start.cpp index c699823ecd..a2777e4177 100644 --- a/src/system/boot/platform/openfirmware/start.cpp +++ b/src/system/boot/platform/openfirmware/start.cpp @@ -27,9 +27,11 @@ extern "C" void _start(uint32 _unused1, uint32 _unused2, void *openFirmwareEntry); extern "C" void start(void *openFirmwareEntry); +#ifdef __powerpc__ // XCOFF "entry-point" is actually a pointer to the real code extern "C" void *_coff_start; void *_coff_start = (void *)&_start; +#endif // GCC defined globals extern void (*__ctor_list)(void); @@ -52,11 +54,13 @@ call_ctors(void) } +#ifdef __powerpc__ static void clear_bss(void) { memset(&__bss_start, 0, &_end - &__bss_start); } +#endif static void @@ -134,13 +138,15 @@ platform_boot_options(void) } -extern "C" void +extern "C" void __attribute__((section(".text.start"))) _start(uint32 _unused1, uint32 _unused3, void *openFirmwareEntry) { // According to the PowerPC bindings, OpenFirmware should have created // a stack of 32kB or higher for us at this point +#ifndef __sparc__ clear_bss(); +#endif call_ctors(); // call C++ constructors before doing anything else diff --git a/src/system/ldscripts/sparc/boot_loader_openfirmware.ld b/src/system/ldscripts/sparc/boot_loader_openfirmware.ld index 656f3689a2..3449242731 100644 --- a/src/system/ldscripts/sparc/boot_loader_openfirmware.ld +++ b/src/system/ldscripts/sparc/boot_loader_openfirmware.ld @@ -5,12 +5,13 @@ ENTRY(_start) SECTIONS { - . = 0x202000 + SIZEOF_HEADERS; + . = 0x202000; __text_begin = .; /* text/read-only data */ - .text : { *(.text .text.* .gnu.linkonce.t.*) + .text : { *(.text.start) /* Make sure entry point is at start of file */ + *(.text .text.* .gnu.linkonce.t.*) *(.rodata .rodata.* .gnu.linkonce.r.*) *(.sdata2) }