Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix matching parameters and return values for "OVERWRITE" functions a… #1285

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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