P4 to Git Change 2061101 by skudchad@skudchad_test2_win_opencl on 2020/01/21 16:47:25
SWDEV-219917 - [VDI Cleanup] Remove some direct OpenCL references, introduce a common functionality.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/18488/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/build/Makefile.hip#30 edit
... //depot/stg/opencl/drivers/opencl/api/hip/fixme.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#51 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hiprtc_internal.hpp#3 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/build/Makefile.api#190 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_common.hpp#25 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_context.cpp#61 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_device.cpp#75 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_execute.cpp#31 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_icd.cpp#36 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_platform_amd.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_program.cpp#54 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#610 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#180 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#150 edit
... //depot/stg/opencl/drivers/opencl/runtime/include/vdi_agent_amd.h#1 add
... //depot/stg/opencl/drivers/opencl/runtime/include/vdi_common.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/os/os.hpp#32 edit
... //depot/stg/opencl/drivers/opencl/runtime/os/os_posix.cpp#49 edit
... //depot/stg/opencl/drivers/opencl/runtime/os/os_win32.cpp#50 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/agent.cpp#9 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/agent.hpp#7 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.cpp#54 edit
... //depot/stg/opencl/drivers/opencl/runtime/runtimedefs#54 edit
[ROCm/clr commit: 29dd0eb7a2]
This commit is contained in:
@@ -80,149 +80,6 @@ __declspec(allocate(".CRT$XTU")) void (*__exit)(void) = Os::tearDown;
|
||||
|
||||
void Os::tearDown() { Thread::tearDown(); }
|
||||
|
||||
//#define DEBUG_getExportsFromMemory
|
||||
/**
|
||||
get export symbols from dll given by start address \param dosHeader
|
||||
of dll in memory and push_back
|
||||
addresses and names of exports into \param kernels
|
||||
*/
|
||||
static void getExportsFromMemory(PIMAGE_DOS_HEADER dosHeader, Os::SymbolCallback callback,
|
||||
void* data) {
|
||||
PCHAR base = (PCHAR)dosHeader;
|
||||
PIMAGE_NT_HEADERS pNTHeader = (PIMAGE_NT_HEADERS)(base + dosHeader->e_lfanew);
|
||||
|
||||
DWORD exportsStart =
|
||||
pNTHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
|
||||
|
||||
if (exportsStart == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
PIMAGE_EXPORT_DIRECTORY exportDir = (PIMAGE_EXPORT_DIRECTORY)(base + exportsStart);
|
||||
|
||||
PSTR filename = (PSTR)(exportDir->Name + base);
|
||||
|
||||
#if defined(DEBUG_getExportsFromMemory)
|
||||
printf("\nExports Table:\n");
|
||||
printf(" Name: %s\n", filename);
|
||||
printf(" Characteristics: %08X\n", exportDir->Characteristics);
|
||||
printf(" TimeDateStamp: %08X -> %s", exportDir->TimeDateStamp,
|
||||
ctime((const time_t*)&exportDir->TimeDateStamp));
|
||||
printf(" Version: %u.%02u\n", exportDir->MajorVersion, exportDir->MinorVersion);
|
||||
printf(" Ordinal base: %08X\n", exportDir->Base);
|
||||
printf(" # of functions: %08X\n", exportDir->NumberOfFunctions);
|
||||
printf(" # of Names: %08X\n", exportDir->NumberOfNames);
|
||||
#endif
|
||||
|
||||
/* address of Export Address table (EAT). */
|
||||
PDWORD functions = (PDWORD)(base + (DWORD)exportDir->AddressOfFunctions);
|
||||
DWORD numberOfFunctions = exportDir->NumberOfFunctions;
|
||||
|
||||
/* address of the Export Name Table (ENT).
|
||||
ENT is an array of RVAs to ASCII strings - each string corresponds to
|
||||
a symbol (function or variable) exported by name. */
|
||||
DWORD* name = (DWORD*)(base + (DWORD)exportDir->AddressOfNames);
|
||||
/* \note: number below is always <= numberOfFunctions */
|
||||
DWORD numberOfNames = exportDir->NumberOfNames;
|
||||
|
||||
/* address of the Export Ordinal Table.
|
||||
This table maps an array index from ENT into
|
||||
the corresponding index in EAT.
|
||||
*/
|
||||
PWORD ordinals = (PWORD)(base + (DWORD)exportDir->AddressOfNameOrdinals);
|
||||
|
||||
#if defined(DEBUG_getExportsFromMemory)
|
||||
/* \note On Ordinals and Algorithm Below.
|
||||
|
||||
Each exported symbol has an ordinal number associated with it that can
|
||||
be used to look the exported symbol up. Also, there is almost always
|
||||
an ASCII name associated with the symbol. Expectedly, the exported
|
||||
symbol name is the same as the name of the function or variable, but
|
||||
in general it is not guaranteed. Usually, when an executable imports
|
||||
a symbol, it uses the symbol name rather than its ordinal. If it was
|
||||
always a case the algorithm below could be much simple - just go over
|
||||
all the names and print them, but some functions may be exported only
|
||||
by ordinals. When importing by name, the system just uses the name to
|
||||
look up the export ordinal of the desired symbol, and retrieves the
|
||||
address using the ordinal value. It might be slightly faster if an
|
||||
ordinal had been used in the first place. Exporting and importing by
|
||||
name is solely a convenience for programmers.
|
||||
The use of the ORDINAL keyword in the Exports section of a .DEF file
|
||||
tells the linker to create an import library that forces an API to be
|
||||
imported by ordinal, not by name.
|
||||
The algorithm in the comments shows how to retrieve all the exports in
|
||||
the general case. If we assume that all is exported by names then a
|
||||
simple version (code below) is sufficient.
|
||||
|
||||
\note removed file exportdump.cpp contains examples of reading
|
||||
exported symbols from DLL loaded in memory or file.
|
||||
*/
|
||||
DWORD exportsEnd = pNTHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
|
||||
|
||||
printf("\n Entry Pt Ordn Name\n");
|
||||
for (DWORD ii = 0; ii < numberOfFunctions; ii++) {
|
||||
DWORD entryPoint = functions[ii];
|
||||
|
||||
if (entryPoint == 0) { // Skip over gaps in exported function
|
||||
continue; // ordinals (the entrypoint is 0 for
|
||||
} // these functions).
|
||||
printf(" %08X %4u", entryPoint, ii + exportDir->Base);
|
||||
|
||||
// Browse thru all names and check out if a function has
|
||||
// an associated exported name.
|
||||
for (DWORD jj = 0; jj < exportDir->NumberOfNames; jj++) {
|
||||
if (ordinals[jj] == ii) {
|
||||
printf(" %s", name[jj] + base);
|
||||
}
|
||||
}
|
||||
// Is it a forwarder? If so, the entry point RVA is inside the
|
||||
// .edata section, and is an RVA to the DllName.EntryPointName
|
||||
if ((entryPoint >= exportsStart) && (entryPoint <= exportsEnd)) {
|
||||
printf(" (forwarder -> %s)", entryPoint + base);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
char OpenCL_prefix[] = "___OpenCL_";
|
||||
size_t OpenCL_prefix_sz = sizeof(OpenCL_prefix) - 1;
|
||||
|
||||
for (DWORD jj = 0; jj < numberOfNames; jj++) {
|
||||
const char* OpenCL_name = (const char*)(base + name[jj]);
|
||||
if (strncmp(OpenCL_name, OpenCL_prefix, OpenCL_prefix_sz) == 0) {
|
||||
address addr = (address)(base + functions[ordinals[jj]]);
|
||||
|
||||
unsigned char opcode = *(unsigned char*)addr;
|
||||
if (opcode == 0xE9) { // jmp instruction at address of export name
|
||||
long disp = *(long*)(addr + 1); // dislacement in jmp
|
||||
addr += 5 /* skip instruction */ + disp;
|
||||
}
|
||||
|
||||
#if defined(DEBUG_getExportsFromMemory)
|
||||
printf("%08X: %s\n", addr, OpenCL_name);
|
||||
#endif
|
||||
callback(&OpenCL_name[1], (const void*)addr, data);
|
||||
} else if (strncmp(OpenCL_name, &OpenCL_prefix[1], OpenCL_prefix_sz - 1) == 0) {
|
||||
address addr = (address)(base + functions[ordinals[jj]]);
|
||||
#if defined(DEBUG_getExportsFromMemory)
|
||||
printf("%08X: %s\n", addr, OpenCL_name);
|
||||
#endif
|
||||
callback(OpenCL_name, (const void*)addr, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Os::iterateSymbols(void* handle, SymbolCallback callback, void* data) {
|
||||
PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)handle;
|
||||
if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
|
||||
// checking validity of NT header was removed since we do not want
|
||||
// exception handling. It can be found in rev #21.
|
||||
getExportsFromMemory((PIMAGE_DOS_HEADER)handle, callback, data);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void* Os::loadLibrary_(const char* filename) {
|
||||
if (filename != NULL) {
|
||||
HMODULE hModule = ::LoadLibrary(filename);
|
||||
|
||||
Reference in New Issue
Block a user