diff --git a/CMakeLists.txt b/CMakeLists.txt index 75b118e..1db42ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,7 +259,7 @@ fxconv_declare_assets(${ASSETS_FX} ${ASSETS_CG}) include_directories( "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include") -add_compile_options(-Wall -Wextra -std=c11 -Os -g -fstrict-volatile-bitfields -mtas) +add_compile_options(-Wall -Wextra -std=c11 -Os -g -fstrict-volatile-bitfields -mtas -flto) if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) add_compile_definitions(FX9860G) @@ -297,6 +297,12 @@ endif() set_target_properties("${NAME}" PROPERTIES OUTPUT_NAME "${NAME}") +# Generate the archive with gcc-ar instead of ar as it will load the LTO plugin +# which is required to generate a usable archive. +set(CMAKE_C_ARCHIVE_CREATE "${CMAKE_C_COMPILER_AR} qcs ") +# Also the ranlib rule (useless because ar is passed the s flag anyway) +set(CMAKE_C_ARCHIVE_FINISH "${CMAKE_C_COMPILER_RANLIB} ") + # Generate linker scripts macro(generate_linker_script OUTPUT INPUT OPTIONS) add_custom_command( diff --git a/fx9860g.ld.c b/fx9860g.ld.c index f86ffa2..a4ac9dc 100644 --- a/fx9860g.ld.c +++ b/fx9860g.ld.c @@ -61,19 +61,19 @@ SECTIONS *(.text.entry) _bctors = . ; - *(.ctors .ctors.*) + KEEP(*(.ctors .ctors.*)) _ectors = . ; _bdtors = . ; - *(.dtors .dtors.*) + KEEP(*(.dtors .dtors.*)) _edtors = . ; _gint_exch_start = . ; - *(.gint.exch) + KEEP(*(.gint.exch)) _gint_exch_size = ABSOLUTE(. - _gint_exch_start); _gint_tlbh_start = . ; - *(.gint.tlbh) + KEEP(*(.gint.tlbh)) _gint_tlbh_size = ABSOLUTE(. - _gint_tlbh_start); *(.text .text.*) diff --git a/fxcg50.ld.c b/fxcg50.ld.c index d6d2753..8ad5e3e 100644 --- a/fxcg50.ld.c +++ b/fxcg50.ld.c @@ -50,19 +50,19 @@ SECTIONS *(.text.entry) _bctors = . ; - *(.ctors .ctors.*) + KEEP(*(.ctors .ctors.*)) _ectors = . ; _bdtors = . ; - *(.dtors .dtors.*) + KEEP(*(.dtors .dtors.*)) _edtors = . ; _gint_exch_start = . ; - *(.gint.exch) + KEEP(*(.gint.exch)) _gint_exch_size = ABSOLUTE(. - _gint_exch_start); _gint_tlbh_start = . ; - *(.gint.tlbh) + KEEP(*(.gint.tlbh)) _gint_tlbh_size = ABSOLUTE(. - _gint_tlbh_start); *(.text .text.*) diff --git a/include/gint/defs/attributes.h b/include/gint/defs/attributes.h index 04cab22..9470f0a 100644 --- a/include/gint/defs/attributes.h +++ b/include/gint/defs/attributes.h @@ -34,6 +34,9 @@ /* Transparent unions */ #define GTRANSPARENT __attribute__((transparent_union)) +/* Functions and globals that are visible through whole-program optimization */ +#define GVISIBLE __attribute__((externally_visible)) + /* Weak symbols */ #define GWEAK __attribute__((weak)) diff --git a/include/gint/drivers.h b/include/gint/drivers.h index e739489..aedf7b6 100644 --- a/include/gint/drivers.h +++ b/include/gint/drivers.h @@ -267,7 +267,7 @@ typedef void **gint_world_t; the section name and the linker then sorts by name. If your driver has a level lower than 10, you must add a leading 0. */ #define GINT_DECLARE_DRIVER(level, name) \ - GSECTION(".gint.drivers." #level) extern gint_driver_t name; + GSECTION(".gint.drivers." #level) GVISIBLE extern gint_driver_t name; //--- // Internal driver control diff --git a/src/kernel/start.c b/src/kernel/start.c index 6c83e3d..7c8cdf1 100644 --- a/src/kernel/start.c +++ b/src/kernel/start.c @@ -34,7 +34,7 @@ extern void (*bctors)(void), (*ectors)(void); extern void (*bdtors)(void), (*edtors)(void); /* User-provided main() function */ -int main(int isappli, int optnum); +int main(void); /* Whether to restart main through the OS menu rather than returning */ int8_t gint_restart = 0; @@ -188,7 +188,10 @@ static int start2(int isappli, int optnum) what it wants in exit() after main() finishes executing */ if(!setjmp(gint_exitbuf)) { callarray(&bctors, &ectors); - exit(main(isappli, optnum)); + // TODO: record isappli and optnum in globals + (void)isappli; + (void)optnum; + exit(main()); } else { callarray(&bdtors, &edtors);