Skip to content

Commit

Permalink
Merge pull request #1285 from shuangxiangkan/master
Browse files Browse the repository at this point in the history
Fix #1277 by matching parameters and return values for "OVERWRITE" functions a…
  • Loading branch information
yuleisui authored Dec 18, 2023
2 parents 0cb0fff + 8f21529 commit 0008685
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 5 deletions.
36 changes: 36 additions & 0 deletions svf-llvm/lib/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,42 @@ void LLVMModuleSet::buildFunToFunMap()
{
if (appfunc->getName().str().compare(owfunc->getName().str()) == 0)
{
Type* returnType1 = appfunc->getReturnType();
Type* returnType2 = owfunc->getReturnType();

// Check if the return types are compatible:
// (1) The types are exactly the same,
// (2) Both are pointer types, and at least one of them is a void*.
// Note that getPointerElementType() will be deprecated in the future versions of LLVM.
// Considering compatibility, avoid using getPointerElementType()->isIntegerTy(8) to determine if it is a void * type.
if (!(returnType1 == returnType2 || (returnType1->isPointerTy() && returnType2->isPointerTy())))
{
continue;
}

if (appfunc->arg_size() != owfunc->arg_size())
continue;

bool argMismatch = false;
Function::const_arg_iterator argIter1 = appfunc->arg_begin();
Function::const_arg_iterator argIter2 = owfunc->arg_begin();
while (argIter1 != appfunc->arg_end() && argIter2 != owfunc->arg_end())
{
Type* argType1 = argIter1->getType();
Type* argType2 = argIter2->getType();

// Check if the parameters types are compatible: (1) The types are exactly the same, (2) Both are pointer types, and at least one of them is a void*.
if (!(argType1 == argType2 || (argType1->isPointerTy() && argType2->isPointerTy())))
{
argMismatch = true;
break;
}
argIter1++;
argIter2++;
}
if (argMismatch)
continue;

Function* fun = const_cast<Function*>(appfunc);
Module* mod = fun->getParent();
FunctionType* funType = fun->getFunctionType();
Expand Down
88 changes: 83 additions & 5 deletions svf-llvm/lib/extapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,20 @@ void* safexrealloc()
return NULL;
}

__attribute__((annotate("REALLOC_RET"), annotate("AllocSize:UNKNOWN")))

char *strtok(char *str, const char *delim)
{
return NULL;
return str;
}

__attribute__((annotate("REALLOC_RET"), annotate("AllocSize:UNKNOWN")))
char *strtok_r(char *str, const char *delim, char **saveptr)
{
return NULL;
return str;
}

char* strsep(char** stringp, const char* delim)
{
return *stringp;
}

__attribute__((annotate("REALLOC_RET"), annotate("AllocSize:Arg1")))
Expand Down Expand Up @@ -727,11 +731,26 @@ char *fgets(char *str, int n, void *stream)
return str;
}

char *fgets_unlocked(char *str, int n, void *stream)
{
return str;
}

char* gets(char *str)
{
return str;
}

void *memchr(const void *str, int c, unsigned long n)
{
return (void *)str;
}

void *memrchr(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;
Expand All @@ -742,6 +761,26 @@ char *strchr(const char *str, int c)
return (char *)str;
}

char *__strchrnull(const char *s, int c)
{
return (char *)s;
}

char *strcasestr(const char *haystack, const char *needle)
{
return (char *)haystack;
}

char* index(const char *s, int c)
{
return (char *)s;
}

char* rindex(const char *s, int c)
{
return (char *)s;
}

char *strerror_r(int errnum, char *buf, unsigned long buflen)
{
return buf;
Expand Down Expand Up @@ -888,18 +927,36 @@ double strtod(const char *str, char **endptr)
return 0.0;
}

double strtod_l(const char *str, char **endptr, void *loc)
{
*endptr = (char *)str;
return 0.0;
}

float strtof(const char *nptr, char **endptr)
{
*endptr = (char *)nptr;
return 0.0;
}

float strtof_l(const char *nptr, char **endptr, void *loc)
{
*endptr = (char *)nptr;
return 0.0;
}

long int strtol(const char *str, char **endptr, int base)
{
*endptr = (char *)str;
return 0;
}

long long strtoll(const char *str, char **endptr, int base)
{
*endptr = (char *)str;
return 0;
}

long double strtold(const char* str, char** endptr)
{
*endptr = (char *)str;
Expand All @@ -912,6 +969,27 @@ unsigned long int strtoul(const char *str, char **endptr, int base)
return 0;
}

unsigned long long strtoull(const char *str, char **endptr, int base)
{
*endptr = (char *)str;
return 0;
}

char *gcvt(double x, int ndigit, char *buf)
{
return buf;
}

void *memmem(const void *haystack, unsigned long haystacklen, const void *needle, unsigned long needlelen)
{
return (void *)haystack;
}

char* ctime_r(const char *timer, char *buf)
{
return buf;
}

int readdir_r(void *__restrict__dir, void *__restrict__entry, void **__restrict__result)
{
__restrict__entry = *__restrict__result;
Expand Down Expand Up @@ -997,7 +1075,7 @@ char * bind_textdomain_codeset(const char * domainname, const char * codeset)

char *ctermid(char *s)
{
return STATIC_OBJECT;
return s;
}

char * dcgettext(const char * domainname, const char * msgid, int category)
Expand Down

0 comments on commit 0008685

Please sign in to comment.