2023-09-04 02:37:48 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
############################################################################
|
|
|
|
# tools/build-globals.sh
|
2022-09-26 08:22:03 +02:00
|
|
|
#
|
2023-09-04 02:37:48 +02:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership. The
|
|
|
|
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance with the
|
|
|
|
# License. You may obtain a copy of the License at
|
2022-09-26 08:22:03 +02:00
|
|
|
#
|
2023-09-04 02:37:48 +02:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2022-09-26 08:22:03 +02:00
|
|
|
#
|
2023-09-04 02:37:48 +02:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
2022-09-26 08:22:03 +02:00
|
|
|
#
|
2023-09-04 02:37:48 +02:00
|
|
|
############################################################################
|
2022-09-26 08:22:03 +02:00
|
|
|
#
|
2023-09-04 02:37:48 +02:00
|
|
|
# Script to create modlib_global.S which contains a structure define
|
|
|
|
# the API names and addresses we will export for resolving symbols in
|
|
|
|
# dynamic loaded shared objects. Typically these are libc APIs.
|
|
|
|
|
2022-09-26 08:22:03 +02:00
|
|
|
#
|
|
|
|
# Symbols to ignore within the NuttX libraries
|
|
|
|
#
|
2023-07-09 00:16:11 +02:00
|
|
|
FILTER="^lib_low|^FUNCTION|^STUB|^__start|^_vect|^arm_|^arp_|^bch|^binfmt|^blake|^block_|^cdcacm|^chksum|^clock_|^close_|^crypto_|^devif_|^devnull|^devuran|^devzero|^emerg|^epoll_|^elf_|^_dbgR|^dq_|^env_|^file_|^files_|^fs_|^ftl_|^g_|^get_|^group_|^global|^hcom|^i2c_|^inode_|^iob_|^irq_|^kmm_|^lfs_|^lib_|^local_|^mm_|^modlib_|^mpu_|^mq_|^nglobals|^net_|^netdev_|^nx|^pipecommon|^posix_spawn_file|^psock_|^ramlog|^rammap|^readline_|^register_|^sched_|^sockfd|^spawn_|^sq_|^stm32|^symtab_|^syslog_|^syslogstream|^task_|^tcp_|^timer_|^uart_|^ub[12]|^udp_|^umm_|^umount|^unload_|^unregister|^up_|^usb|^usrsock_|^watchdog|^wd_|globalNames$|nglobals$|global_table$|^\.l"
|
2023-07-07 01:15:59 +02:00
|
|
|
|
|
|
|
if [ -z "${NM}" ]; then
|
|
|
|
NM="nm"
|
|
|
|
fi
|
2022-09-26 08:22:03 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Extract symbols from the runtime
|
|
|
|
#
|
2023-07-07 01:15:59 +02:00
|
|
|
SYMS=`cat System.map | awk '{print $3}' | sort | grep -Ev ${FILTER}`
|
2022-09-26 08:22:03 +02:00
|
|
|
SYM=(${SYMS})
|
2023-07-07 01:15:59 +02:00
|
|
|
GLOBALS="libs/libc/modlib/modlib_globals.S"
|
2022-09-26 08:22:03 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Generate the modlib_xxxx_globals.S file
|
|
|
|
#
|
|
|
|
cat >${GLOBALS} <<__EOF__
|
2023-07-07 01:15:59 +02:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
# define SYMBOL(s) _##s
|
|
|
|
# define GLOBAL .global
|
|
|
|
# define SECTION .data
|
|
|
|
.macro GLOBAL ep
|
|
|
|
.global SYMBOL(\ep)
|
|
|
|
.type SYMBOL(\ep), "object"
|
|
|
|
.endm
|
|
|
|
.macro SIZE ep
|
|
|
|
.endm
|
|
|
|
#elif defined(__ELF__)
|
|
|
|
# define SYMBOL(s) s
|
|
|
|
# define SECTION .data
|
|
|
|
.macro GLOBAL ep
|
|
|
|
.global SYMBOL(\ep)
|
|
|
|
.type SYMBOL(\ep), "object"
|
|
|
|
.endm
|
|
|
|
.macro SIZE ep
|
|
|
|
.size SYMBOL(\ep), . - SYMBOL(\ep)
|
|
|
|
.endm
|
|
|
|
#else
|
|
|
|
# define SYMBOL(s) _##s
|
|
|
|
# define SECTION .section __DATA,__data
|
|
|
|
.macro GLOBAL ep
|
|
|
|
.private_extern SYMBOL(\ep)
|
|
|
|
.globl SYMBOL(\ep)
|
|
|
|
.endm
|
|
|
|
.macro SIZE ep
|
|
|
|
.endm
|
|
|
|
#endif
|
|
|
|
|
2022-09-26 08:22:03 +02:00
|
|
|
#if __SIZEOF_POINTER__ == 8
|
|
|
|
.macro globalEntry index, ep
|
2023-07-07 01:15:59 +02:00
|
|
|
.quad .l\index
|
|
|
|
.quad \ep
|
2022-09-26 08:22:03 +02:00
|
|
|
.endm
|
|
|
|
# define ALIGN 8
|
|
|
|
#else
|
|
|
|
.macro globalEntry index, ep
|
2023-07-07 01:15:59 +02:00
|
|
|
.long .l\index
|
|
|
|
.long \ep
|
2022-09-26 08:22:03 +02:00
|
|
|
.endm
|
|
|
|
# define ALIGN 4
|
|
|
|
#endif
|
|
|
|
#ifdef __ARM_ARCH_ISA_THUMB2
|
|
|
|
# ifdef __ARM_ARCH_7M__
|
2023-07-07 01:15:59 +02:00
|
|
|
.arch armv7e-m
|
2022-09-26 08:22:03 +02:00
|
|
|
# elif defined ___ARM_ARCH 8
|
|
|
|
.arch armv8-m.base
|
|
|
|
#endif
|
|
|
|
#ifdef __ARM_ASM_SYNTAX_UNIFIED__
|
2023-07-07 01:15:59 +02:00
|
|
|
.syntax unified
|
2022-09-26 08:22:03 +02:00
|
|
|
#endif
|
2023-07-07 01:15:59 +02:00
|
|
|
.thumb
|
2022-09-26 08:22:03 +02:00
|
|
|
#endif
|
2023-07-07 01:15:59 +02:00
|
|
|
.data
|
|
|
|
.align ALIGN
|
2023-09-04 02:37:48 +02:00
|
|
|
GLOBAL globalNames
|
2022-09-26 08:22:03 +02:00
|
|
|
|
2023-07-07 01:15:59 +02:00
|
|
|
SYMBOL(globalNames):
|
2022-09-26 08:22:03 +02:00
|
|
|
__EOF__
|
|
|
|
|
2023-09-04 02:37:48 +02:00
|
|
|
for ((i = 0; i < ${#SYM[@]}; i++))
|
2022-09-26 08:22:03 +02:00
|
|
|
do
|
2023-09-04 02:37:48 +02:00
|
|
|
echo ".l${i}: .string \"${SYM[$i]}\"" >>${GLOBALS}
|
2022-09-26 08:22:03 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
cat >>${GLOBALS} <<__EOF__
|
2023-09-04 02:37:48 +02:00
|
|
|
SIZE globalNames
|
2022-09-26 08:22:03 +02:00
|
|
|
|
2023-07-07 01:15:59 +02:00
|
|
|
.align ALIGN
|
2023-07-09 00:16:11 +02:00
|
|
|
GLOBAL nglobals
|
2023-09-04 02:37:48 +02:00
|
|
|
SYMBOL(nglobals):
|
|
|
|
.word ${#SYM[@]}
|
2023-07-09 00:16:11 +02:00
|
|
|
SIZE nglobals
|
2022-09-26 08:22:03 +02:00
|
|
|
|
2023-07-07 01:15:59 +02:00
|
|
|
.align ALIGN
|
2023-07-09 00:16:11 +02:00
|
|
|
GLOBAL global_table
|
|
|
|
SYMBOL(global_table):
|
2022-09-26 08:22:03 +02:00
|
|
|
__EOF__
|
|
|
|
|
2023-09-04 02:37:48 +02:00
|
|
|
for ((i = 0; i < ${#SYM[@]}; i++))
|
2022-09-26 08:22:03 +02:00
|
|
|
do
|
2023-09-04 02:37:48 +02:00
|
|
|
echo " globalEntry ${i}, ${SYM[$i]}" >>${GLOBALS}
|
2022-09-26 08:22:03 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
cat >>${GLOBALS} <<__EOF__
|
2023-07-09 00:16:11 +02:00
|
|
|
SIZE global_table
|
2022-09-26 08:22:03 +02:00
|
|
|
__EOF__
|
|
|
|
|
2023-09-04 02:37:48 +02:00
|
|
|
echo "${#SYM[@]} symbols defined"
|