Skip to content

Commit

Permalink
scripts/utils: Build a list of "excluded" libc APIs
Browse files Browse the repository at this point in the history
This script generates a list of exported symbols (functions, global
variables, static inlines and CPP names) which are present in picolibc but
not present in the minimal C library.

These symbols shall not be used by the "core Zephyr kernel"; the
construction of a script that detects use of the is left as an exercise to
the reader.

Signed-off-by: Keith Packard <[email protected]>
  • Loading branch information
keith-packard committed May 4, 2023
1 parent 2b4fdd1 commit 310e7ed
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scripts/utils/find_id.cocci
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
virtual patch
virtual report

@initialize:python@
@@
@find_id@
identifier id;
type ty;
parameter list[nb_params] params;
position p;
@@
(
ty id@p(params);
|
extern ty id@p;
)

@script:python@
id << find_id.id;
p << find_id.p;
@@
print("identifier %s %s %s" % (id, p[0].file, p[0].line))
39 changes: 39 additions & 0 deletions scripts/utils/gen-libc-exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

HERE=`dirname "$0"`

if [ -z "$ZEPHYR_SDK_INSTALL_DIR" ]; then
echo 'Must define ZEPHYR_SDK_INSTALL_DIR' 1>&2
exit 1
fi

if [ -z "$ZEPHYR_BASE" ]; then
echo 'Must define ZEPHYR_BASE' 1>&2
exit 1
fi

gen_syms() {
while read i; do
spatch --macro-file "$HERE"/libc-macros.h -sp-file "$HERE"/find_id.cocci "$i" 2>/dev/null |
awk '/identifier/ { if ($2 !~ "_.*") print $2; }'
grep '^[ \t]*#[ \t]*\(define\|undef\)[ \t][ \t]*[A-Za-z]' "$i" |
sed 's/^[ \t]*#[ \t]*\(define\|undef\)[ \t][ \t]*\([_A-Za-z][_A-Za-z0-9]*\).*$/\1 \2/' |
awk '{ if ($1 == "define") defs[$2] = 1; else defs[$2] = 0; } END { for (id in defs) if (defs[id]) print id; }'
done | (LANG=C sort -u)
}

TMPDIR=`mktemp -d $PWD/gen-libc.XXXXXXXX`
trap "rm -r $TMPDIR" EXIT

MINIMAL_LIBC_INCLUDE="$ZEPHYR_BASE"/lib/libc/minimal/include
POSIX_INCLUDE="$ZEPHYR_BASE"/include/zephyr/posix
MINIMAL_LIBC_SYMS="$TMPDIR"/minimal-names

find "$MINIMAL_LIBC_INCLUDE" "$POSIX_INCLUDE" -type f | gen_syms > "$MINIMAL_LIBC_SYMS"

PICOLIBC_INCLUDE="$ZEPHYR_SDK_INSTALL_DIR"/arm-zephyr-eabi/picolibc/include
PICOLIBC_LIBC_SYMS="$TMPDIR"/picolibc-names

find "$PICOLIBC_INCLUDE" -type f | gen_syms > "$PICOLIBC_LIBC_SYMS"

LANG=C comm -23 "$PICOLIBC_LIBC_SYMS" "$MINIMAL_LIBC_SYMS"
1 change: 1 addition & 0 deletions scripts/utils/libc-macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define __printf_like(a,b)

0 comments on commit 310e7ed

Please sign in to comment.