Skip to content

Commit a0b04e3

Browse files
authored
Rewrote regen-symbols.sh (gen-libblis-symbols.sh). (#751)
Details: - Wrote an alternative to regen-symbols.sh, gen-libblis-symbols.sh, that generates a list of exported symbols from the monolithic blis.h file rather than peeking inside of the shared object via nm. (This new script lives in the 'build' directory and the older script has been retired to build/old.) Special thanks to Devin Matthews for authoring gen-libblis-symbols.sh. - Added a 'symbols' target to the top-level Makefile which will refresh build/libblis-symbols.def, with supporting changes to common.mk. - Updates to build/libblis-symbols.def using the new symbol-generating script.
1 parent 6b894c3 commit a0b04e3

File tree

5 files changed

+302
-199
lines changed

5 files changed

+302
-199
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
clean cleanmk cleanh cleanlib distclean \
6363
cleantest cleanblastest cleanblistest \
6464
changelog \
65+
symbols \
6566
install uninstall uninstall-old \
6667
uninstall-libs uninstall-lib-symlinks uninstall-headers \
6768
uninstall-old-libs uninstall-lib-symlinks uninstall-old-headers
@@ -497,6 +498,19 @@ ifeq ($(ALL_MAKE_DEFS_MK_PRESENT),no)
497498
endif
498499

499500

501+
# --- Shared/dynamic libblis symbol file creation/refresh ---
502+
503+
symbols: check-env $(SYM_FILE)
504+
505+
$(SYM_FILE): $(HEADERS_TO_INSTALL)
506+
ifeq ($(ENABLE_VERBOSE),yes)
507+
$(GEN_SYMS) > $(SYM_FILE)
508+
else
509+
@echo "Updating $(SYM_FILE)"
510+
@$(GEN_SYMS) > $(SYM_FILE)
511+
endif
512+
513+
500514
# --- Consolidated blis.h header creation ---
501515

502516
flat-header: check-env $(BLIS_H_FLAT)

build/gen-libblis-symbols.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
get_config_var()
4+
{
5+
# Parse the compiler assigned to the CC variable within the config.mk file.
6+
echo "$(grep "^ *$1 *:=" config.mk | sed 's/'$1' *:= *//')"
7+
}
8+
9+
main()
10+
{
11+
if [ ! -e config.mk ]; then
12+
echo "No config.mk file detected; have you configured BLIS?"
13+
exit 1
14+
fi
15+
16+
CC=$(get_config_var CC)
17+
CONFIG_NAME=$(get_config_var CONFIG_NAME)
18+
BLIS_H_FLAT="include/${CONFIG_NAME}/blis.h"
19+
20+
if [ ! -e ${BLIS_H_FLAT} ]; then
21+
echo "No monolithic blis.h file detected at ${BLIS_H_FLAT}; have you run 'make'?"
22+
exit 1
23+
fi
24+
25+
#
26+
# Header line
27+
#
28+
echo "EXPORTS"
29+
30+
#
31+
# Breakdown of commands:
32+
# $(CC) ... # Pre-process blis.h, making sure to include all BLAS and CBLAS symbols
33+
# | tr ... # Make sure to split lines at ';' so that each declaration is on its own line
34+
# | grep ... # Find exported symbols
35+
# | sed -E
36+
# -e ... # 1. Remove all __attribute__ clauses
37+
# -e ... # 2. Select only the portion before an opening '(' (if any)
38+
# -e ... # 3. Pull out the last word, which is the function name.
39+
# | grep ... # Remove constants
40+
# | grep ... # Remove blank lines
41+
# | sed ... # Remove trailing spaces
42+
# | sort
43+
# | uniq
44+
#
45+
${CC} -DBLIS_ENABLE_CBLAS=1 -DBLIS_ENABLE_BLAS=1 -E ${BLIS_H_FLAT} \
46+
| tr ';' '\n' \
47+
| grep visibility \
48+
| sed -E \
49+
-e 's/__attribute__ *\( *\([^\)]+(\([^\)]+\) *)\) *\)//g' \
50+
-e 's/(.*) *\(.*/\1/' \
51+
-e 's/.* ([^ ].*)/\1/' \
52+
| grep -v BLIS \
53+
| grep -E '[^ ]' \
54+
| sed -e 's/[[:space:]]*$//g' \
55+
| sort \
56+
| uniq
57+
}
58+
59+
main "$@"
60+

0 commit comments

Comments
 (0)