[Git][ghc/ghc][wip/romes/rts-linker-direct-symbol-lookup] testsuite: Add test for lookupSymbolInNativeObj

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Wed Apr 3 21:50:23 UTC 2024



Ben Gamari pushed to branch wip/romes/rts-linker-direct-symbol-lookup at Glasgow Haskell Compiler / GHC


Commits:
00f908b0 by Ben Gamari at 2024-04-03T17:41:37-04:00
testsuite: Add test for lookupSymbolInNativeObj

- - - - -


5 changed files:

- + testsuite/tests/rts/linker/lookupSymbolInNativeObj/Makefile
- + testsuite/tests/rts/linker/lookupSymbolInNativeObj/all.T
- + testsuite/tests/rts/linker/lookupSymbolInNativeObj/lookupSymbolInNativeObj1.c
- + testsuite/tests/rts/linker/lookupSymbolInNativeObj/lookupSymbolInNativeObj1.stdout
- + testsuite/tests/rts/linker/lookupSymbolInNativeObj/obj.c


Changes:

=====================================
testsuite/tests/rts/linker/lookupSymbolInNativeObj/Makefile
=====================================
@@ -0,0 +1,9 @@
+TOP=../../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+lookupSymbolInNativeObj1:
+	'$(TEST_HC)' -shared -dynamic obj.c -o libobj.so
+	'$(TEST_HC)' -no-hs-main -dynamic lookupSymbolInNativeObj1.c -o main
+	./main
+


=====================================
testsuite/tests/rts/linker/lookupSymbolInNativeObj/all.T
=====================================
@@ -0,0 +1,5 @@
+test('lookupSymbolInNativeObj1',
+     [unless(have_dynamic(), skip),
+      extra_files(['obj.c'])],
+     makefile_test, [])
+


=====================================
testsuite/tests/rts/linker/lookupSymbolInNativeObj/lookupSymbolInNativeObj1.c
=====================================
@@ -0,0 +1,39 @@
+#include "Rts.h"
+
+#if defined(mingw32_HOST_OS)
+#define PATH_STR(str) L##str
+#else
+#define PATH_STR(str) str
+#endif
+
+typedef void (*hello_t)();
+
+int main(int argc, char *argv[])
+{
+  RtsConfig conf = defaultRtsConfig;
+  conf.rts_opts_enabled = RtsOptsAll;
+  hs_init_ghc(&argc, &argv, conf);
+
+  initLinker_(0);
+
+  int ok;
+  char *errmsg;
+  void *obj = loadNativeObj("./libobj.so", &errmsg);
+  if (!obj) {
+     barf("loadNativeObj failed: %s", errmsg);
+  }
+
+  hello_t sym;
+  sym = lookupSymbolInNativeObj(obj, "hello");
+  if (sym == NULL) {
+     barf("lookupSymbolInNativeObj failed unexpectedly");
+  }
+  sym();
+
+  sym = lookupSymbolInNativeObj(obj, "hello_world");
+  if (sym != NULL) {
+     barf("lookupSymbolInNativeObj succeeded unexpectedly");
+  }
+
+  return 0;
+}


=====================================
testsuite/tests/rts/linker/lookupSymbolInNativeObj/lookupSymbolInNativeObj1.stdout
=====================================
@@ -0,0 +1 @@
+hello world


=====================================
testsuite/tests/rts/linker/lookupSymbolInNativeObj/obj.c
=====================================
@@ -0,0 +1,5 @@
+#include <stdio.h>
+
+void hello() {
+  printf("hello world\n");
+}



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/00f908b07ae52b0ecfea90eb708a309da0257abe

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/00f908b07ae52b0ecfea90eb708a309da0257abe
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240403/e7592da6/attachment-0001.html>


More information about the ghc-commits mailing list