| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 #include <stdio.h> | 
|  | 2 #include <string.h> | 
|  | 3 | 
|  | 4 /* This is a libdl emulation library which provides the statically-linked LLVM | 
|  | 5  * gold plugin as if it were dynamically loaded. | 
|  | 6  * | 
|  | 7  * The only supported usage is the following: | 
|  | 8  * | 
|  | 9  *   void *plugin = dlopen("LLVMgold", RTLD_NOW); | 
|  | 10  *   void *onload_function = dlsym(plugin, "onload"); | 
|  | 11  */ | 
|  | 12 | 
|  | 13 | 
|  | 14 /* This must match RTLD_NOW in dlwrap.h */ | 
|  | 15 #define RTLD_NOW   0x2 | 
|  | 16 | 
|  | 17 static int dummy; | 
|  | 18 static int haserr = 0; | 
|  | 19 static char errmsg[200]; | 
|  | 20 | 
|  | 21 /* This is not the real signature of this function, | 
|  | 22  * but we just need the symbol address. | 
|  | 23  */ | 
|  | 24 void llvm_plugin_onload(); | 
|  | 25 | 
|  | 26 void *pnacl_dlopen(const char *filename, int flag) { | 
|  | 27   void *ret; | 
|  | 28   if (flag != 0 && flag != RTLD_NOW) { | 
|  | 29     sprintf(errmsg, "Error: Unknown flag to pnacl_dlopen: %d\n", flag); | 
|  | 30     haserr = 1; | 
|  | 31     return NULL; | 
|  | 32   } | 
|  | 33   if (strstr(filename, "LLVMgold") == NULL) { | 
|  | 34     sprintf(errmsg, "Error: Unexpected pnacl_dlopen: %s\n", filename); | 
|  | 35     haserr = 1; | 
|  | 36     return NULL; | 
|  | 37   } | 
|  | 38   return (void*)&dummy; | 
|  | 39 } | 
|  | 40 | 
|  | 41 char *pnacl_dlerror(void) { | 
|  | 42   if (haserr) { | 
|  | 43     haserr = 0; | 
|  | 44     return errmsg; | 
|  | 45   } | 
|  | 46   return NULL; | 
|  | 47 } | 
|  | 48 | 
|  | 49 void *pnacl_dlsym(void *handle, const char *symbol) { | 
|  | 50   if (handle != (void*)&dummy) { | 
|  | 51     sprintf(errmsg, "Error: Unexpected pnacl_dlsym handle\n"); | 
|  | 52     haserr = 1; | 
|  | 53     return NULL; | 
|  | 54   } | 
|  | 55 | 
|  | 56   if (strcmp(symbol, "onload") != 0) { | 
|  | 57     sprintf(errmsg, "Error: Unexpected pnacl_dlsym symbol: %s\n", symbol); | 
|  | 58     haserr = 1; | 
|  | 59     return NULL; | 
|  | 60   } | 
|  | 61   return (void*)&llvm_plugin_onload; | 
|  | 62 } | 
|  | 63 | 
|  | 64 int pnacl_dlclose(void *handle) { | 
|  | 65   return 0; | 
|  | 66 } | 
| OLD | NEW | 
|---|