summaryrefslogtreecommitdiff
path: root/testsuite/tests
diff options
context:
space:
mode:
authorArtem Pyanykh <artempyanykh@gmail.com>2019-02-21 12:10:38 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-03-20 19:52:39 -0400
commit368187591a5454e47c4e08dae90d39d2af1fad40 (patch)
treece6b0c92dc5b0b9b493a33421bbe1f71ae915e6c /testsuite/tests
parent3394a7cd27cec64a577ee0a9df887a431ccb3696 (diff)
downloadhaskell-368187591a5454e47c4e08dae90d39d2af1fad40.tar.gz
Adjust section placement and relocation logic for Mach-O
1. Place each section on a separate page to ensure required alignment (wastes lots ot space, needs to be improved). 2. Unwire relocation logic from macho sections (the most fiddly part is adjusting internal relocations). Other todos: 0. Add a test for section alignment. 1. Investigate 32bit relocations! 2. Fix memory leak in ZEROPAGE section allocation. 3. Fix creating redundant jump islands for GOT. 4. Investigate more compact section placement.
Diffstat (limited to 'testsuite/tests')
-rw-r--r--testsuite/tests/rts/linker/Makefile8
-rw-r--r--testsuite/tests/rts/linker/all.T9
-rwxr-xr-xtestsuite/tests/rts/linker/runnerbin0 -> 1528176 bytes
-rw-r--r--testsuite/tests/rts/linker/runner.c65
-rw-r--r--testsuite/tests/rts/linker/unsigned_reloc_macho_64.s11
-rw-r--r--testsuite/tests/rts/linker/unsigned_reloc_macho_64.stdout2
6 files changed, 95 insertions, 0 deletions
diff --git a/testsuite/tests/rts/linker/Makefile b/testsuite/tests/rts/linker/Makefile
new file mode 100644
index 0000000000..c5d80faa3f
--- /dev/null
+++ b/testsuite/tests/rts/linker/Makefile
@@ -0,0 +1,8 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+unsigned_reloc_macho_64:
+ as -o unsigned_reloc_macho_64.o unsigned_reloc_macho_64.s
+ '$(TEST_HC)' $(TEST_HC_OPTS_NO_RTSOPTS) -v0 --make -no-rtsopts-suggestions -no-hs-main -o runner -debug runner.c
+ ./runner unsigned_reloc_macho_64.o getAnswer
diff --git a/testsuite/tests/rts/linker/all.T b/testsuite/tests/rts/linker/all.T
new file mode 100644
index 0000000000..d1b3c22b27
--- /dev/null
+++ b/testsuite/tests/rts/linker/all.T
@@ -0,0 +1,9 @@
+# -*-: mode: python -*-
+
+test('unsigned_reloc_macho_64',
+ [
+ extra_files(['runner.c', 'unsigned_reloc_macho_64.s']),
+ unless(opsys('darwin'), skip),
+ unless(arch('x86_64'), skip)
+ ],
+ run_command, ['$MAKE -s --no-print-directory unsigned_reloc_macho_64'])
diff --git a/testsuite/tests/rts/linker/runner b/testsuite/tests/rts/linker/runner
new file mode 100755
index 0000000000..7771d4ab57
--- /dev/null
+++ b/testsuite/tests/rts/linker/runner
Binary files differ
diff --git a/testsuite/tests/rts/linker/runner.c b/testsuite/tests/rts/linker/runner.c
new file mode 100644
index 0000000000..7c34ac284a
--- /dev/null
+++ b/testsuite/tests/rts/linker/runner.c
@@ -0,0 +1,65 @@
+#include <Rts.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#define MAX_SYMNAME 256
+
+typedef long (*fun_t)(void);
+
+int main(int argc, char *argv[])
+{
+ fun_t f;
+ int ok;
+ char * objpath;
+
+ hs_init(&argc, &argv);
+
+ initLinker();
+
+ if (argc < 3) {
+ errorBelch("usage: runner <objpath> <symname>");
+ exit(1);
+ }
+ objpath = argv[1];
+
+#ifdef darwin_HOST_OS
+ char symname[MAX_SYMNAME + 1];
+ symname[0] = '_';
+ strncpy(&symname[1], argv[2], MAX_SYMNAME);
+#else
+ char * symname = argv[2];
+#endif
+
+ printf("Linking: path = %s, symname = %s\n", objpath, symname);
+
+ ok = loadObj(objpath);
+ if (!ok) {
+ errorBelch("loadObj(%s) failed", objpath);
+ exit(1);
+ }
+
+ ok = resolveObjs();
+ if (!ok) {
+ errorBelch("resolveObjs failed");
+ exit(1);
+ }
+
+ f = lookupSymbol(symname);
+ if (!f) {
+ errorBelch("lookupSymbol failed");
+ exit(1);
+ }
+
+ printf("%ld\n", f());
+
+ ok = unloadObj(objpath);
+ if (!ok) {
+ errorBelch("unloadObj(%s) failed", objpath);
+ exit(1);
+ }
+
+ return 0;
+}
+
diff --git a/testsuite/tests/rts/linker/unsigned_reloc_macho_64.s b/testsuite/tests/rts/linker/unsigned_reloc_macho_64.s
new file mode 100644
index 0000000000..733c9863bd
--- /dev/null
+++ b/testsuite/tests/rts/linker/unsigned_reloc_macho_64.s
@@ -0,0 +1,11 @@
+ .text
+ .globl _getAnswer
+
+_getAnswer:
+ mov L2(%rip), %rdx
+ movq (%rdx), %rax
+ ret
+
+ .data
+L1: .quad 42
+L2: .quad L1
diff --git a/testsuite/tests/rts/linker/unsigned_reloc_macho_64.stdout b/testsuite/tests/rts/linker/unsigned_reloc_macho_64.stdout
new file mode 100644
index 0000000000..8251451f5f
--- /dev/null
+++ b/testsuite/tests/rts/linker/unsigned_reloc_macho_64.stdout
@@ -0,0 +1,2 @@
+Linking: path = unsigned_reloc_macho_64.o, symname = _getAnswer
+42 \ No newline at end of file