Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions backends/arm/cmake/ArmRunnerUtilsInternal.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ function(arm_runner_configure_ethos_u_platform)
add_corstone_subdirectory(
"${ARG_SYSTEM_CONFIG}" "${ARG_SDK_PATH}" "${ARG_MEMORY_MODE}"
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND TARGET ethosu_target_link)
get_target_property(
_ethosu_target_link_options ethosu_target_link INTERFACE_LINK_OPTIONS
)
list(REMOVE_ITEM _ethosu_target_link_options --entry Reset_Handler)
list(APPEND _ethosu_target_link_options "LINKER:--entry=Reset_Handler")
set_property(
TARGET ethosu_target_link PROPERTY INTERFACE_LINK_OPTIONS
"${_ethosu_target_link_options}"
)
endif()
configure_timing_adapters("${ARG_SYSTEM_CONFIG}" "${ARG_MEMORY_MODE}")
foreach(_platform_variable TARGET_BOARD ETHOSU_MODEL ETHOSU_ARENA)
if(DEFINED ${_platform_variable})
Expand Down Expand Up @@ -747,14 +758,14 @@ function(arm_runner_configure_linker_script)

get_corstone_linker_script(_linker_script "${ARG_SYSTEM_CONFIG}")

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang)$")
set(LINK_FILE_EXT ld)
set(LINK_FILE_OPTION "-T")
set(COMPILER_PREPROCESSOR_OPTIONS -E -x c -P)
else()
message(
FATAL_ERROR
"arm_runner_configure_linker_script only supports the GNU compiler."
"arm_runner_configure_linker_script only supports GNU and Clang."
)
endif()

Expand Down
62 changes: 60 additions & 2 deletions backends/arm/cmake/linker_scripts/Corstone-300.ld
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ PHDRS
rom_sram PT_LOAD;
rom_rodata PT_LOAD;
rom_model PT_LOAD;
#ifdef __clang__
tls PT_TLS;
#endif
null PT_NULL;
}

Expand Down Expand Up @@ -117,6 +120,8 @@ SECTIONS
*(.dtors)

KEEP(*(.eh_frame*))
*(.got)
*(.got.*)
} > ITCM :rom_exec

/*
Expand All @@ -143,7 +148,11 @@ SECTIONS
__exidx_end = .;
} > ITCM :rom_exec

#ifdef __clang__
.copy.table :
#else
.copy.table (READONLY) :
#endif
{
. = ALIGN(4);
__copy_table_start__ = .;
Expand All @@ -155,17 +164,26 @@ SECTIONS
LONG (__sram_data_start__)
LONG ((__sram_data_end__ - __sram_data_start__) / 4)

LONG (__eddr_data + (__sram_data_end__ - __sram_data_start__))
LONG (LOADADDR(.rodata))
LONG (__rodata_start__)
LONG ((__rodata_end__ - __rodata_start__) / 4)

__copy_table_end__ = .;
} > ITCM :rom_exec

#ifdef __clang__
.zero.table :
#else
.zero.table (READONLY) :
#endif
{
. = ALIGN(4);
__zero_table_start__ = .;
#ifdef __clang__
LONG (ADDR(.tbss))
LONG (SIZEOF(.tbss) / 4)
#endif

LONG (__bss_start__)
LONG ((__bss_end__ - __bss_start__) / 4)
__zero_table_end__ = .;
Expand All @@ -188,6 +206,9 @@ SECTIONS

. = ALIGN(4);
/* preinit data */
#ifdef __clang__
__bothinit_array_start = .;
#endif
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
Expand All @@ -198,6 +219,9 @@ SECTIONS
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
#ifdef __clang__
__bothinit_array_end = .;
#endif

. = ALIGN(4);
/* finit data */
Expand All @@ -209,9 +233,29 @@ SECTIONS
KEEP(*(.jcr*))
. = ALIGN(4);
/* All data end */
#ifndef __clang__
__data_end__ = .;
#endif
} > DTCM :rom_data

#ifdef __clang__
.tdata : AT(LOADADDR(.data) + SIZEOF(.data))
{
__tls_start = .;
*(.tdata .tdata.* .gnu.linkonce.td.*)
. = ALIGN(4);
__data_end__ = .;
} > DTCM :rom_data :tls

.tbss (NOLOAD) :
{
*(.tbss .tbss.* .gnu.linkonce.tb.*)
*(.tcommon)
. = ALIGN(4);
__tls_end = .;
} > DTCM :null :tls
#endif

#if (ETHOSU_MODEL == 0)
.sram.rodata :
{
Expand Down Expand Up @@ -246,7 +290,6 @@ SECTIONS
* (expected_output_data_sec)
. = ALIGN(16);
* (sec_command_stream, sec_weight_data, sec_input_data)
* (.got*)
* (ethosu_core_in_queue)
* (ethosu_core_out_queue)
. = ALIGN(4);
Expand All @@ -266,6 +309,7 @@ SECTIONS
*(.sram.data)
. = ALIGN(4);
*op_*.cpp.obj (*.text*)
. = ALIGN(4);
__sram_data_end__ = .;
} > BRAM AT >DDR :rom_sram

Expand Down Expand Up @@ -320,6 +364,20 @@ SECTIONS
} > DTCM :null
PROVIDE(__stack = __StackTop);

#ifdef __clang__
PROVIDE(__data_start = __data_start__);
PROVIDE(__data_source = LOADADDR(.data));
PROVIDE(__data_size = __data_end__ - __data_start__);
PROVIDE(__bss_start = __bss_start__);
PROVIDE(__bss_size = __bss_end__ - __bss_start__);
PROVIDE(__tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)));
PROVIDE(__tls_base = __tls_start);
PROVIDE(__arm32_tls_tcb_offset = MAX(8, __tls_align));
PROVIDE(__heap_start = __end__);
PROVIDE(__heap_end = __HeapLimit);
PROVIDE(__stack_limit = __StackLimit);
#endif

__RAM_segment_used_end__ = .;

/* Check if data + heap + stack exceeds DTCM limit */
Expand Down
59 changes: 58 additions & 1 deletion backends/arm/cmake/linker_scripts/Corstone-320.ld
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ PHDRS
{
rom_boot PT_LOAD;
rom_exec PT_LOAD;
rom_sram PT_LOAD;
rom_dram PT_LOAD;
rom_model PT_LOAD;
#ifdef __clang__
tls PT_TLS;
#endif
null PT_NULL;
}

Expand Down Expand Up @@ -100,7 +104,11 @@ SECTIONS
* Alignment requirement from up to 496 interrupts, rounded to the closest
* power of two equals 512 (words), thus 2048 bytes.
*/
#ifdef __clang__
.data.vtable_rw (NOLOAD):
#else
.data.vtable_rw (COPY):
#endif
{
. = ALIGN(0x800);
KEEP(*(.vtable_rw))
Expand Down Expand Up @@ -143,12 +151,34 @@ SECTIONS
*(vtable)
*(.data)
*(.data.*)
*(.got)
*(.got.*)
*(.rodata*)

. = ALIGN(4);
#ifndef __clang__
__data_end__ = .;
#endif
} > BRAM :rom_exec

#ifdef __clang__
.tdata :
{
__tls_start = .;
*(.tdata .tdata.* .gnu.linkonce.td.*)
. = ALIGN(4);
__data_end__ = .;
} > BRAM :rom_exec :tls

.tbss (NOLOAD) :
{
*(.tbss .tbss.* .gnu.linkonce.tb.*)
*(.tcommon)
. = ALIGN(4);
__tls_end = .;
} > BRAM :null :tls
#endif

.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
Expand Down Expand Up @@ -178,6 +208,11 @@ SECTIONS
. = ALIGN(4);
__zero_table_start__ = .;

#ifdef __clang__
LONG (ADDR(.tbss))
LONG (SIZEOF(.tbss) / 4)
#endif

LONG (ADDR(.bss))
LONG (SIZEOF(.bss) / 4)

Expand All @@ -194,6 +229,9 @@ SECTIONS

. = ALIGN(4);
/* preinit data */
#ifdef __clang__
__bothinit_array_start = .;
#endif
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
Expand All @@ -204,6 +242,9 @@ SECTIONS
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
#ifdef __clang__
__bothinit_array_end = .;
#endif

. = ALIGN(4);
/* finit data */
Expand All @@ -213,7 +254,8 @@ SECTIONS
PROVIDE_HIDDEN (__fini_array_end = .);

KEEP(*(.jcr*))
} > SRAM :rom_dram
. = ALIGN(4);
} > SRAM :rom_sram

#if (ETHOSU_MODEL == 0)
.sram.rodata :
Expand All @@ -239,6 +281,7 @@ SECTIONS
*(.fast_memory)
. = ALIGN(16);
*(.bss.ethosu_scratch);
. = ALIGN(4);
} > SRAM :null

.ddr :
Expand Down Expand Up @@ -307,6 +350,20 @@ SECTIONS
} > DTCM :null
PROVIDE(__stack = __StackTop);

#ifdef __clang__
PROVIDE(__data_start = __data_start__);
PROVIDE(__data_source = LOADADDR(.data));
PROVIDE(__data_size = __data_end__ - __data_start__);
PROVIDE(__bss_start = __bss_start__);
PROVIDE(__bss_size = __bss_end__ - __bss_start__);
PROVIDE(__tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)));
PROVIDE(__tls_base = __tls_start);
PROVIDE(__arm32_tls_tcb_offset = MAX(8, __tls_align));
PROVIDE(__heap_start = __end__);
PROVIDE(__heap_end = __HeapLimit);
PROVIDE(__stack_limit = __StackLimit);
#endif

/* Check if stack exceeds DTCM limit */
ASSERT(LENGTH(DTCM) >= __STACK_SIZE, "region DTCM overflowed with stack")
}
15 changes: 10 additions & 5 deletions backends/arm/scripts/build_executor_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ help() {
echo " --output=<FOLDER> Output folder Default: <MODEL>/<MODEL>_<TARGET INFO>.pte"
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
echo " --ethosu_tools_dir=<FOLDER> Path to your Ethos-U tools dir if you not using default: ${ethosu_tools_dir}"
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (arm-none-eabi-gcc, arm-zephyr-eabi-gcc). Default: ${toolchain}"
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (arm-none-eabi-gcc, arm-none-eabi-clang, arm-zephyr-eabi-gcc). Default: ${toolchain}"
echo " --select_ops_list=<OPS> Comma separated list of portable (non-delegated) kernels to include Default: ${select_ops_list}"
echo " NOTE: This is used when select_ops_model is not possible to use, e.g. for semihosting or bundleio."
echo " See https://docs.pytorch.org/executorch/stable/kernel-library-selective-build.html for more information."
Expand Down Expand Up @@ -98,16 +98,21 @@ done

if [[ ${toolchain} == "arm-none-eabi-gcc" ]]; then
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake
size_tool=arm-none-eabi-size
elif [[ ${toolchain} == "arm-none-eabi-clang" ]]; then
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake
size_tool=llvm-size
elif [[ ${toolchain} == "arm-zephyr-eabi-gcc" ]]; then
toolchain_cmake=${et_root_dir}/examples/zephyr/x86_64-linux-arm-zephyr-eabi-gcc.cmake
size_tool=arm-zephyr-eabi-size
elif [[ ${toolchain} == "aarch64-linux-musl-gcc" ]]; then
echo "Error: aarch64-linux-musl-gcc is not supported for this bare-metal runner."
echo " Use executorch/backends/arm/scripts/build_executorch.sh with aarch64-linux-musl-gcc"
echo " or run the direct drive CMake flow to build executor_runner for Linux."
exit 1;
else
echo "Error: Invalid toolchain selection, provided: ${toolchain}"
echo " Valid options are {arm-none-eabi-gcc, arm-zephyr-eabi-gcc}"
echo " Valid options are {arm-none-eabi-gcc, arm-none-eabi-clang, arm-zephyr-eabi-gcc}"
exit 1;
fi
toolchain_cmake=$(realpath ${toolchain_cmake})
Expand Down Expand Up @@ -252,6 +257,6 @@ cmake --build ${output_folder} -j"${parallel_jobs}" -- arm_executor_runner

echo "[${BASH_SOURCE[0]}] Generated ${toolchain} elf file:"
find ${output_folder} -name "arm_executor_runner"
echo "executable_text: $(find ${output_folder} -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $1}') bytes"
echo "executable_data: $(find ${output_folder} -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $2}') bytes"
echo "executable_bss: $(find ${output_folder} -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $3}') bytes"
echo "executable_text: $(find ${output_folder} -name arm_executor_runner -exec ${size_tool} {} \; | grep -v filename | awk '{print $1}') bytes"
echo "executable_data: $(find ${output_folder} -name arm_executor_runner -exec ${size_tool} {} \; | grep -v filename | awk '{print $2}') bytes"
echo "executable_bss: $(find ${output_folder} -name arm_executor_runner -exec ${size_tool} {} \; | grep -v filename | awk '{print $3}') bytes"
6 changes: 4 additions & 2 deletions backends/arm/scripts/build_executorch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ help() {
echo " --devtools Build Devtools libs"
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
echo " --cmake-args=<ARGS> Additional arguments passed to cmake configure"
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (arm-none-eabi-gcc, arm-zephyr-eabi-gcc, aarch64-linux-musl-gcc). Default: ${toolchain}"
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (arm-none-eabi-gcc, arm-none-eabi-clang, arm-zephyr-eabi-gcc, aarch64-linux-musl-gcc). Default: ${toolchain}"
echo " --target_cpu=<CPU> Override the toolchain's default TARGET_CPU (e.g. cortex-m4). Switching target_cpu reuses the same cmake-out dir, so clear ${et_build_root}/cmake-out first to avoid stale per-CPU artifacts. Default: unset (toolchain default)."
exit 0
}
Expand All @@ -65,14 +65,16 @@ done

if [[ ${toolchain} == "arm-none-eabi-gcc" ]]; then
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake
elif [[ ${toolchain} == "arm-none-eabi-clang" ]]; then
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake
elif [[ ${toolchain} == "arm-zephyr-eabi-gcc" ]]; then
toolchain_cmake=${et_root_dir}/examples/zephyr/x86_64-linux-arm-zephyr-eabi-gcc.cmake
elif [[ ${toolchain} == "aarch64-linux-musl-gcc" ]]; then
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/aarch64-linux-musl-toolchain.cmake
is_linux_musl=1
else
echo "Error: Invalid toolchain selection, provided: ${toolchain}"
echo " Valid options are {arm-none-eabi-gcc, arm-zephyr-eabi-gcc, aarch64-linux-musl-gcc}"
echo " Valid options are {arm-none-eabi-gcc, arm-none-eabi-clang, arm-zephyr-eabi-gcc, aarch64-linux-musl-gcc}"
exit 1;
fi
toolchain_cmake=$(realpath ${toolchain_cmake})
Expand Down
Loading
Loading