Skip to content

Commit

Permalink
Prevent ICD from loading outdated amdocl binary 1.Keep track of libra…
Browse files Browse the repository at this point in the history
…ry name in KHRicdVendorRec 2.Check if library with the same name has already been loaded before adding it in ICD list
  • Loading branch information
lttamd committed Aug 2, 2022
1 parent 7072cf2 commit 1bea2c2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions loader/icd.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ void khrIcdVendorAdd(const char *libraryName)
goto Done;
}

// get the library's file name
const char *libName = libraryName;
const char *c;
for (c = libraryName; *c; ++c)
{
if (*c == DIRECTORY_SYMBOL)
{
libName = c + 1;
}
}

// ensure that we haven't already loaded this vendor
for (vendorIterator = khrIcdVendors; vendorIterator; vendorIterator = vendorIterator->next)
{
Expand All @@ -87,6 +98,11 @@ void khrIcdVendorAdd(const char *libraryName)
KHR_ICD_TRACE("already loaded vendor %s, nothing to do here\n", libraryName);
goto Done;
}
if (!strcmp(vendorIterator->libName, libName))
{
KHR_ICD_TRACE("already loaded library %s, nothing to do here\n", libName);
goto Done;
}
}

// get the library's clGetExtensionFunctionAddress pointer
Expand Down Expand Up @@ -184,6 +200,8 @@ void khrIcdVendorAdd(const char *libraryName)
KHR_ICD_TRACE("failed get platform handle to library\n");
continue;
}
vendor->libName = (char *)malloc(strlen(libName) + 1);
strcpy(vendor->libName, libName);
vendor->clGetExtensionFunctionAddress = p_clGetExtensionFunctionAddress;
vendor->platform = platforms[i];
vendor->suffix = suffix;
Expand Down Expand Up @@ -417,3 +435,15 @@ void khrIcdContextPropertiesGetPlatform(const cl_context_properties *properties,
}
}

void khrIcdFreeLibName()
{
KHRicdVendor *vendorIterator;
for (vendorIterator = khrIcdVendors; vendorIterator; vendorIterator = vendorIterator->next)
{
if (vendorIterator->libName != NULL)
{
free(vendorIterator->libName);
vendorIterator->libName = NULL;
}
}
}
6 changes: 6 additions & 0 deletions loader/icd.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ struct KHRicdVendorRec
// the loaded library object (true type varies on Linux versus Windows)
void *library;

// the file name of the library
char *libName;

// the extension suffix for this platform
char *suffix;

Expand Down Expand Up @@ -160,6 +163,9 @@ void khrIcdContextPropertiesGetPlatform(
const cl_context_properties *properties,
cl_platform_id *outPlatform);

// free libName in KHRicdVendorRec struct
void khrIcdFreeLibName();

// internal tracing macros
#define KHR_ICD_TRACE(...) \
do \
Expand Down
2 changes: 2 additions & 0 deletions loader/linux/icd_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ void khrIcdOsVendorsEnumerate(void)
closedir(dir);
}

khrIcdFreeLibName();

if (NULL != envPath)
{
khrIcd_free_getenv(envPath);
Expand Down
3 changes: 3 additions & 0 deletions loader/windows/icd_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ BOOL CALLBACK khrIcdOsVendorsEnumerate(PINIT_ONCE InitOnce, PVOID Parameter, PVO
{
KHR_ICD_TRACE("Failed to close platforms key %s, ignoring\n", platformsName);
}

khrIcdFreeLibName();

#if defined(CL_ENABLE_LAYERS)
khrIcdLayersEnumerateEnv();
#endif // defined(CL_ENABLE_LAYERS)
Expand Down

0 comments on commit 1bea2c2

Please sign in to comment.