From b142ffadb2512a5d58c9cbdc16584056f7347cd8 Mon Sep 17 00:00:00 2001 From: shuangxiang kan <18550887212@163.com> Date: Thu, 7 Sep 2023 15:10:59 +1000 Subject: [PATCH 1/4] Remove "STATIC" annotation in extapi.bc --- svf-llvm/include/SVF-LLVM/LLVMUtil.h | 4 +- svf-llvm/lib/LLVMUtil.cpp | 2 - svf-llvm/lib/SVFIRExtAPI.cpp | 2 +- svf-llvm/lib/SymbolTableBuilder.cpp | 9 -- svf-llvm/lib/extapi.c | 165 +++++++-------------------- svf/include/Util/SVFUtil.h | 34 ------ svf/lib/Util/ExtAPI.cpp | 6 - 7 files changed, 44 insertions(+), 178 deletions(-) diff --git a/svf-llvm/include/SVF-LLVM/LLVMUtil.h b/svf-llvm/include/SVF-LLVM/LLVMUtil.h index f885668c2..be2fb8ac9 100644 --- a/svf-llvm/include/SVF-LLVM/LLVMUtil.h +++ b/svf-llvm/include/SVF-LLVM/LLVMUtil.h @@ -141,10 +141,10 @@ inline const PointerType *getRefTypeOfHeapAllocOrStatic(const CallBase* cs) if (const PointerType *argType = SVFUtil::dyn_cast(arg->getType())) refType = SVFUtil::dyn_cast(getPtrElementType(argType)); } - // Case 2: heap/static object held by return value. + // Case 2: heap object held by return value. else { - assert((SVFUtil::isStaticExtCall(svfcs) || SVFUtil::isHeapAllocExtCallViaRet(svfcs)) + assert(SVFUtil::isHeapAllocExtCallViaRet(svfcs) && "Must be heap alloc via ret, or static allocation site"); refType = SVFUtil::dyn_cast(cs->getType()); } diff --git a/svf-llvm/lib/LLVMUtil.cpp b/svf-llvm/lib/LLVMUtil.cpp index 17ee478c5..40c0c66ed 100644 --- a/svf-llvm/lib/LLVMUtil.cpp +++ b/svf-llvm/lib/LLVMUtil.cpp @@ -53,8 +53,6 @@ const std::string structName = "struct."; */ bool LLVMUtil::isObject(const Value* ref) { - if (SVFUtil::isa(ref) && SVFUtil::isStaticExtCall(LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(SVFUtil::cast(ref))) ) - return true; if (SVFUtil::isa(ref) && SVFUtil::isHeapAllocExtCallViaRet(LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(SVFUtil::cast(ref)))) return true; if (SVFUtil::isa(ref)) diff --git a/svf-llvm/lib/SVFIRExtAPI.cpp b/svf-llvm/lib/SVFIRExtAPI.cpp index b862eca68..b924180c3 100644 --- a/svf-llvm/lib/SVFIRExtAPI.cpp +++ b/svf-llvm/lib/SVFIRExtAPI.cpp @@ -128,7 +128,7 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle const SVFInstruction* svfInst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(cs); const SVFCallInst* svfCall = SVFUtil::cast(svfInst); - if (isHeapAllocExtCallViaRet(svfCall) || isStaticExtCall(svfCall)) + if (isHeapAllocExtCallViaRet(svfCall)) { NodeID val = pag->getValueNode(svfInst); NodeID obj = pag->getObjectNode(svfInst); diff --git a/svf-llvm/lib/SymbolTableBuilder.cpp b/svf-llvm/lib/SymbolTableBuilder.cpp index 7bc27efe2..563c420ba 100644 --- a/svf-llvm/lib/SymbolTableBuilder.cpp +++ b/svf-llvm/lib/SymbolTableBuilder.cpp @@ -750,15 +750,6 @@ void SymbolTableBuilder::initTypeInfo(ObjTypeInfo* typeinfo, const Value* val, // Heap object, label its field as infinite here objSize = typeinfo->getMaxFieldOffsetLimit(); } - else if (SVFUtil::isa(val) && - isStaticExtCall( - LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction( - SVFUtil::cast(val)))) - { - analyzeStaticObjType(typeinfo,val); - // static object allocated before main, label its field as infinite here - objSize = typeinfo->getMaxFieldOffsetLimit(); - } else if(ArgInProgEntryFunction(val)) { analyzeStaticObjType(typeinfo,val); diff --git a/svf-llvm/lib/extapi.c b/svf-llvm/lib/extapi.c index b918bca77..fddcfaa6e 100644 --- a/svf-llvm/lib/extapi.c +++ b/svf-llvm/lib/extapi.c @@ -11,7 +11,6 @@ ALLOC_RET, // returns a ptr to a newly allocated object ALLOC_ARGi // stores a pointer to an allocated object in *argi REALLOC_RET, - STATIC, // retval points to an unknown static var X MEMSET, // memcpy() operations MEMCPY, // memset() operations OVERWRITE, // svf function overwrite app function @@ -23,291 +22,209 @@ void *SyGetmem(unsigned long size) return NULL; } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) const unsigned short **__ctype_b_loc(void) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) int **__ctype_tolower_loc(void) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) int **__ctype_toupper_loc(void) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) int *__errno_location(void) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) int * __h_errno_location(void) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) void* __res_state(void) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char *asctime(const void *timeptr) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char * bindtextdomain(const char * domainname, const char * dirname) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char * bind_textdomain_codeset(const char * domainname, const char * codeset) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char *ctermid(char *s) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char * dcgettext(const char * domainname, const char * msgid, int category) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char * dgettext(const char * domainname, const char * msgid) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char * dngettext(const char * domainname, const char * msgid, const char * msgid_plural, unsigned long int n) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) void *fdopen(int fd, const char *mode) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct group *getgrgid(unsigned int gid) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct group *getgrnam(const char *name) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct hostent *gethostbyaddr(const void *addr, unsigned int len, int type) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct hostent *gethostbyname(const char *name) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct hostent *gethostbyname2(const char *name, int af) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct mntent *getmntent(void *stream) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct protoent *getprotobyname(const char *name) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct protoent *getprotobynumber(int proto) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct passwd *getpwent(void) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct passwd *getpwnam(const char *name) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct passwd *getpwuid(unsigned int uid) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct servent *getservbyname(const char *name, const char *proto) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct servent *getservbyport(int port, const char *proto) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct spwd *getspnam(const char *name) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char * gettext(const char * msgid) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct tm *gmtime(const void *timer) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) const char *gnu_get_libc_version(void) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) const char * gnutls_check_version(const char * req_version) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct lconv *localeconv(void) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) struct tm *localtime(const void *timer) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char * ngettext(const char * msgid, const char * msgid_plural, unsigned long int n) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) void *pango_cairo_font_map_get_default(void) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char *re_comp(const char *regex) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char *setlocale(int category, const char *locale) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char *tgoto(const char *cap, int col, int row) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) char *tparm(char *str, ...) { - return NULL; + return malloc(10); } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("STATIC"))) const char *zError(int a) { - return NULL; + return malloc(10); } __attribute__((annotate("ALLOC_RET"))) diff --git a/svf/include/Util/SVFUtil.h b/svf/include/Util/SVFUtil.h index d21570d53..e27c64163 100644 --- a/svf/include/Util/SVFUtil.h +++ b/svf/include/Util/SVFUtil.h @@ -350,14 +350,6 @@ inline bool isReallocExtFun(const SVFFunction* fun) return fun && (ExtAPI::getExtAPI()->is_realloc(fun)); } -/// Return true if the call is a static global call -//@{ -/// note that this function is not suppose to be used externally -inline bool isStaticExtFun(const SVFFunction* fun) -{ - return fun && ExtAPI::getExtAPI()->has_static(fun); -} - /// Program entry function e.g. main //@{ /// Return true if this is a program entry function (e.g. main) @@ -494,32 +486,6 @@ inline bool isReallocExtCall(const SVFInstruction *inst) } //@} -inline bool isStaticExtCall(const CallSite cs) -{ - bool isPtrTy = cs.getInstruction()->getType()->isPointerTy(); - return isPtrTy && isStaticExtFun(getCallee(cs)); -} - -inline bool isStaticExtCall(const SVFInstruction *inst) -{ - bool isPtrTy = inst->getType()->isPointerTy(); - return isPtrTy && isStaticExtFun(getCallee(inst)); -} -//@} - -/// Return true if the call is a static global call -//@{ -inline bool isHeapAllocOrStaticExtCall(const CallSite cs) -{ - return isStaticExtCall(cs) || isHeapAllocExtCall(cs); -} - -inline bool isHeapAllocOrStaticExtCall(const SVFInstruction *inst) -{ - return isStaticExtCall(inst) || isHeapAllocExtCall(inst); -} -//@} - /// Return true if this is a thread creation call ///@{ inline bool isThreadForkCall(const CallSite cs) diff --git a/svf/lib/Util/ExtAPI.cpp b/svf/lib/Util/ExtAPI.cpp index 1285863f0..7ce1d2e62 100644 --- a/svf/lib/Util/ExtAPI.cpp +++ b/svf/lib/Util/ExtAPI.cpp @@ -144,12 +144,6 @@ bool ExtAPI::hasExtFuncAnnotation(const SVFFunction* fun, const std::string& fun return false; } -// Does (F) have a static var X (unavailable to us) that its return points to? -bool ExtAPI::has_static(const SVFFunction* F) -{ - return F && hasExtFuncAnnotation(F, "STATIC"); -} - bool ExtAPI::is_memcpy(const SVFFunction *F) { return F && hasExtFuncAnnotation(F, "MEMCPY"); From 54967658ef820f062dbbd85ddaaf2a9b4a1bd01e Mon Sep 17 00:00:00 2001 From: shuangxiang kan <18550887212@163.com> Date: Fri, 8 Sep 2023 16:33:37 +1000 Subject: [PATCH 2/4] Return "STATIC_OBJECT" in an external function which has a static var that its return value points to --- svf-llvm/lib/extapi.c | 568 +++++++++++++++++++++--------------------- 1 file changed, 283 insertions(+), 285 deletions(-) diff --git a/svf-llvm/lib/extapi.c b/svf-llvm/lib/extapi.c index fddcfaa6e..d44021aac 100644 --- a/svf-llvm/lib/extapi.c +++ b/svf-llvm/lib/extapi.c @@ -1,5 +1,5 @@ -// #include #define NULL ((void *)0) +#define STATIC_OBJECT malloc(10) /* Functions with __attribute__((annotate("XXX"))) will be handle by SVF specifcially. @@ -7,7 +7,6 @@ The description of methodProperties is as follows: - SVF, // inform SVF that this function is managed by SVF and should not use its body. ALLOC_RET, // returns a ptr to a newly allocated object ALLOC_ARGi // stores a pointer to an allocated object in *argi REALLOC_RET, @@ -15,216 +14,448 @@ MEMCPY, // memset() operations OVERWRITE, // svf function overwrite app function */ -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("OVERWRITE"))) -void *SyGetmem(unsigned long size) + +void * __rawmemchr(const void * s, int c) { - return NULL; + return (void *)s; +} + +struct jpeg_error_mgr *jpeg_std_error(struct jpeg_error_mgr * a) +{ + return a; +} + +char *fgets(char *str, int n, void *stream) +{ + return str; +} + +void *memchr(const void *str, int c, unsigned long n) +{ + return (void *)str; +} + +void * mremap(void * old_address, unsigned long old_size, unsigned long new_size, int flags) +{ + return old_address; +} + +char *strchr(const char *str, int c) +{ + return (char *)str; +} + +char *strerror_r(int errnum, char *buf, unsigned long buflen) +{ + return buf; +} + +char *strpbrk(const char *str1, const char *str2) +{ + return (char *)str1; +} + +char *strptime(const void* s, const void* format, void* tm) +{ + return (char *)s; +} + +char *strrchr(const char *str, int c) +{ + return (char *)str; +} + +char *strstr(const char *haystack, const char *needle) +{ + return (char *)haystack; +} + +char *tmpnam_r(char *s) +{ + return s; +} + +int isalnum(int character) +{ + return character; +} + +int isalpha(int character) +{ + return character; +} + +int isblank(int character) +{ + return character; +} + +int iscntrl(int c) +{ + return c; +} + +int isdigit(int c) +{ + return c; +} + +int isgraph(int c) +{ + return c; +} + +int islower( int arg ) +{ + return arg; +} + +int isprint(int c) +{ + return c; +} + +int ispunct(int argument) +{ + return argument; +} + +int isspace(char c) +{ + return c; +} + +int isupper(int c) +{ + return c; +} + +int isxdigit(int c) +{ + return c; +} + +char *asctime_r(const void *tm, char *buf) +{ + return buf; +} + +void *bsearch(const void *key, const void *base, unsigned long nitems, unsigned long size, int (*compar)(const void *, const void *)) +{ + return (void *)base; +} + +struct mntent *getmntent_r(void *fp, struct mntent *mntbuf, char *buf, int buflen) +{ + return mntbuf; +} + +struct tm *gmtime_r(const void *timer, struct tm *buf) +{ + return buf; +} + +char * gzgets(void* file, char * buf, int len) +{ + return buf; +} + +struct tm *localtime_r(const void *timep, struct tm *result) +{ + return result; +} + +char *realpath(const char *restrict path, char *restrict resolved_path) +{ + return resolved_path; +} + +void* freopen64( const char* voidname, const char* mode, void* fp ) +{ + return fp; +} + +void* freopen(const char* voidname, const char* mode, void* fp) +{ + return fp; +} + +const char *inet_ntop(int af, const void *restrict src, char *restrict dst, unsigned int size) +{ + return dst; +} + +double strtod(const char *str, char **endptr) +{ + *endptr = (char *)str; + return 0.0; +} + +float strtof(const char *nptr, char **endptr) +{ + *endptr = (char *)nptr; + return 0.0; +} + +long int strtol(const char *str, char **endptr, int base) +{ + *endptr = (char *)str; + return 0; +} + +long double strtold(const char* str, char** endptr) +{ + *endptr = (char *)str; + return 0.0; +} + +unsigned long int strtoul(const char *str, char **endptr, int base) +{ + *endptr = (char *)str; + return 0; +} + +int readdir_r(void *__restrict__dir, void *__restrict__entry, void **__restrict__result) +{ + __restrict__entry = *__restrict__result; + return 0; +} + +int getpwnam_r(const char *name, void *pwd, char *buf, unsigned long buflen, void **result) +{ + *result = pwd; + return 0; +} + +int getpwuid_r(unsigned int uid, void *pwd, char *buf, unsigned long buflen, void **result) +{ + *result = pwd; + return 0; +} + +void _ZNSt8__detail15_List_node_base7_M_hookEPS0_(void *arg0, void **arg1) +{ + *arg1 = arg0; +} + +void* __dynamic_cast(void* source, const void* sourceTypeInfo, const void* targetTypeInfo, unsigned long castType) +{ + return source; +} + +void _ZNSsC1EPKcRKSaIcE(void **arg0, void *arg1) +{ + *arg0 = arg1; +} + +void _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EPKcRKS3_(void **arg0, void *arg1) +{ + *arg0 = arg1; } const unsigned short **__ctype_b_loc(void) { - return malloc(10); + return STATIC_OBJECT; } int **__ctype_tolower_loc(void) { - return malloc(10); + return STATIC_OBJECT; } int **__ctype_toupper_loc(void) { - return malloc(10); + return STATIC_OBJECT; } int *__errno_location(void) { - return malloc(10); + return STATIC_OBJECT; } int * __h_errno_location(void) { - return malloc(10); + return STATIC_OBJECT; } void* __res_state(void) { - return malloc(10); + return STATIC_OBJECT; } char *asctime(const void *timeptr) { - return malloc(10); + return STATIC_OBJECT; } char * bindtextdomain(const char * domainname, const char * dirname) { - return malloc(10); + return STATIC_OBJECT; } char * bind_textdomain_codeset(const char * domainname, const char * codeset) { - return malloc(10); + return STATIC_OBJECT; } char *ctermid(char *s) { - return malloc(10); + return STATIC_OBJECT; } char * dcgettext(const char * domainname, const char * msgid, int category) { - return malloc(10); + return STATIC_OBJECT; } char * dgettext(const char * domainname, const char * msgid) { - return malloc(10); + return STATIC_OBJECT; } char * dngettext(const char * domainname, const char * msgid, const char * msgid_plural, unsigned long int n) { - return malloc(10); + return STATIC_OBJECT; } void *fdopen(int fd, const char *mode) { - return malloc(10); + return STATIC_OBJECT; } struct group *getgrgid(unsigned int gid) { - return malloc(10); + return STATIC_OBJECT; } struct group *getgrnam(const char *name) { - return malloc(10); + return STATIC_OBJECT; } struct hostent *gethostbyaddr(const void *addr, unsigned int len, int type) { - return malloc(10); + return STATIC_OBJECT; } struct hostent *gethostbyname(const char *name) { - return malloc(10); + return STATIC_OBJECT; } struct hostent *gethostbyname2(const char *name, int af) { - return malloc(10); + return STATIC_OBJECT; } struct mntent *getmntent(void *stream) { - return malloc(10); + return STATIC_OBJECT; } struct protoent *getprotobyname(const char *name) { - return malloc(10); + return STATIC_OBJECT; } struct protoent *getprotobynumber(int proto) { - return malloc(10); + return STATIC_OBJECT; } struct passwd *getpwent(void) { - return malloc(10); + return STATIC_OBJECT; } struct passwd *getpwnam(const char *name) { - return malloc(10); + return STATIC_OBJECT; } struct passwd *getpwuid(unsigned int uid) { - return malloc(10); + return STATIC_OBJECT; } struct servent *getservbyname(const char *name, const char *proto) { - return malloc(10); + return STATIC_OBJECT; } struct servent *getservbyport(int port, const char *proto) { - return malloc(10); + return STATIC_OBJECT; } struct spwd *getspnam(const char *name) { - return malloc(10); + return STATIC_OBJECT; } char * gettext(const char * msgid) { - return malloc(10); + return STATIC_OBJECT; } struct tm *gmtime(const void *timer) { - return malloc(10); + return STATIC_OBJECT; } const char *gnu_get_libc_version(void) { - return malloc(10); + return STATIC_OBJECT; } const char * gnutls_check_version(const char * req_version) { - return malloc(10); + return STATIC_OBJECT; } struct lconv *localeconv(void) { - return malloc(10); + return STATIC_OBJECT; } struct tm *localtime(const void *timer) { - return malloc(10); + return STATIC_OBJECT; } char * ngettext(const char * msgid, const char * msgid_plural, unsigned long int n) { - return malloc(10); + return STATIC_OBJECT; } void *pango_cairo_font_map_get_default(void) { - return malloc(10); + return STATIC_OBJECT; } char *re_comp(const char *regex) { - return malloc(10); + return STATIC_OBJECT; } char *setlocale(int category, const char *locale) { - return malloc(10); + return STATIC_OBJECT; } char *tgoto(const char *cap, int col, int row) { - return malloc(10); + return STATIC_OBJECT; } char *tparm(char *str, ...) { - return malloc(10); + return STATIC_OBJECT; } const char *zError(int a) { - return malloc(10); + return STATIC_OBJECT; } __attribute__((annotate("ALLOC_RET"))) @@ -871,242 +1102,9 @@ void* _ZNSt5arrayIPK1ALm2EE4backEv(void *arg) return ptr2; } - -void * __rawmemchr(const void * s, int c) -{ - return (void *)s; -} - -struct jpeg_error_mgr *jpeg_std_error(struct jpeg_error_mgr * a) -{ - return a; -} - -char *fgets(char *str, int n, void *stream) -{ - return str; -} - -void *memchr(const void *str, int c, unsigned long n) -{ - return (void *)str; -} - -void * mremap(void * old_address, unsigned long old_size, unsigned long new_size, int flags) -{ - return old_address; -} - -char *strchr(const char *str, int c) -{ - return (char *)str; -} - -char *strerror_r(int errnum, char *buf, unsigned long buflen) -{ - return buf; -} - -char *strpbrk(const char *str1, const char *str2) -{ - return (char *)str1; -} - -char *strptime(const void* s, const void* format, void* tm) -{ - return (char *)s; -} - -char *strrchr(const char *str, int c) -{ - return (char *)str; -} - -char *strstr(const char *haystack, const char *needle) -{ - return (char *)haystack; -} - -char *tmpnam_r(char *s) -{ - return s; -} - -int isalnum(int character) -{ - return character; -} - -int isalpha(int character) -{ - return character; -} - -int isblank(int character) -{ - return character; -} - -int iscntrl(int c) -{ - return c; -} - -int isdigit(int c) -{ - return c; -} - -int isgraph(int c) -{ - return c; -} - -int islower( int arg ) -{ - return arg; -} - -int isprint(int c) -{ - return c; -} - -int ispunct(int argument) -{ - return argument; -} - -int isspace(char c) -{ - return c; -} - -int isupper(int c) -{ - return c; -} - -int isxdigit(int c) -{ - return c; -} - -char *asctime_r(const void *tm, char *buf) -{ - return buf; -} - -void *bsearch(const void *key, const void *base, unsigned long nitems, unsigned long size, int (*compar)(const void *, const void *)) -{ - return (void *)base; -} - -struct mntent *getmntent_r(void *fp, struct mntent *mntbuf, char *buf, int buflen) -{ - return mntbuf; -} - -struct tm *gmtime_r(const void *timer, struct tm *buf) -{ - return buf; -} - -char * gzgets(void* file, char * buf, int len) -{ - return buf; -} - -struct tm *localtime_r(const void *timep, struct tm *result) -{ - return result; -} - -char *realpath(const char *restrict path, char *restrict resolved_path) -{ - return resolved_path; -} - -void* freopen64( const char* voidname, const char* mode, void* fp ) -{ - return fp; -} - -void* freopen(const char* voidname, const char* mode, void* fp) -{ - return fp; -} - -const char *inet_ntop(int af, const void *restrict src, char *restrict dst, unsigned int size) -{ - return dst; -} - -double strtod(const char *str, char **endptr) -{ - *endptr = (char *)str; - return 0.0; -} - -float strtof(const char *nptr, char **endptr) -{ - *endptr = (char *)nptr; - return 0.0; -} - -long int strtol(const char *str, char **endptr, int base) -{ - *endptr = (char *)str; - return 0; -} - -long double strtold(const char* str, char** endptr) -{ - *endptr = (char *)str; - return 0.0; -} - -unsigned long int strtoul(const char *str, char **endptr, int base) -{ - *endptr = (char *)str; - return 0; -} - -int readdir_r(void *__restrict__dir, void *__restrict__entry, void **__restrict__result) -{ - __restrict__entry = *__restrict__result; - return 0; -} - -int getpwnam_r(const char *name, void *pwd, char *buf, unsigned long buflen, void **result) -{ - *result = pwd; - return 0; -} - -int getpwuid_r(unsigned int uid, void *pwd, char *buf, unsigned long buflen, void **result) -{ - *result = pwd; - return 0; -} - - -void _ZNSt8__detail15_List_node_base7_M_hookEPS0_(void *arg0, void **arg1) -{ - *arg1 = arg0; -} - -void* __dynamic_cast(void* source, const void* sourceTypeInfo, const void* targetTypeInfo, unsigned long castType) -{ - return source; -} - -void _ZNSsC1EPKcRKSaIcE(void **arg0, void *arg1) -{ - *arg0 = arg1; -} - -void _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EPKcRKS3_(void **arg0, void *arg1) +__attribute__((annotate("ALLOC_RET"))) +__attribute__((annotate("OVERWRITE"))) +void *SyGetmem(unsigned long size) { - *arg0 = arg1; -} + return NULL; +} \ No newline at end of file From 51cdb4028307c36906fc157b3c7d2a4663e98333 Mon Sep 17 00:00:00 2001 From: shuangxiang kan <18550887212@163.com> Date: Fri, 8 Sep 2023 17:40:18 +1000 Subject: [PATCH 3/4] Move the functions with annotations to the front of the functions without annotations in extapi.c --- svf-llvm/lib/extapi.c | 1035 ++++++++++++++++++++--------------------- 1 file changed, 517 insertions(+), 518 deletions(-) diff --git a/svf-llvm/lib/extapi.c b/svf-llvm/lib/extapi.c index d44021aac..215e28deb 100644 --- a/svf-llvm/lib/extapi.c +++ b/svf-llvm/lib/extapi.c @@ -14,1097 +14,1096 @@ MEMCPY, // memset() operations OVERWRITE, // svf function overwrite app function */ - -void * __rawmemchr(const void * s, int c) +__attribute__((annotate("ALLOC_RET"))) +void *malloc(unsigned long size) { - return (void *)s; + return NULL; } -struct jpeg_error_mgr *jpeg_std_error(struct jpeg_error_mgr * a) +__attribute__((annotate("ALLOC_RET"))) +void *fopen(const char *voidname, const char *mode) { - return a; + return NULL; } -char *fgets(char *str, int n, void *stream) +__attribute__((annotate("ALLOC_RET"))) +void *fopen64(const char *voidname, const char *mode) { - return str; + return NULL; } -void *memchr(const void *str, int c, unsigned long n) +__attribute__((annotate("ALLOC_RET"))) +struct dirent64 *readdir64(void *dirp) { - return (void *)str; + return NULL; } -void * mremap(void * old_address, unsigned long old_size, unsigned long new_size, int flags) +__attribute__((annotate("ALLOC_RET"))) +void *tmpvoid64(void) { - return old_address; + return NULL; } -char *strchr(const char *str, int c) +__attribute__((annotate("ALLOC_RET"))) +void *calloc(unsigned long nitems, unsigned long size) { - return (char *)str; + return NULL; } -char *strerror_r(int errnum, char *buf, unsigned long buflen) +__attribute__((annotate("ALLOC_RET"))) +void *zmalloc(unsigned long size) { - return buf; + return NULL; } -char *strpbrk(const char *str1, const char *str2) +__attribute__((annotate("ALLOC_RET"))) +void *gzdopen(int fd, const char *mode) { - return (char *)str1; + return NULL; } -char *strptime(const void* s, const void* format, void* tm) +__attribute__((annotate("ALLOC_RET"))) +void *iconv_open(const char *tocode, const char *fromcode) { - return (char *)s; + return NULL; } -char *strrchr(const char *str, int c) +__attribute__((annotate("ALLOC_RET"))) +void *lalloc(unsigned long size, int a) { - return (char *)str; + return NULL; } -char *strstr(const char *haystack, const char *needle) +__attribute__((annotate("ALLOC_RET"))) +void *lalloc_clear(unsigned long size, int a) { - return (char *)haystack; + return NULL; } -char *tmpnam_r(char *s) +__attribute__((annotate("ALLOC_RET"))) +long *nhalloc(unsigned int a, const char *b, int c) { - return s; + return NULL; } -int isalnum(int character) +__attribute__((annotate("ALLOC_RET"))) +void *oballoc(unsigned long size) { - return character; + return NULL; } -int isalpha(int character) +__attribute__((annotate("ALLOC_RET"))) +void *popen(const char *command, const char *type) { - return character; + return NULL; } -int isblank(int character) +__attribute__((annotate("ALLOC_RET"))) +void *pthread_getspecific(const char *a, const char *b) { - return character; + return NULL; } -int iscntrl(int c) +__attribute__((annotate("ALLOC_RET"))) +struct dirent *readdir(void *dirp) { - return c; + return NULL; } -int isdigit(int c) +__attribute__((annotate("ALLOC_RET"))) +void* safe_calloc(unsigned nelem, unsigned elsize) { - return c; + return NULL; } -int isgraph(int c) +__attribute__((annotate("ALLOC_RET"))) +void* safe_malloc(unsigned long size) { - return c; + return NULL; } -int islower( int arg ) +__attribute__((annotate("ALLOC_RET"))) +char* safecalloc(int a, int b) { - return arg; + return NULL; } -int isprint(int c) +__attribute__((annotate("ALLOC_RET"))) +char* safemalloc(int a, int b) { - return c; + return NULL; } -int ispunct(int argument) +__attribute__((annotate("ALLOC_RET"))) +void *setmntent(const char *voidname, const char *type) { - return argument; + return NULL; } -int isspace(char c) +__attribute__((annotate("ALLOC_RET"))) +void *shmat(int shmid, const void *shmaddr, int shmflg) { - return c; + return NULL; } -int isupper(int c) +__attribute__((annotate("ALLOC_RET"))) +void* __sysv_signal(int a, void *b) { - return c; + return NULL; } -int isxdigit(int c) +__attribute__((annotate("ALLOC_RET"))) +void (*signal(int sig, void (*func)(int)))(int) { - return c; + return NULL; } -char *asctime_r(const void *tm, char *buf) +__attribute__((annotate("ALLOC_RET"))) +char *tempnam(const char *dir, const char *pfx) { - return buf; + return NULL; } -void *bsearch(const void *key, const void *base, unsigned long nitems, unsigned long size, int (*compar)(const void *, const void *)) +__attribute__((annotate("ALLOC_RET"))) +void *tmpvoid(void) { - return (void *)base; + return NULL; } -struct mntent *getmntent_r(void *fp, struct mntent *mntbuf, char *buf, int buflen) +__attribute__((annotate("ALLOC_RET"))) +void* xcalloc(unsigned long size1, unsigned long size2) { - return mntbuf; + return NULL; } -struct tm *gmtime_r(const void *timer, struct tm *buf) +__attribute__((annotate("ALLOC_RET"))) +void* xmalloc(unsigned long size) { - return buf; + return NULL; } -char * gzgets(void* file, char * buf, int len) +__attribute__((annotate("ALLOC_RET"))) +void *_Znam(unsigned long size) { - return buf; + return NULL; } -struct tm *localtime_r(const void *timep, struct tm *result) +__attribute__((annotate("ALLOC_RET"))) +void *_Znaj(unsigned long size) { - return result; + return NULL; } -char *realpath(const char *restrict path, char *restrict resolved_path) +__attribute__((annotate("ALLOC_RET"))) +void *_Znwj(unsigned long size) { - return resolved_path; + return NULL; } -void* freopen64( const char* voidname, const char* mode, void* fp ) +__attribute__((annotate("ALLOC_RET"))) +void *__cxa_allocate_exception(unsigned long size) { - return fp; + return NULL; } -void* freopen(const char* voidname, const char* mode, void* fp) +__attribute__((annotate("ALLOC_RET"))) +void* aligned_alloc(unsigned long size1, unsigned long size2) { - return fp; + return NULL; } -const char *inet_ntop(int af, const void *restrict src, char *restrict dst, unsigned int size) +__attribute__((annotate("ALLOC_RET"))) +void* memalign(unsigned long size1, unsigned long size2) { - return dst; + return NULL; } -double strtod(const char *str, char **endptr) +__attribute__((annotate("ALLOC_RET"))) +void *valloc(unsigned long size) { - *endptr = (char *)str; - return 0.0; + return NULL; } -float strtof(const char *nptr, char **endptr) +__attribute__((annotate("ALLOC_RET"))) +void *mmap64(void *addr, unsigned long len, int prot, int flags, int fildes, long off) { - *endptr = (char *)nptr; - return 0.0; + return NULL; } -long int strtol(const char *str, char **endptr, int base) +__attribute__((annotate("ALLOC_RET"))) +char *XSetLocaleModifiers(char *a) { - *endptr = (char *)str; - return 0; + return NULL; } -long double strtold(const char* str, char** endptr) +__attribute__((annotate("ALLOC_RET"))) +char * __strdup(const char * string) { - *endptr = (char *)str; - return 0.0; + return NULL; } -unsigned long int strtoul(const char *str, char **endptr, int base) +__attribute__((annotate("ALLOC_RET"))) +char *crypt(const char *key, const char *salt) { - *endptr = (char *)str; - return 0; + return NULL; } -int readdir_r(void *__restrict__dir, void *__restrict__entry, void **__restrict__result) +__attribute__((annotate("ALLOC_RET"))) +char *ctime(const void *timer) { - __restrict__entry = *__restrict__result; - return 0; + return NULL; } -int getpwnam_r(const char *name, void *pwd, char *buf, unsigned long buflen, void **result) +__attribute__((annotate("ALLOC_RET"))) +char *dlerror(void) { - *result = pwd; - return 0; + return NULL; } -int getpwuid_r(unsigned int uid, void *pwd, char *buf, unsigned long buflen, void **result) +__attribute__((annotate("ALLOC_RET"))) +void *dlopen(const char *voidname, int flags) { - *result = pwd; - return 0; + return NULL; } -void _ZNSt8__detail15_List_node_base7_M_hookEPS0_(void *arg0, void **arg1) +__attribute__((annotate("ALLOC_RET"))) +const char *gai_strerror(int errcode) { - *arg1 = arg0; + return NULL; } -void* __dynamic_cast(void* source, const void* sourceTypeInfo, const void* targetTypeInfo, unsigned long castType) +__attribute__((annotate("ALLOC_RET"))) +const char *gcry_cipher_algo_name(int errcode) { - return source; + return NULL; } -void _ZNSsC1EPKcRKSaIcE(void **arg0, void *arg1) +__attribute__((annotate("ALLOC_RET"))) +const char *svfgcry_md_algo_name_(int errcode) { - *arg0 = arg1; + return NULL; } -void _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EPKcRKS3_(void **arg0, void *arg1) +__attribute__((annotate("ALLOC_RET"))) +char *getenv(const char *name) { - *arg0 = arg1; + return NULL; } -const unsigned short **__ctype_b_loc(void) +__attribute__((annotate("ALLOC_RET"))) +char *getlogin(void) { - return STATIC_OBJECT; + return NULL; } -int **__ctype_tolower_loc(void) +__attribute__((annotate("ALLOC_RET"))) +char *getpass(const char *prompt) { - return STATIC_OBJECT; + return NULL; } -int **__ctype_toupper_loc(void) +__attribute__((annotate("ALLOC_RET"))) +const char * gnutls_strerror(int error) { - return STATIC_OBJECT; + return NULL; } -int *__errno_location(void) -{ - return STATIC_OBJECT; +__attribute__((annotate("ALLOC_RET"))) +const char *gpg_strerror(unsigned int a) +{ + return NULL; } -int * __h_errno_location(void) +__attribute__((annotate("ALLOC_RET"))) +const char * gzerror(void* file, int * errnum) { - return STATIC_OBJECT; + return NULL; } -void* __res_state(void) +__attribute__((annotate("ALLOC_RET"))) +char *inet_ntoa(unsigned int in) { - return STATIC_OBJECT; + return NULL; } -char *asctime(const void *timeptr) +__attribute__((annotate("ALLOC_RET"))) +void *initscr(void) { - return STATIC_OBJECT; + return NULL; } -char * bindtextdomain(const char * domainname, const char * dirname) +__attribute__((annotate("ALLOC_RET"))) +void* llvm_stacksave() { - return STATIC_OBJECT; + return NULL; } -char * bind_textdomain_codeset(const char * domainname, const char * codeset) +__attribute__((annotate("ALLOC_RET"))) +void *mmap(void *addr, unsigned long len, int prot, int flags, int fildes, long off) { - return STATIC_OBJECT; + return NULL; } -char *ctermid(char *s) +__attribute__((annotate("ALLOC_RET"))) +void *newwin(int nlines, int ncols, int begin_y, int begin_x) { - return STATIC_OBJECT; + return NULL; } -char * dcgettext(const char * domainname, const char * msgid, int category) +__attribute__((annotate("ALLOC_RET"))) +char *nl_langinfo(int item) { - return STATIC_OBJECT; + return NULL; } -char * dgettext(const char * domainname, const char * msgid) +__attribute__((annotate("ALLOC_RET"))) +void *opendir(const char *name) { - return STATIC_OBJECT; + return NULL; } -char * dngettext(const char * domainname, const char * msgid, const char * msgid_plural, unsigned long int n) +__attribute__((annotate("ALLOC_RET"))) +void *sbrk(long increment) { - return STATIC_OBJECT; + return NULL; } -void *fdopen(int fd, const char *mode) +__attribute__((annotate("ALLOC_RET"))) +char *strdup(const char *s) { - return STATIC_OBJECT; + return NULL; } -struct group *getgrgid(unsigned int gid) +__attribute__((annotate("ALLOC_RET"))) +char *strerror(int errnum) { - return STATIC_OBJECT; + return NULL; } -struct group *getgrnam(const char *name) +__attribute__((annotate("ALLOC_RET"))) +char *strsignal(int errnum) { - return STATIC_OBJECT; + return NULL; } -struct hostent *gethostbyaddr(const void *addr, unsigned int len, int type) +__attribute__((annotate("ALLOC_RET"))) +char *textdomain(const char * domainname) { - return STATIC_OBJECT; + return NULL; } -struct hostent *gethostbyname(const char *name) +__attribute__((annotate("ALLOC_RET"))) +char *tgetstr(char *id, char **area) { - return STATIC_OBJECT; + return NULL; } -struct hostent *gethostbyname2(const char *name, int af) +__attribute__((annotate("ALLOC_RET"))) +char *tigetstr(char *capname) { - return STATIC_OBJECT; + return NULL; } -struct mntent *getmntent(void *stream) +__attribute__((annotate("ALLOC_RET"))) +char *tmpnam(char *s) { - return STATIC_OBJECT; + return NULL; } -struct protoent *getprotobyname(const char *name) +__attribute__((annotate("ALLOC_RET"))) +char *ttyname(int fd) { - return STATIC_OBJECT; + return NULL; } -struct protoent *getprotobynumber(int proto) +__attribute__((annotate("REALLOC_RET"))) +char *getcwd(char *buf, unsigned long size) { - return STATIC_OBJECT; + return NULL; } -struct passwd *getpwent(void) +__attribute__((annotate("REALLOC_RET"))) +char *mem_realloc(void *ptr, unsigned long size) { - return STATIC_OBJECT; + return NULL; } -struct passwd *getpwnam(const char *name) +__attribute__((annotate("REALLOC_RET"))) +char *realloc(void *ptr, unsigned long size) { - return STATIC_OBJECT; + return NULL; } -struct passwd *getpwuid(unsigned int uid) +__attribute__((annotate("REALLOC_RET"))) +void* safe_realloc(void *p, unsigned long n) { - return STATIC_OBJECT; + return NULL; } -struct servent *getservbyname(const char *name, const char *proto) +__attribute__((annotate("REALLOC_RET"))) +void* saferealloc(void *p, unsigned long n1, unsigned long n2) { - return STATIC_OBJECT; + return NULL; } -struct servent *getservbyport(int port, const char *proto) +__attribute__((annotate("REALLOC_RET"))) +void* safexrealloc() { - return STATIC_OBJECT; + return NULL; } -struct spwd *getspnam(const char *name) +__attribute__((annotate("REALLOC_RET"))) +char *strtok(char *str, const char *delim) { - return STATIC_OBJECT; + return NULL; } -char * gettext(const char * msgid) +__attribute__((annotate("REALLOC_RET"))) +char *strtok_r(char *str, const char *delim, char **saveptr) { - return STATIC_OBJECT; + return NULL; } -struct tm *gmtime(const void *timer) +__attribute__((annotate("REALLOC_RET"))) +void *xrealloc(void *ptr, unsigned long bytes) { - return STATIC_OBJECT; + return NULL; } -const char *gnu_get_libc_version(void) +__attribute__((annotate("ALLOC_RET"))) +void *_Znwm(unsigned long size) { - return STATIC_OBJECT; + return NULL; } -const char * gnutls_check_version(const char * req_version) +__attribute__((annotate("ALLOC_RET"))) +void *_ZnwmRKSt9nothrow_t(unsigned long size, void *) { - return STATIC_OBJECT; + return NULL; } -struct lconv *localeconv(void) +__attribute__((annotate("ALLOC_RET"))) +void *_ZnamRKSt9nothrow_t(unsigned long size, void *) { - return STATIC_OBJECT; + return NULL; } -struct tm *localtime(const void *timer) +__attribute__((annotate("ALLOC_ARG0"))) +int asprintf(char **restrict strp, const char *restrict fmt, ...) { - return STATIC_OBJECT; + return 0; } -char * ngettext(const char * msgid, const char * msgid_plural, unsigned long int n) +__attribute__((annotate("ALLOC_ARG0"))) +int vasprintf(char **strp, const char *fmt, void* ap) { - return STATIC_OBJECT; + return 0; } -void *pango_cairo_font_map_get_default(void) +__attribute__((annotate("ALLOC_ARG0"))) +int db_create(void **dbp, void *dbenv, unsigned int flags) { - return STATIC_OBJECT; + return 0; } -char *re_comp(const char *regex) +__attribute__((annotate("ALLOC_ARG0"))) +int gnutls_pkcs12_bag_init(void *a) { - return STATIC_OBJECT; + return 0; } -char *setlocale(int category, const char *locale) +__attribute__((annotate("ALLOC_ARG0"))) +int gnutls_pkcs12_init(void *a) { - return STATIC_OBJECT; + return 0; } -char *tgoto(const char *cap, int col, int row) +__attribute__((annotate("ALLOC_ARG0"))) +int gnutls_x509_crt_init(void *a) { - return STATIC_OBJECT; + return 0; } -char *tparm(char *str, ...) +__attribute__((annotate("ALLOC_ARG0"))) +int gnutls_x509_privkey_init(void *a) { - return STATIC_OBJECT; + return 0; } -const char *zError(int a) +__attribute__((annotate("ALLOC_ARG0"))) +int posix_memalign(void **a, unsigned long b, unsigned long c) { - return STATIC_OBJECT; + return 0; } -__attribute__((annotate("ALLOC_RET"))) -void *fopen(const char *voidname, const char *mode) +__attribute__((annotate("ALLOC_ARG1"))) +int scandir(const char *restrict dirp, struct dirent ***restrict namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)) { - return NULL; + return 0; } -__attribute__((annotate("ALLOC_RET"))) -void *fopen64(const char *voidname, const char *mode) +__attribute__((annotate("ALLOC_ARG2"))) +int XmbTextPropertyToTextList(void *a, void *b, char ***c, int *d) { - return NULL; + return 0; } -__attribute__((annotate("ALLOC_RET"))) -struct dirent64 *readdir64(void *dirp) +__attribute__((annotate("MEMCPY"))) +void llvm_memcpy_p0i8_p0i8_i64(char* dst, char* src, int sz, int flag){} + +__attribute__((annotate("MEMCPY"))) +void llvm_memcpy_p0i8_p0i8_i32(char* dst, char* src, int sz, int flag){} + +__attribute__((annotate("MEMCPY"))) +void llvm_memcpy(char* dst, char* src, int sz, int flag){} + +__attribute__((annotate("MEMCPY"))) +void llvm_memmove(char* dst, char* src, int sz, int flag){} + +__attribute__((annotate("MEMCPY"))) +void llvm_memmove_p0i8_p0i8_i64(char* dst, char* src, int sz, int flag){} + +__attribute__((annotate("MEMCPY"))) +void llvm_memmove_p0i8_p0i8_i32(char* dst, char* src, int sz, int flag){} + +__attribute__((annotate("MEMCPY"))) +void __memcpy_chk(char* dst, char* src, int sz, int flag){} + +__attribute__((annotate("MEMCPY"))) +void *memmove(void *str1, const void *str2, unsigned long n) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -void *tmpvoid64(void) +__attribute__((annotate("MEMCPY"))) +void bcopy(const void *s1, void *s2, unsigned long n){} + +__attribute__((annotate("MEMCPY"))) +void *memccpy( void * restrict dest, const void * restrict src, int c, unsigned long count) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -void *calloc(unsigned long nitems, unsigned long size) +__attribute__((annotate("MEMCPY"))) +void __memmove_chk(char* dst, char* src, int sz){} + +__attribute__((annotate("MEMSET"))) +void llvm_memset(char* dst, char elem, int sz, int flag){} + +__attribute__((annotate("MEMSET"))) +void llvm_memset_p0i8_i32(char* dst, char elem, int sz, int flag){} + +__attribute__((annotate("MEMSET"))) +void llvm_memset_p0i8_i64(char* dst, char elem, int sz, int flag){} + +__attribute__((annotate("MEMSET"))) +char *__memset_chk(char * dest, int c, unsigned long destlen, int flag) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -void *zmalloc(unsigned long size) +__attribute__((annotate("MEMCPY"))) +char * __strcpy_chk(char * dest, const char * src, unsigned long destlen) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -void *gzdopen(int fd, const char *mode) +__attribute__((annotate("MEMCPY"))) +char *__strcat_chk(char * dest, const char * src, unsigned long destlen) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -void *iconv_open(const char *tocode, const char *fromcode) +__attribute__((annotate("MEMCPY"))) +char *stpcpy(char *restrict dst, const char *restrict src) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -void *lalloc(unsigned long size, int a) +__attribute__((annotate("MEMCPY"))) +char *strcat(char *dest, const char *src) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -void *lalloc_clear(unsigned long size, int a) +__attribute__((annotate("MEMCPY"))) +char *strcpy(char *dest, const char *src) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -long *nhalloc(unsigned int a, const char *b, int c) +__attribute__((annotate("MEMCPY"))) +char *strncat(char *dest, const char *src, unsigned long n) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -void *oballoc(unsigned long size) +__attribute__((annotate("MEMCPY"))) +char *strncpy(char *dest, const char *src, unsigned long n) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -void *popen(const char *command, const char *type) +__attribute__((annotate("MEMCPY"))) +unsigned long iconv(void* cd, char **restrict inbuf, unsigned long *restrict inbytesleft, char **restrict outbuf, unsigned long *restrict outbytesleft) { - return NULL; + return 0; } -__attribute__((annotate("ALLOC_RET"))) -void *pthread_getspecific(const char *a, const char *b) +__attribute__((annotate("OVERWRITE"))) +void* _ZNSt5arrayIPK1ALm2EE4backEv(void *arg) { - return NULL; + void* ptr1 = (char*)arg + 0; + void* ptr2 = (char*)ptr1 + 0; + return ptr2; } __attribute__((annotate("ALLOC_RET"))) -struct dirent *readdir(void *dirp) +__attribute__((annotate("OVERWRITE"))) +void *SyGetmem(unsigned long size) { return NULL; } -__attribute__((annotate("ALLOC_RET"))) -void* safe_calloc(unsigned nelem, unsigned elsize) +void * __rawmemchr(const void * s, int c) { - return NULL; + return (void *)s; } -__attribute__((annotate("ALLOC_RET"))) -void* safe_malloc(unsigned long size) +struct jpeg_error_mgr *jpeg_std_error(struct jpeg_error_mgr * a) { - return NULL; + return a; } -__attribute__((annotate("ALLOC_RET"))) -char* safecalloc(int a, int b) +char *fgets(char *str, int n, void *stream) { - return NULL; + return str; } -__attribute__((annotate("ALLOC_RET"))) -char* safemalloc(int a, int b) +void *memchr(const void *str, int c, unsigned long n) { - return NULL; + return (void *)str; } -__attribute__((annotate("ALLOC_RET"))) -void *setmntent(const char *voidname, const char *type) +void * mremap(void * old_address, unsigned long old_size, unsigned long new_size, int flags) { - return NULL; + return old_address; } -__attribute__((annotate("ALLOC_RET"))) -void *shmat(int shmid, const void *shmaddr, int shmflg) +char *strchr(const char *str, int c) { - return NULL; + return (char *)str; } -__attribute__((annotate("ALLOC_RET"))) -void* __sysv_signal(int a, void *b) +char *strerror_r(int errnum, char *buf, unsigned long buflen) { - return NULL; + return buf; } -__attribute__((annotate("ALLOC_RET"))) -void (*signal(int sig, void (*func)(int)))(int) +char *strpbrk(const char *str1, const char *str2) { - return NULL; + return (char *)str1; } -__attribute__((annotate("ALLOC_RET"))) -char *tempnam(const char *dir, const char *pfx) +char *strptime(const void* s, const void* format, void* tm) { - return NULL; + return (char *)s; } -__attribute__((annotate("ALLOC_RET"))) -void *tmpvoid(void) +char *strrchr(const char *str, int c) { - return NULL; + return (char *)str; } -__attribute__((annotate("ALLOC_RET"))) -void* xcalloc(unsigned long size1, unsigned long size2) +char *strstr(const char *haystack, const char *needle) { - return NULL; + return (char *)haystack; } -__attribute__((annotate("ALLOC_RET"))) -void* xmalloc(unsigned long size) +char *tmpnam_r(char *s) { - return NULL; + return s; } -__attribute__((annotate("ALLOC_RET"))) -void *_Znam(unsigned long size) +int isalnum(int character) { - return NULL; + return character; } -__attribute__((annotate("ALLOC_RET"))) -void *_Znaj(unsigned long size) +int isalpha(int character) { - return NULL; + return character; } -__attribute__((annotate("ALLOC_RET"))) -void *_Znwj(unsigned long size) +int isblank(int character) { - return NULL; + return character; } -__attribute__((annotate("ALLOC_RET"))) -void *__cxa_allocate_exception(unsigned long size) +int iscntrl(int c) { - return NULL; + return c; } -__attribute__((annotate("ALLOC_RET"))) -void* aligned_alloc(unsigned long size1, unsigned long size2) +int isdigit(int c) { - return NULL; + return c; } -__attribute__((annotate("ALLOC_RET"))) -void* memalign(unsigned long size1, unsigned long size2) +int isgraph(int c) { - return NULL; + return c; } -__attribute__((annotate("ALLOC_RET"))) -void *valloc(unsigned long size) +int islower( int arg ) { - return NULL; + return arg; } -__attribute__((annotate("ALLOC_RET"))) -void *mmap64(void *addr, unsigned long len, int prot, int flags, int fildes, long off) +int isprint(int c) { - return NULL; + return c; } -__attribute__((annotate("ALLOC_RET"))) -char *XSetLocaleModifiers(char *a) +int ispunct(int argument) { - return NULL; + return argument; } -__attribute__((annotate("ALLOC_RET"))) -char * __strdup(const char * string) +int isspace(char c) { - return NULL; + return c; } -__attribute__((annotate("ALLOC_RET"))) -char *crypt(const char *key, const char *salt) +int isupper(int c) { - return NULL; + return c; } -__attribute__((annotate("ALLOC_RET"))) -char *ctime(const void *timer) +int isxdigit(int c) { - return NULL; + return c; } -__attribute__((annotate("ALLOC_RET"))) -char *dlerror(void) +char *asctime_r(const void *tm, char *buf) { - return NULL; + return buf; } -__attribute__((annotate("ALLOC_RET"))) -void *dlopen(const char *voidname, int flags) +void *bsearch(const void *key, const void *base, unsigned long nitems, unsigned long size, int (*compar)(const void *, const void *)) { - return NULL; + return (void *)base; } -__attribute__((annotate("ALLOC_RET"))) -const char *gai_strerror(int errcode) +struct mntent *getmntent_r(void *fp, struct mntent *mntbuf, char *buf, int buflen) { - return NULL; + return mntbuf; } -__attribute__((annotate("ALLOC_RET"))) -const char *gcry_cipher_algo_name(int errcode) +struct tm *gmtime_r(const void *timer, struct tm *buf) { - return NULL; + return buf; } -__attribute__((annotate("ALLOC_RET"))) -const char *svfgcry_md_algo_name_(int errcode) +char * gzgets(void* file, char * buf, int len) { - return NULL; + return buf; } -__attribute__((annotate("ALLOC_RET"))) -char *getenv(const char *name) +struct tm *localtime_r(const void *timep, struct tm *result) { - return NULL; + return result; } -__attribute__((annotate("ALLOC_RET"))) -char *getlogin(void) +char *realpath(const char *restrict path, char *restrict resolved_path) { - return NULL; + return resolved_path; } -__attribute__((annotate("ALLOC_RET"))) -char *getpass(const char *prompt) +void* freopen64( const char* voidname, const char* mode, void* fp ) { - return NULL; + return fp; } -__attribute__((annotate("ALLOC_RET"))) -const char * gnutls_strerror(int error) +void* freopen(const char* voidname, const char* mode, void* fp) { - return NULL; + return fp; } -__attribute__((annotate("ALLOC_RET"))) -const char *gpg_strerror(unsigned int a) +const char *inet_ntop(int af, const void *restrict src, char *restrict dst, unsigned int size) { - return NULL; + return dst; } -__attribute__((annotate("ALLOC_RET"))) -const char * gzerror(void* file, int * errnum) +double strtod(const char *str, char **endptr) { - return NULL; + *endptr = (char *)str; + return 0.0; } -__attribute__((annotate("ALLOC_RET"))) -char *inet_ntoa(unsigned int in) +float strtof(const char *nptr, char **endptr) { - return NULL; + *endptr = (char *)nptr; + return 0.0; } -__attribute__((annotate("ALLOC_RET"))) -void *initscr(void) +long int strtol(const char *str, char **endptr, int base) { - return NULL; + *endptr = (char *)str; + return 0; } -__attribute__((annotate("ALLOC_RET"))) -void* llvm_stacksave() +long double strtold(const char* str, char** endptr) { - return NULL; + *endptr = (char *)str; + return 0.0; } -__attribute__((annotate("ALLOC_RET"))) -void *mmap(void *addr, unsigned long len, int prot, int flags, int fildes, long off) +unsigned long int strtoul(const char *str, char **endptr, int base) { - return NULL; + *endptr = (char *)str; + return 0; } -__attribute__((annotate("ALLOC_RET"))) -void *newwin(int nlines, int ncols, int begin_y, int begin_x) +int readdir_r(void *__restrict__dir, void *__restrict__entry, void **__restrict__result) { - return NULL; + __restrict__entry = *__restrict__result; + return 0; } -__attribute__((annotate("ALLOC_RET"))) -char *nl_langinfo(int item) +int getpwnam_r(const char *name, void *pwd, char *buf, unsigned long buflen, void **result) { - return NULL; + *result = pwd; + return 0; } -__attribute__((annotate("ALLOC_RET"))) -void *opendir(const char *name) +int getpwuid_r(unsigned int uid, void *pwd, char *buf, unsigned long buflen, void **result) { - return NULL; -} + *result = pwd; + return 0; +} -__attribute__((annotate("ALLOC_RET"))) -void *sbrk(long increment) +void _ZNSt8__detail15_List_node_base7_M_hookEPS0_(void *arg0, void **arg1) { - return NULL; + *arg1 = arg0; } -__attribute__((annotate("ALLOC_RET"))) -char *strdup(const char *s) +void* __dynamic_cast(void* source, const void* sourceTypeInfo, const void* targetTypeInfo, unsigned long castType) { - return NULL; + return source; } -__attribute__((annotate("ALLOC_RET"))) -char *strerror(int errnum) +void _ZNSsC1EPKcRKSaIcE(void **arg0, void *arg1) { - return NULL; + *arg0 = arg1; } -__attribute__((annotate("ALLOC_RET"))) -char *strsignal(int errnum) +void _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EPKcRKS3_(void **arg0, void *arg1) { - return NULL; + *arg0 = arg1; } -__attribute__((annotate("ALLOC_RET"))) -char *textdomain(const char * domainname) +const unsigned short **__ctype_b_loc(void) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_RET"))) -char *tgetstr(char *id, char **area) +int **__ctype_tolower_loc(void) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_RET"))) -char *tigetstr(char *capname) +int **__ctype_toupper_loc(void) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_RET"))) -char *tmpnam(char *s) +int *__errno_location(void) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_RET"))) -char *ttyname(int fd) +int * __h_errno_location(void) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_RET"))) -void *malloc(unsigned long size) +void* __res_state(void) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("REALLOC_RET"))) -char *getcwd(char *buf, unsigned long size) +char *asctime(const void *timeptr) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("REALLOC_RET"))) -char *mem_realloc(void *ptr, unsigned long size) +char * bindtextdomain(const char * domainname, const char * dirname) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("REALLOC_RET"))) -char *realloc(void *ptr, unsigned long size) +char * bind_textdomain_codeset(const char * domainname, const char * codeset) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("REALLOC_RET"))) -void* safe_realloc(void *p, unsigned long n) +char *ctermid(char *s) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("REALLOC_RET"))) -void* saferealloc(void *p, unsigned long n1, unsigned long n2) +char * dcgettext(const char * domainname, const char * msgid, int category) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("REALLOC_RET"))) -void* safexrealloc() +char * dgettext(const char * domainname, const char * msgid) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("REALLOC_RET"))) -char *strtok(char *str, const char *delim) +char * dngettext(const char * domainname, const char * msgid, const char * msgid_plural, unsigned long int n) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("REALLOC_RET"))) -char *strtok_r(char *str, const char *delim, char **saveptr) +void *fdopen(int fd, const char *mode) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("REALLOC_RET"))) -void *xrealloc(void *ptr, unsigned long bytes) +struct group *getgrgid(unsigned int gid) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_RET"))) -void *_Znwm(unsigned long size) +struct group *getgrnam(const char *name) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_RET"))) -void *_ZnwmRKSt9nothrow_t(unsigned long size, void *) +struct hostent *gethostbyaddr(const void *addr, unsigned int len, int type) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_RET"))) -void *_ZnamRKSt9nothrow_t(unsigned long size, void *) +struct hostent *gethostbyname(const char *name) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_ARG0"))) -int asprintf(char **restrict strp, const char *restrict fmt, ...) +struct hostent *gethostbyname2(const char *name, int af) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_ARG0"))) -int vasprintf(char **strp, const char *fmt, void* ap) +struct mntent *getmntent(void *stream) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_ARG0"))) -int db_create(void **dbp, void *dbenv, unsigned int flags) +struct protoent *getprotobyname(const char *name) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_ARG0"))) -int gnutls_pkcs12_bag_init(void *a) +struct protoent *getprotobynumber(int proto) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_ARG0"))) -int gnutls_pkcs12_init(void *a) +struct passwd *getpwent(void) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_ARG0"))) -int gnutls_x509_crt_init(void *a) +struct passwd *getpwnam(const char *name) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_ARG0"))) -int gnutls_x509_privkey_init(void *a) +struct passwd *getpwuid(unsigned int uid) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_ARG0"))) -int posix_memalign(void **a, unsigned long b, unsigned long c) +struct servent *getservbyname(const char *name, const char *proto) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_ARG1"))) -int scandir(const char *restrict dirp, struct dirent ***restrict namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)) +struct servent *getservbyport(int port, const char *proto) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_ARG2"))) -int XmbTextPropertyToTextList(void *a, void *b, char ***c, int *d) +struct spwd *getspnam(const char *name) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -void llvm_memcpy_p0i8_p0i8_i64(char* dst, char* src, int sz, int flag){} - -__attribute__((annotate("MEMCPY"))) -void llvm_memcpy_p0i8_p0i8_i32(char* dst, char* src, int sz, int flag){} - -__attribute__((annotate("MEMCPY"))) -void llvm_memcpy(char* dst, char* src, int sz, int flag){} - -__attribute__((annotate("MEMCPY"))) -void llvm_memmove(char* dst, char* src, int sz, int flag){} - -__attribute__((annotate("MEMCPY"))) -void llvm_memmove_p0i8_p0i8_i64(char* dst, char* src, int sz, int flag){} - -__attribute__((annotate("MEMCPY"))) -void llvm_memmove_p0i8_p0i8_i32(char* dst, char* src, int sz, int flag){} - -__attribute__((annotate("MEMCPY"))) -void __memcpy_chk(char* dst, char* src, int sz, int flag){} - -__attribute__((annotate("MEMCPY"))) -void *memmove(void *str1, const void *str2, unsigned long n) +char * gettext(const char * msgid) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -void bcopy(const void *s1, void *s2, unsigned long n){} - -__attribute__((annotate("MEMCPY"))) -void *memccpy( void * restrict dest, const void * restrict src, int c, unsigned long count) +struct tm *gmtime(const void *timer) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -void __memmove_chk(char* dst, char* src, int sz){} - -__attribute__((annotate("MEMSET"))) -void llvm_memset(char* dst, char elem, int sz, int flag){} - -__attribute__((annotate("MEMSET"))) -void llvm_memset_p0i8_i32(char* dst, char elem, int sz, int flag){} - -__attribute__((annotate("MEMSET"))) -void llvm_memset_p0i8_i64(char* dst, char elem, int sz, int flag){} - -__attribute__((annotate("MEMSET"))) -char *__memset_chk(char * dest, int c, unsigned long destlen, int flag) +const char *gnu_get_libc_version(void) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -char * __strcpy_chk(char * dest, const char * src, unsigned long destlen) +const char * gnutls_check_version(const char * req_version) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -char *__strcat_chk(char * dest, const char * src, unsigned long destlen) +struct lconv *localeconv(void) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -char *stpcpy(char *restrict dst, const char *restrict src) +struct tm *localtime(const void *timer) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -char *strcat(char *dest, const char *src) +char * ngettext(const char * msgid, const char * msgid_plural, unsigned long int n) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -char *strcpy(char *dest, const char *src) +void *pango_cairo_font_map_get_default(void) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -char *strncat(char *dest, const char *src, unsigned long n) +char *re_comp(const char *regex) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -char *strncpy(char *dest, const char *src, unsigned long n) +char *setlocale(int category, const char *locale) { - return NULL; + return STATIC_OBJECT; } -__attribute__((annotate("MEMCPY"))) -unsigned long iconv(void* cd, char **restrict inbuf, unsigned long *restrict inbytesleft, char **restrict outbuf, unsigned long *restrict outbytesleft) +char *tgoto(const char *cap, int col, int row) { - return 0; + return STATIC_OBJECT; } -__attribute__((annotate("OVERWRITE"))) -void* _ZNSt5arrayIPK1ALm2EE4backEv(void *arg) +char *tparm(char *str, ...) { - void* ptr1 = (char*)arg + 0; - void* ptr2 = (char*)ptr1 + 0; - return ptr2; + return STATIC_OBJECT; } -__attribute__((annotate("ALLOC_RET"))) -__attribute__((annotate("OVERWRITE"))) -void *SyGetmem(unsigned long size) +const char *zError(int a) { - return NULL; + return STATIC_OBJECT; } \ No newline at end of file From 459880df66f24416f9d2484a59afc1ca6e72c9fa Mon Sep 17 00:00:00 2001 From: shuangxiang kan <18550887212@163.com> Date: Fri, 8 Sep 2023 18:58:08 +1000 Subject: [PATCH 4/4] annotate fdopen() with "ALLOC_RET" --- svf-llvm/lib/extapi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/svf-llvm/lib/extapi.c b/svf-llvm/lib/extapi.c index 215e28deb..3280d8e95 100644 --- a/svf-llvm/lib/extapi.c +++ b/svf-llvm/lib/extapi.c @@ -32,6 +32,12 @@ void *fopen64(const char *voidname, const char *mode) return NULL; } +__attribute__((annotate("ALLOC_RET"))) +void *fdopen(int fd, const char *mode) +{ + return NULL; +} + __attribute__((annotate("ALLOC_RET"))) struct dirent64 *readdir64(void *dirp) { @@ -968,11 +974,6 @@ char * dngettext(const char * domainname, const char * msgid, const char * msgid return STATIC_OBJECT; } -void *fdopen(int fd, const char *mode) -{ - return STATIC_OBJECT; -} - struct group *getgrgid(unsigned int gid) { return STATIC_OBJECT;