From 060cbc5cf48f37454ae93443d0ef0af3826a7f5c Mon Sep 17 00:00:00 2001 From: nsz Date: Wed, 14 Sep 2011 02:51:16 +0200 Subject: [PATCH] prototype comparision tools --- data/musl.problems | 144 +++++++++++++++++++++++++++++++++++++++++++++ makeall.sh | 64 ++++++++++++++++++++ makeproto.sh | 29 +++++++++ type.sh | 80 +++++++++++++++++++++++++ 4 files changed, 317 insertions(+) create mode 100644 data/musl.problems create mode 100755 makeall.sh create mode 100755 makeproto.sh create mode 100755 type.sh diff --git a/data/musl.problems b/data/musl.problems new file mode 100644 index 0000000..fee26ff --- /dev/null +++ b/data/musl.problems @@ -0,0 +1,144 @@ +header FD_CLR sys/select.h sys_select.h +header FD_ISSET sys/select.h sys_select.h +header FD_SET sys/select.h sys_select.h +header FD_ZERO sys/select.h sys_select.h +header accept sys/socket.h sys_socket.h +proto aio_error aio.h int(struct aiocb*) int(const struct aiocb*) int aio_error(struct aiocb *); int aio_error(const struct aiocb *aiocbp); +proto aio_suspend aio.h int(struct aiocb*const[],int,const struct timespec*) int(const struct aiocb*const[],int,const struct timespec*) int aio_suspend(struct aiocb *const [], int, const struct timespec *); int aio_suspend(const struct aiocb *const list[], int nent, const struct timespec *timeout); +header bind sys/socket.h sys_socket.h +nodecl cfmakeraw T +nodecl cfsetspeed W +header chmod sys/stat.h sys_stat.h +nodecl clearerr_unlocked W +header connect sys/socket.h sys_socket.h +nodecl crypt_r W +header ctermid unistd.h stdio.h +nodecl daemon T +nodecl dst_offset V +proto encrypt unistd.h void(char*,int) void(char[64],int) void encrypt(char *, int); void encrypt(char block[64], int edflag); +nodecl environ V +proto erand48 stdlib.h double(unsigned short[]) double(unsigned short[3]) double erand48 (unsigned short [3]); double erand48(unsigned short xsubi[3]); +header fchmod sys/stat.h sys_stat.h +header fchmodat sys/stat.h sys_stat.h +nodecl feof_unlocked W +nodecl ferror_unlocked W +nodecl fflush_unlocked W +nodecl fgetwc_unlocked W +nodecl fgetws_unlocked W +nodecl fileno_unlocked W +nodecl fputwc_unlocked W +nodecl fputws_unlocked W +nodecl fread_unlocked W +header fstat sys/stat.h sys_stat.h +header fstatat sys/stat.h sys_stat.h +header fstatvfs sys/statvfs.h sys_statvfs.h +header ftok sys/ipc.h sys_ipc.h +header futimens sys/stat.h sys_stat.h sys_time.h +proto futimens sys/stat.h int(int,const struct timespec[]) int(int,const struct timespec[2]) int futimens(int, const struct timespec [2]); int futimens(int fd, const struct timespec times[2]); +nodecl fwrite_unlocked W +proto getdate time.h extern struct tm*(const char*) struct tm*(const char*) extern struct tm *getdate (const char *); struct tm *getdate(const char *string); +nodecl getdents W +nodecl getdomainname T +header getitimer sys/time.h sys_time.h +header getpeername sys/socket.h sys_socket.h +header getpriority sys/resource.h sys_resource.h +header getrlimit sys/resource.h sys_resource.h +header getrusage sys/resource.h sys_resource.h +header getsockname sys/socket.h sys_socket.h +header getsockopt sys/socket.h sys_socket.h +header gettimeofday sys/time.h sys_time.h +nodecl getw T +nodecl getwc_unlocked W +nodecl getwchar_unlocked W +header htonl netinet/in.h arpa_inet.h +header htons netinet/in.h arpa_inet.h +header if_freenameindex net/if.h net_if.h +header if_indextoname net/if.h net_if.h +header if_nameindex net/if.h net_if.h +header if_nametoindex net/if.h net_if.h +header inet_addr arpa/inet.h arpa_inet.h +header inet_ntoa arpa/inet.h arpa_inet.h +header inet_ntop arpa/inet.h arpa_inet.h +header inet_pton arpa/inet.h arpa_inet.h +proto jrand48 stdlib.h long(unsigned short[]) long(unsigned short[3]) long jrand48 (unsigned short [3]); long jrand48(unsigned short xsubi[3]); +proto lcong48 stdlib.h void(unsigned short[]) void(unsigned short[7]) void lcong48 (unsigned short [7]); void lcong48(unsigned short param[7]); +header listen sys/socket.h sys_socket.h +header lstat sys/stat.h sys_stat.h +header mkdir sys/stat.h sys_stat.h +header mkdirat sys/stat.h sys_stat.h +header mkfifo sys/stat.h sys_stat.h +header mkfifoat sys/stat.h sys_stat.h +header mknod sys/stat.h sys_stat.h +header mknodat sys/stat.h sys_stat.h +header mlock sys/mman.h sys_mman.h +header mlockall sys/mman.h sys_mman.h +header mmap sys/mman.h sys_mman.h +header mprotect sys/mman.h sys_mman.h +header msgctl sys/msg.h sys_msg.h +header msgget sys/msg.h sys_msg.h +header msgrcv sys/msg.h sys_msg.h +header msgsnd sys/msg.h sys_msg.h +header msync sys/mman.h sys_mman.h +header munlock sys/mman.h sys_mman.h +header munlockall sys/mman.h sys_mman.h +header munmap sys/mman.h sys_mman.h +proto nrand48 stdlib.h long(unsigned short[]) long(unsigned short[3]) long int nrand48 (unsigned short [3]); long nrand48(unsigned short xsubi[3]); +header ntohl netinet/in.h arpa_inet.h +header ntohs netinet/in.h arpa_inet.h +proto pipe unistd.h int(int[]) int(int[2]) int pipe(int [2]); int pipe(int fildes[2]); +nodecl pivot_root T +proto poll poll.h int(struct pollfd*,nfds_t,int) int(struct pollfd[],nfds_t,int) int poll (struct pollfd *, nfds_t, int); int poll(struct pollfd fds[], nfds_t nfds, int timeout); +header posix_madvise sys/mman.h sys_mman.h +proto posix_spawn spawn.h int(pid_t*,const char*,const posix_spawn_file_actions_t*,const posix_spawnattr_t*,char**,char**) int(pid_t*,const char*,const posix_spawn_file_actions_t*,const posix_spawnattr_t*,char*const[],char*const[]) int posix_spawn(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *, char **, char **); int posix_spawn(pid_t *restrict pid, const char *restrict path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *restrict attrp, char *const argv[restrict], char *const envp[restrict]); +proto posix_spawnp spawn.h int(pid_t*,const char*,const posix_spawn_file_actions_t*,const posix_spawnattr_t*,char**,char**) int(pid_t*,const char*,const posix_spawn_file_actions_t*,const posix_spawnattr_t*,char*const[],char*const[]) int posix_spawnp(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *, char **, char **); int posix_spawnp(pid_t *restrict pid, const char *restrict file, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *restrict attrp, char *const argv[restrict], char *const envp[restrict]); +header pselect sys/select.h sys_select.h +nodecl putw T +nodecl putwc_unlocked W +nodecl putwchar_unlocked W +proto readlink unistd.h int(const char*,char*,size_t) ssize_t(const char*,char*,size_t) int readlink(const char *, char *, size_t); ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize); +proto readlinkat unistd.h int(int,const char*,char*,size_t) ssize_t(int,const char*,char*,size_t) int readlinkat(int, const char *, char *, size_t); ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize); +header readv sys/uio.h sys_uio.h +header recv sys/socket.h sys_socket.h +header recvfrom sys/socket.h sys_socket.h +header recvmsg sys/socket.h sys_socket.h +nodecl scalbf T +proto seed48 stdlib.h unsigned short*(unsigned short[]) unsigned short*(unsigned short[3]) unsigned short *seed48 (unsigned short [3]); unsigned short *seed48(unsigned short seed16v[3]); +header select sys/select.h sys_select.h +header semget sys/sem.h sys_sem.h +header semop sys/sem.h sys_sem.h +header send sys/socket.h sys_socket.h +header sendmsg sys/socket.h sys_socket.h +header sendto sys/socket.h sys_socket.h +header setitimer sys/time.h sys_time.h +proto setpgrp unistd.h int(void) pid_t(void) int setpgrp(void); pid_t setpgrp(void); +header setpriority sys/resource.h sys_resource.h +header setrlimit sys/resource.h sys_resource.h +header setsockopt sys/socket.h sys_socket.h +header shm_open sys/mman.h sys_mman.h +header shm_unlink sys/mman.h sys_mman.h +header shmat sys/shm.h sys_shm.h +header shmctl sys/shm.h sys_shm.h +header shmdt sys/shm.h sys_shm.h +header shmget sys/shm.h sys_shm.h +header shutdown sys/socket.h sys_socket.h +nodecl sincos T +header sockatmark sys/socket.h sys_socket.h +header socket sys/socket.h sys_socket.h +header socketpair sys/socket.h sys_socket.h +proto socketpair sys/socket.h int(int,int,int,int[]) int(int,int,int,int[2]) int socketpair (int, int, int, int [2]); int socketpair(int domain, int type, int protocol, int socket_vector[2]); +nodecl start T +header stat sys/stat.h sys_stat.h +header statvfs sys/statvfs.h sys_statvfs.h +nodecl stime T +header times sys/times.h sys_times.h +header umask sys/stat.h sys_stat.h +header uname sys/utsname.h sys_utsname.h +header utimensat sys/stat.h sys_stat.h sys_time.h +proto utimensat sys/stat.h int(int,const char*,const struct timespec[],int) int(int,const char*,const struct timespec[2],int) int utimensat(int, const char *, const struct timespec [2], int); int utimensat(int fd, const char *path, const struct timespec times[2], int flag); +header utimes sys/time.h sys_stat.h sys_time.h +proto utimes sys/time.h int(const char*,const struct timeval[]) int(const char*,const struct timeval[2]) int utimes (const char *, const struct timeval [2]); int utimes(const char *path, const struct timeval times[2]); +header wait sys/wait.h sys_wait.h +header waitid sys/wait.h sys_wait.h +header waitpid sys/wait.h sys_wait.h +header wcrtomb wchar.h stdio.h +header writev sys/uio.h sys_uio.h diff --git a/makeall.sh b/makeall.sh new file mode 100755 index 0000000..99aa757 --- /dev/null +++ b/makeall.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +export LC_ALL=C + +[ -f data/musl.tags.proto -a -f data/posix2008.ok.proto ] || ./makeproto.sh + +{ + awk -F'\t' '{print $1}' data/musl.tags data/posix2008.ok # data/c99 + awk -F'\t' '{print $2}' data/musl.syms +} |sort |uniq |awk -F'\t' ' +BEGIN { + posix = "data/posix2008.ok.proto" + syms = "data/musl.syms" + tags = "data/musl.tags.proto" + + while (getline < syms == 1) + sym[$2] = $1 + while (getline < tags == 1) + tag[$1] = $2 "\t" $3 "\t" $5 "\t" $6 + while (getline < posix == 1) + pos[$1] = $2 "\t" $5 "\t" $6 +} +{ + s = "" + if (sym[$1]) + s = s " obj" + if (tag[$1]) + s = s " inc" + if (pos[$1]) + s = s " posix" + + print $1 "\t" substr(s,2) "\t" sym[$1] "\t" tag[$1] "\t" pos[$1] +}' >data/musl.all + +awk -F'\t' ' +$2 == "obj" || $2 == "obj posix" { + # not declared + if ($1 !~ /^_/) + print "nodecl\t" $1 "\t" $3 +} +$2 ~ /inc posix/ && $4 != $8 { + # different header + n = split($8, a, " ") + for (i = 1; i <= n; i++) + if ($4 == a[i]) + break + if (i > n) + print "header\t" $1 "\t" $4 "\t" $8 +} +$2 ~ /inc posix/ && $7 != $10 && $5 == "p" { + # different prototype + + # todo: move to type.sh + gsub(/restrict const/, "const", $10) + gsub(/restrict/, "", $10) +# gsub(/\[[0-9]+\]/, "[]", $10) + gsub(/unsigned int/, "unsigned", $7) + gsub(/long int/, "long", $7) + + if ($7 != $10) + print "proto\t" $1 "\t" $4 "\t" $7 "\t" $10 "\t" $6 "\t" $9 +} +' data/musl.all >data/musl.problems + diff --git a/makeproto.sh b/makeproto.sh new file mode 100755 index 0000000..326e6dd --- /dev/null +++ b/makeproto.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +export LC_ALL=C +MUSL=${MUSL:-../musl} + +awk -F'\t' -v inc=$MUSL/include/ ' +$3 == "p" && $2 !~ /^bits\// { + cmd = "awk '\''NR == " $4 "{s=$0;if(s!~/;/){getline; s=s " " $0} print s; exit}'\'' " inc $2 + cmd | getline proto + close(cmd) + gsub(/\t/, " ", proto) +} +{ + print $0 "\t" proto + proto = "" +} +' data/musl.tags >/tmp/tags.proto + +awk -F'\t' '{print $5}' /tmp/tags.proto |./type.sh >/tmp/tags.type +awk -F'\t' '{print $5}' data/posix2008.ok |./type.sh >/tmp/posix2008.type + +join() { + awk -v f=$2 '{getline s < f; print $0 "\t" s}' $1 +} + +join /tmp/tags.proto /tmp/tags.type >data/musl.tags.proto +join data/posix2008.ok /tmp/posix2008.type >data/posix2008.ok.proto + +rm -f /tmp/tags.proto /tmp/tags.type /tmp/posix2008.type diff --git a/type.sh b/type.sh new file mode 100755 index 0000000..3aa5a9c --- /dev/null +++ b/type.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +export LC_ALL=C + +# drop names from a declaration (hack to make prototypes comparable) +awk ' +BEGIN { + # type is not typedefed so next unknown id is probably a variable name + split("void char short int long float double signed unsigned _Bool _Complex", a) + for (i in a) + tok[a[i]] = "type" + + # next token is an id, type is not typedefed + split("struct union enum", a) + for (i in a) + tok[a[i]] = "struct" + + # decoratoin that can be skipped + split("static extern auto register inline const volatile restrict", a) + for (i in a) + tok[a[i]] = "decor" + + # punctuators + split("( ) [ ] , ... *", a) + for (i in a) + tok[a[i]] = "punct" +} + +function put(tok) { + if (tok ~ /^[a-zA-Z_]/) { + s = s sep tok + sep = " " + } else { + s = s tok + sep = "" + } +} + +{ + # eat comments + gsub(/\/\*[^/]*\*\//, "") + gsub(/\/\/.*/, "") + + gsub(/[^a-zA-Z0-9_.]/," & ") + gsub(/\.\.\./, " & ") + + state = "type" + sep = "" + s = "" + for (i = 1; i <= NF; i++) { + if ($i == ";") + break + if (state == "type") { + put($i) + if (!tok[$i] || tok[$i] == "type") + state = "id" + if (tok[$i] == "struct") { + i++ + put($i) + state = "id" + } + } else if (state == "id") { + if (!tok[$i]) { + state = "idfound" + continue + } + put($i) + if ($i == ")") + state = "idfound" + if ($i == ",") + state = "type" + } else if (state == "idfound") { + put($i) + if ($i == "(" || $i == ",") + state = "type" + } + } + print s +} +' -- 2.20.1