Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Unified Diff: dlwrap/dlwrap.c

Issue 8713008: Add dlwrap.c to binutils to simulate dlopen/dlsym for gold plugin (Closed)
Patch Set: x Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dlwrap/dlwrap.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dlwrap/dlwrap.c
===================================================================
new file mode 100644
--- /dev/null
+++ b/dlwrap/dlwrap.c
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include <string.h>
+
+/* This is a libdl emulation library which provides the statically-linked LLVM
+ * gold plugin as if it were dynamically loaded.
+ *
+ * The only supported usage is the following:
+ *
+ * void *plugin = dlopen("LLVMgold", RTLD_NOW);
+ * void *onload_function = dlsym(plugin, "onload");
+ */
+
+
+/* This must match RTLD_NOW in dlwrap.h */
+#define RTLD_NOW 0x2
+
+static int dummy;
+static int haserr = 0;
+static char errmsg[200];
+
+/* This is not the real signature of this function,
+ * but we just need the symbol address.
+ */
+void llvm_plugin_onload();
+
+void *pnacl_dlopen(const char *filename, int flag) {
+ void *ret;
+ if (flag != 0 && flag != RTLD_NOW) {
+ sprintf(errmsg, "Error: Unknown flag to pnacl_dlopen: %d\n", flag);
+ haserr = 1;
+ return NULL;
+ }
+ if (strstr(filename, "LLVMgold") == NULL) {
+ sprintf(errmsg, "Error: Unexpected pnacl_dlopen: %s\n", filename);
+ haserr = 1;
+ return NULL;
+ }
+ return (void*)&dummy;
+}
+
+char *pnacl_dlerror(void) {
+ if (haserr) {
+ haserr = 0;
+ return errmsg;
+ }
+ return NULL;
+}
+
+void *pnacl_dlsym(void *handle, const char *symbol) {
+ if (handle != (void*)&dummy) {
+ sprintf(errmsg, "Error: Unexpected pnacl_dlsym handle\n");
+ haserr = 1;
+ return NULL;
+ }
+
+ if (strcmp(symbol, "onload") != 0) {
+ sprintf(errmsg, "Error: Unexpected pnacl_dlsym symbol: %s\n", symbol);
+ haserr = 1;
+ return NULL;
+ }
+ return (void*)&llvm_plugin_onload;
+}
+
+int pnacl_dlclose(void *handle) {
+ return 0;
+}
« no previous file with comments | « dlwrap/dlwrap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698