From b6bf10a24409113ea5d4d042efb2c7421696f04b Mon Sep 17 00:00:00 2001 From: nsz Date: Mon, 18 Apr 2016 21:17:57 +0000 Subject: [PATCH] update abi_* scripts --- abi_func.sh | 56 +++++++++--------------- abi_func_data.sh | 2 +- abi_type.sh | 111 ++++++++++++++++++++++++++++------------------- abi_type_data.sh | 4 +- makedecls.sh | 108 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 199 insertions(+), 82 deletions(-) create mode 100755 makedecls.sh diff --git a/abi_func.sh b/abi_func.sh index f110f24..6c6d44a 100755 --- a/abi_func.sh +++ b/abi_func.sh @@ -1,37 +1,23 @@ #!/bin/sh -#set -xeu - export LC_ALL=C -#MUSL=${MUSL:-../musl} awk -F'\t' '$3 ~ /^p$/ { print $1 -}' data/musl.tags >/tmp/m.funcs -awk -F'\t' '$3 ~ /^p$/ { - print $2 -}' data/musl.tags >/tmp/m.header +}' data/musl.generic.decls |sort |uniq >/tmp/m.funcs -echo '#define _GNU_SOURCE 1' >abi_func.cc -echo '#define _FILE_OFFSET_BITS 64' >>abi_func.cc -echo '#define SYSLOG_NAMES 1' >>abi_func.cc -#echo '#include ' >>abi_func.cc -#echo '#include ' >>abi_func.cc -echo '' >>abi_func.cc +echo ' +#define _GNU_SOURCE 1 +#define _FILE_OFFSET_BITS 64 +' >abi_func.cc -sort /tmp/m.header |uniq |awk ' -# /^sys\/(auxv|cachectl|fantotify|errno|fcntl|poll|signal|soundcard|termios)\.h$/ { printf "//" } -# /^(stdalign|stdnoreturn|threads|wait)\.h$/ { printf "//" } -# /^sys\/(cachectl)\.h$/ { printf "//" } -# /^(threads)\.h$/ { printf "//" } - { print "#include <" $0 ">" }' >>abi_func.cc -#echo 'typedef long long long_long; typedef long double long_double;' >>abi.cc -#echo 'struct size{int i;}; struct align{int i;};' >>abi.cc -#echo '#define p(s,t) void x_##t(s t x, s t* ptr, size(*y)[sizeof(s t)], align(*z)[__alignof__(s t)]){}' >>abi.cc -#echo '#define pp(s,t) void x_##t(s t* ptr, size(*y)[sizeof(s t*)], align(*z)[__alignof__(s t*)]){}' >>abi.cc +awk -F'\t' '$3 ~ /^p$/ { + if ($2 ~ /^(sys\/(cachectl|io)|threads)\.h$/) next + print "#include <" $2 ">" +}' data/musl.generic.decls |sort |uniq >>abi_func.cc -echo '#define T(x) void t_##x(__typeof(x)*p){}' >>abi_func.cc echo ' +#define T(x) void t_##x(__typeof(x)*p){} #ifdef __GLIBC__ #define M(x) #undef sigsetjmp @@ -41,15 +27,13 @@ echo ' #endif ' >>abi_func.cc -sort /tmp/m.funcs |uniq |awk ' - /^(__flt_rounds|__freadahead|__freadptr|__freadptrinc|__fseterr|_flush_cache|_pthread_cleanup_pop|_pthread_cleanup_push|cachectl|cacheflush|call_once|cnd_broadcast|cnd_destroy|cnd_init|cnd_signal|cnd_timedwait|cnd_wait|fgetln|getdents|gets|index|issetugid|memchr|memrchr|mtx_destroy|mtx_init|mtx_lock|mtx_timedlock|mtx_trylock|mtx_unlock|posix_close|rindex|strcasestr|strchr|strchrnul|strlcat|strlcpy|strpbrk|strrchr|strstr|thrd_create|thrd_current|thrd_detach|thrd_equal|thrd_exit|thrd_join|thrd_sleep|thrd_yield|tss_create|tss_delete|tss_get|tss_set|wcschr|wcspbrk|wcsrchr|wcsstr|wcswcs|wmemchr)$/ { - print "M(T(" $0 "))"; next - } - /^(ElfW)$/ { printf "// " } - { print "T(" $0 ")" }' >>abi_func.cc - -#$CXX -S -o - abi_func.cc |sed -n 's/^\(_Z.*\):/\1/p' |$CXXFILT |sed ' -#s/(\*)/@/;s/^t_\([^(]*\)(\(.*\)@\(.*\))/\2\1\3/ -#s/floatcomplex /float _Complex/g -#s/doublecomplex /double _Complex/g -#' >data/musl.abi_func +awk ' +/^(_flush_cache|cachectl|cacheflush|iopl|ioperm|call_once|cnd_broadcast|cnd_destroy|cnd_init|cnd_signal|cnd_timedwait|cnd_wait|mtx_destroy|mtx_init|mtx_lock|mtx_timedlock|mtx_trylock|mtx_unlock|thrd_create|thrd_current|thrd_detach|thrd_equal|thrd_exit|thrd_join|thrd_sleep|thrd_yield|tss_create|tss_delete|tss_get|tss_set)$/ { + print "// "$0; next +} +#/^(__flt_rounds|__freadahead|__freadptr|__freadptrinc|__fseterr|_pthread_cleanup_pop|_pthread_cleanup_push|gets|issetugid|posix_close|strlcat|strlcpy)$/ +/^(__flt_rounds|__freadahead|__freadptr|__freadptrinc|__fseterr|_pthread_cleanup_pop|_pthread_cleanup_push|fgetln|getdents|gets|index|issetugid|memchr|memrchr|posix_close|rindex|strcasestr|strchr|strchrnul|strlcat|strlcpy|strpbrk|strrchr|strstr|wcschr|wcspbrk|wcsrchr|wcsstr|wcswcs|wmemchr)$/ { + print "M(T(" $0 "))"; next +} +/^(ElfW)$/ { printf "// " } +{ print "T(" $0 ")" }' /tmp/m.funcs >>abi_func.cc diff --git a/abi_func_data.sh b/abi_func_data.sh index 637dbae..ff34a5e 100755 --- a/abi_func_data.sh +++ b/abi_func_data.sh @@ -2,7 +2,7 @@ CXXFILT=${CXXFILT:-c++filt} -$CXX -S -o - abi_func.cc |sed -n 's/^\(_Z.*\):/\1/p' |$CXXFILT |sed ' +$CXX -nostdinc++ -S -o - abi_func.cc |sed -n 's/^\(_Z.*\):/\1/p' |$CXXFILT |sed ' s/(\*)/@/;s/^t_\([^(]*\)(\(.*\)@\(.*\))/\2\1\3/ s/floatcomplex /float _Complex/g s/doublecomplex /double _Complex/g diff --git a/abi_type.sh b/abi_type.sh index e389e32..be445af 100755 --- a/abi_type.sh +++ b/abi_type.sh @@ -1,58 +1,81 @@ #!/bin/sh export LC_ALL=C -MUSL=${MUSL:-../musl} -awk -F'\t' '$3 ~ /^[sut]$/ { +ALL=' +aarch64 +arm +i386 +microblaze +mips +mips64 +or1k +powerpc +powerpc64 +sh +x32 +x86_64 +' +ARCH="${ARCH:-$ALL}" + +# install headers to T.$arch +for arch in $ARCH +do + +{ +awk -F'\t' '$3 ~ /^[sutSUT]$/ { print $1 -}' data/musl.tags >/tmp/m.type -echo 'char' >>/tmp/m.type -echo 'short' >>/tmp/m.type -echo 'int' >>/tmp/m.type -echo 'long' >>/tmp/m.type -echo 'long_long' >>/tmp/m.type -echo 'float' >>/tmp/m.type -echo 'double' >>/tmp/m.type -echo 'long_double' >>/tmp/m.type -echo 'wchar_t' >>/tmp/m.type -echo 'bool' >>/tmp/m.type -echo 'void' >>/tmp/m.type - -( - cd $MUSL/include - find . -name '*.h' | sed 's,^\./,,' >/tmp/m.header -) - -echo '#define _GNU_SOURCE 1' >abi_type.cc -echo '#define _FILE_OFFSET_BITS 64' >>abi_type.cc -echo '#define SYSLOG_NAMES 1' >>abi_type.cc -echo '#include ' >>abi_type.cc -echo '#include ' >>abi_type.cc -echo '' >>abi_type.cc - -sort /tmp/m.header |uniq |awk ' - /^sys\/(auxv|cachectl|fantotify|errno|fcntl|kd|poll|signal|soundcard|termios|vt)\.h$/ { printf "//" } - /^(bits\/.*|stdalign|stdnoreturn|threads|wait)\.h$/ { printf "//" } - { print "#include <" $0 ">" }' >>abi_type.cc -echo 'typedef long long long_long; typedef long double long_double;' >>abi_type.cc -echo 'struct size{int i;}; struct align{int i;};' >>abi_type.cc -echo '#define p(s,t) void x_##t(s t x, s t* ptr, size(*y)[sizeof(s t)], align(*z)[__alignof__(s t)]){}' >>abi_type.cc -echo '#define pp(s,t) void y_##t(s t* ptr, size(*y)[sizeof(s t*)], align(*z)[__alignof__(s t*)]){}' >>abi_type.cc +}' data/musl.generic.decls data/musl.$arch.decls +echo 'char +short +int +long +long_long +float +double +long_double +wchar_t +bool +void' +} |sort |uniq >/tmp/m.$arch.type + +awk -F'\t' '{print $2}' data/musl.generic.decls |sort |uniq >/tmp/m.header + echo ' +#define _GNU_SOURCE 1 +#define _FILE_OFFSET_BITS 64 +#define SYSLOG_NAMES 1 +#include +#include +' >abi_type.$arch.cc + +awk ' +/^sys\/(auxv|cachectl|fantotify|errno|fcntl|io|kd|poll|reg|signal|soundcard|termios|vt)\.h$/ { printf "//" } +/^(stdalign|stdnoreturn|threads|wait)\.h$/ { printf "//" } +{ print "#include <" $0 ">" }' /tmp/m.header >>abi_type.$arch.cc + +echo ' +typedef long long long_long; +typedef long double long_double; +struct size {char c;}; +struct align {char c;}; +#define T(s,t) void x_##t(s t x, s t* ptr, size(*y)[sizeof(s t)], align(*z)[__alignof__(s t)]){} +#define P(s,t) void y_##t(s t* ptr, size(*y)[sizeof(s t*)], align(*z)[__alignof__(s t*)]){} #ifdef __GLIBC__ #define M(x) #else #define M(x) x #endif -' >>abi_type.cc - -sort /tmp/m.type |uniq |awk ' - /^(once_flag|mtx_t|cnd_t|thrd_start_t|thrd_t|tss_dtor_t|tss_t)$/ || - /^(struct|union) __(CODE|ptcb|siginfo|ucontext|sigjmp_buf|double_repr|float_repr|sigset_t|mbstate_t|fsid_t)$/ || - /^(elf_fpxregset_t|struct user_fpxregs_struct|Sg_io_vec|struct ih_.*|struct ip6_hdrctl|tcp_seq|union _G_fpos64_t|struct cpu_set_t|__isoc_va_list|ns_tcp_tsig.*|ns_tsig_.*|struct ptrace_peeksiginfo_.*)$/ { printf "//" } - { if (!sub(/ /,",")) sub(/^/,",") } - /,(DIR|FILE|void)$/ { print "pp(" $0 ")"; next } - { print "p(" $0 ")" }' >>abi_type.cc +' >>abi_type.$arch.cc + +awk ' +/^(once_flag|mtx_t|cnd_t|thrd_start_t|thrd_t|tss_dtor_t|tss_t)$/ || +/^(struct|union) __(CODE|ptcb|siginfo|ucontext|sigjmp_buf|double_repr|float_repr|sigset_t|mbstate_t|fsid_t|locale_struct)$/ || +/^(elf_fpxregset_t|struct user_fpxregs_struct|Sg_io_vec|struct ih_.*|struct ip6_hdrctl|tcp_seq|union _G_fpos64_t|struct cpu_set_t|__isoc_va_list|ns_tcp_tsig.*|ns_tsig_.*|struct ptrace_peeksiginfo_.*)$/ { printf "//" } +{ if (!sub(/ /,",")) sub(/^/,",") } +/,(DIR|FILE|void)$/ { print "P(" $0 ")"; next } +{ print "T(" $0 ")" }' /tmp/m.$arch.type >>abi_type.$arch.cc +done #$CXX -S -o - abi_type.cc |sed -n 's/^\(_Z.*\):/\1/p' |$CXXFILT |sed ' #s/^x_\([^(]*\)(\(.*\))/\1: \2/ diff --git a/abi_type_data.sh b/abi_type_data.sh index 5d6420d..c4ed77e 100755 --- a/abi_type_data.sh +++ b/abi_type_data.sh @@ -1,8 +1,10 @@ #!/bin/sh CXXFILT=${CXXFILT:-c++filt} +#TODO +ARCH=${ARCH:-x86_64} -$CXX -S -o - abi.cc |sed -n 's/^\(_Z.*\):/\1/p' |$CXXFILT |sed ' +$CXX -S -o - abi_type.$ARCH.cc |sed -n 's/^\(_Z.*\):/\1/p' |$CXXFILT |sed ' s/^x_\([^(]*\)(\(.*\))/\1: \2/ s/^y_\([^(]*\)(\(.*\))/\1*: \2/ s/floatcomplex /float _Complex/g diff --git a/makedecls.sh b/makedecls.sh new file mode 100755 index 0000000..ff8c6ac --- /dev/null +++ b/makedecls.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +set -xeu + +export LC_ALL=C + +# musl repo dir +MUSL="${MUSL:-../musl}" + +ALL=' +aarch64 +arm +i386 +microblaze +mips +mips64 +or1k +powerpc +powerpc64 +sh +x32 +x86_64 +' + +ARCH="${ARCH:-$ALL}" + +# install headers to T.$arch +for arch in $ARCH +do +[ -e T.$arch ] && continue +make -f "$MUSL"/Makefile install-headers srcdir="$MUSL" prefix=T.$arch ARCH=$arch +rm -rf obj/include/bits +done +rm -rf obj lib + +# run ctags on headers +for arch in $ARCH +do +[ -e T.$arch/musl.tags ] && continue +cd T.$arch/include +ctags -f ../musl.tags -R -n -u --language-force=c --c-kinds=pxdstuve --fields=k . +# fix wchar_t bug of ctags (not ok for c++) +awk '/typedef.* wchar_t/{print "wchar_t\tbits/alltypes.h\t" NR ";\"\tt"}' bits/alltypes.h >>../musl.tags +cd ../.. +done + +# add declarations (slow) +for arch in $ARCH +do +[ -e T.$arch/musl.decls ] && continue +cd T.$arch/include +awk ' +BEGIN { FS="\t" } + +function decl(t,h,n) { + cmd = "awk '\''NR==" n + if (t ~ /[pxt]/) + cmd = cmd "{s=$0; if(s!~/;/){getline; s=s \" \" $0} print s; exit}" + else if (t == "d") + cmd = cmd "{s=$0; while(gsub(/\\\\$/,\"\",s)){getline; s=s $0} print s; exit}" + else + return "" + cmd = cmd "'\'' " h + cmd | getline s + close(cmd) + gsub(/\t/, " ", s) + gsub(/ +/, " ", s) + if (t == "p") + gsub(/ \(/, "(", s) + return s +} +/^[^!]/ { + gsub(/[^0-9]*/,"",$3) + if ($4 == "s") + $1 = "struct " $1 + if ($4 == "u") + $1 = "union " $1 + print $1 "\t" $2 "\t" $4 "\t" $3 "\t" decl($4,$2,$3) +}' ../musl.tags >../musl.decls.raw + +# fix ups +awk ' +BEGIN { FS="\t" } +$3=="d" && $5 ~ /^#undef/ {next} +$3=="x" && $5 ~ /^(struct|union) [_0-9a-zA-Z]*;$/ { + a = ($5 ~ /^struct/) ? "struct " : "union " + b = ($5 ~ /^struct/) ? "S" : "U" + print a $1 "\t" $2 "\t" b "\t" $4 "\t" $5 + next +} +$1~/^(FILE|DIR)$/ { + print $1 "\t" $2 "\tT\t" $4 "\t" $5 + next +} +{ print $0 }' ../musl.decls.raw | sort >../musl.decls +cd ../.. +done + +# add decls to data/ +for arch in $ARCH +do +grep ' bits/' T.$arch/musl.decls >data/musl.$arch.decls +done +for arch in $ARCH +do +grep -v ' bits/' T.$arch/musl.decls >data/musl.generic.decls +break +done -- 2.20.1