From ba78abf4a6e2d5b0abfa67994481512e58597b9e Mon Sep 17 00:00:00 2001 From: nsz Date: Sun, 17 Apr 2016 21:59:53 +0000 Subject: [PATCH] add abi_func --- Makefile | 8 +++---- abi_func.sh | 55 +++++++++++++++++++++++++++++++++++++++++++ abi_func_data.sh | 9 +++++++ abi.sh => abi_type.sh | 0 abi_type_data.sh | 10 ++++++++ 5 files changed, 78 insertions(+), 4 deletions(-) create mode 100755 abi_func.sh create mode 100755 abi_func_data.sh rename abi.sh => abi_type.sh (100%) create mode 100755 abi_type_data.sh diff --git a/Makefile b/Makefile index b1efef6..a7d6ba1 100644 --- a/Makefile +++ b/Makefile @@ -36,12 +36,12 @@ sizeof-g++: sizeof.c abi: abi.ARCH.diff cp abi.ARCH.* data/ -abi.cc: - ./abi.sh -abi.ARCH.glibc: abi.cc +abi_type.cc: + ./abi_type.sh +abi.ARCH.glibc: abi_type.cc g++ -std=c++11 $(GLIBC_FLAGS) -c -o $@.o $< nm -C $@.o |sed -n 's/^[[:xdigit:]]* T //p' |sort >$@ -abi.ARCH.musl: abi.cc +abi.ARCH.musl: abi_type.cc g++ -std=c++11 -nostdinc -fno-stack-protector -isystem $(MUSL)/include -isystem $(LIBGCC) -isystem /usr/include -c -o $@.o $< nm -C $@.o |sed -n 's/^[[:xdigit:]]* T //p' |sort >$@ abi.ARCH.diff: abi.ARCH.glibc abi.ARCH.musl diff --git a/abi_func.sh b/abi_func.sh new file mode 100755 index 0000000..f110f24 --- /dev/null +++ b/abi_func.sh @@ -0,0 +1,55 @@ +#!/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 + +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 + +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 + +echo '#define T(x) void t_##x(__typeof(x)*p){}' >>abi_func.cc +echo ' +#ifdef __GLIBC__ +#define M(x) +#undef sigsetjmp +#define sigsetjmp __sigsetjmp +#else +#define M(x) x +#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 diff --git a/abi_func_data.sh b/abi_func_data.sh new file mode 100755 index 0000000..637dbae --- /dev/null +++ b/abi_func_data.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +CXXFILT=${CXXFILT:-c++filt} + +$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 +' diff --git a/abi.sh b/abi_type.sh similarity index 100% rename from abi.sh rename to abi_type.sh diff --git a/abi_type_data.sh b/abi_type_data.sh new file mode 100755 index 0000000..5d6420d --- /dev/null +++ b/abi_type_data.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +CXXFILT=${CXXFILT:-c++filt} + +$CXX -S -o - abi.cc |sed -n 's/^\(_Z.*\):/\1/p' |$CXXFILT |sed ' +s/^x_\([^(]*\)(\(.*\))/\1: \2/ +s/^y_\([^(]*\)(\(.*\))/\1*: \2/ +s/floatcomplex /float _Complex/g +s/doublecomplex /double _Complex/g +' -- 2.20.1