[commit: ghc] master, wip/deploy-docs, wip/packaging-fail, wip/run-nofib, wip/windows-32bit: Directly test section alignment, fix internal reloc probing length (d950f11)

git at git.haskell.org git at git.haskell.org
Thu Mar 21 17:00:52 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branches: master,wip/deploy-docs,wip/packaging-fail,wip/run-nofib,wip/windows-32bit
Link       : http://ghc.haskell.org/trac/ghc/changeset/d950f11eff0a5dc0ad950fbd47e3ee32649d1d62/ghc

>---------------------------------------------------------------

commit d950f11eff0a5dc0ad950fbd47e3ee32649d1d62
Author: Artem Pyanykh <artempyanykh at gmail.com>
Date:   Sat Mar 16 18:12:00 2019 +0300

    Directly test section alignment, fix internal reloc probing length


>---------------------------------------------------------------

d950f11eff0a5dc0ad950fbd47e3ee32649d1d62
 rts/linker/MachO.c                                   |  8 ++++++--
 testsuite/tests/rts/linker/Makefile                  |  6 +++---
 testsuite/tests/rts/linker/aligned_mem_access.c      | 14 --------------
 testsuite/tests/rts/linker/aligned_mem_access.stdout |  2 --
 testsuite/tests/rts/linker/all.T                     |  6 +++---
 testsuite/tests/rts/linker/section_alignment.c       | 14 ++++++++++++++
 testsuite/tests/rts/linker/section_alignment.stdout  |  2 ++
 7 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c
index b720077..6e109e5 100644
--- a/rts/linker/MachO.c
+++ b/rts/linker/MachO.c
@@ -977,11 +977,15 @@ relocateSection(ObjectCode* oc, int curSection)
         }
 
         IF_DEBUG(linker, debugBelch("relocateSection: thing = %p\n", (void *) thing));
+
+        /* Thing points to memory within one of the relocated sections. We can
+         * probe the first byte to sanity check internal relocations.
+         */
         if (0 == reloc->r_extern) {
             if (reloc->r_pcrel) {
-                checkProddableBlock(oc, (void *)((char *)thing + baseValue), relocLenBytes);
+                checkProddableBlock(oc, (void *)((char *)thing + baseValue), 1);
             } else {
-                checkProddableBlock(oc, (void *)thing, relocLenBytes);
+                checkProddableBlock(oc, (void *)thing, 1);
             }
         }
 
diff --git a/testsuite/tests/rts/linker/Makefile b/testsuite/tests/rts/linker/Makefile
index 2320d34..edbd291 100644
--- a/testsuite/tests/rts/linker/Makefile
+++ b/testsuite/tests/rts/linker/Makefile
@@ -7,7 +7,7 @@ unsigned_reloc_macho_x64:
 	'$(TEST_HC)' $(TEST_HC_OPTS_NO_RTSOPTS) -v0 --make -no-rtsopts-suggestions -no-hs-main -o runner runner.c
 	./runner unsigned_reloc_macho_x64.o getAnswer
 
-aligned_mem_access:
-	cc -c -o aligned_mem_access.o aligned_mem_access.c
+section_alignment:
+	cc -c -o section_alignment.o section_alignment.c
 	'$(TEST_HC)' $(TEST_HC_OPTS_NO_RTSOPTS) -v0 --make -no-rtsopts-suggestions -no-hs-main -o runner runner.c
-	./runner aligned_mem_access.o foo
+	./runner section_alignment.o isAligned
diff --git a/testsuite/tests/rts/linker/aligned_mem_access.c b/testsuite/tests/rts/linker/aligned_mem_access.c
deleted file mode 100644
index cef90c3..0000000
--- a/testsuite/tests/rts/linker/aligned_mem_access.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <stdio.h>
-#include <immintrin.h>
-
-__m128 mvec   = {1.0, 2.0, 3.0, 42.0};
-float  fvec[] = {.0, .0, .0, .0};
-
-/* Uses movaps instruction to move data between XMMn <-> mem. Fails
- * with segfault when data section is not properly aligned (16 byte).
- */
-long foo(void)
-{
-        _mm_store_ps(fvec, mvec);
-        return (long) fvec[3];
-}
diff --git a/testsuite/tests/rts/linker/aligned_mem_access.stdout b/testsuite/tests/rts/linker/aligned_mem_access.stdout
deleted file mode 100644
index 4b728c2..0000000
--- a/testsuite/tests/rts/linker/aligned_mem_access.stdout
+++ /dev/null
@@ -1,2 +0,0 @@
-Linking: path = aligned_mem_access.o, symname = _foo
-42
\ No newline at end of file
diff --git a/testsuite/tests/rts/linker/all.T b/testsuite/tests/rts/linker/all.T
index 23d79d3..be2e972 100644
--- a/testsuite/tests/rts/linker/all.T
+++ b/testsuite/tests/rts/linker/all.T
@@ -8,9 +8,9 @@ test('unsigned_reloc_macho_x64',
      ],
      run_command, ['$MAKE -s --no-print-directory unsigned_reloc_macho_x64'])
 
-test('aligned_mem_access',
+test('section_alignment',
      [
-         extra_files(['runner.c', 'aligned_mem_access.c']),
+         extra_files(['runner.c', 'section_alignment.c']),
          unless(opsys('darwin') and arch('x86_64'), expect_broken(13624))
      ],
-     run_command, ['$MAKE -s --no-print-directory aligned_mem_access'])
+     run_command, ['$MAKE -s --no-print-directory section_alignment'])
diff --git a/testsuite/tests/rts/linker/section_alignment.c b/testsuite/tests/rts/linker/section_alignment.c
new file mode 100644
index 0000000..a5c9b02
--- /dev/null
+++ b/testsuite/tests/rts/linker/section_alignment.c
@@ -0,0 +1,14 @@
+#include <stdint.h>
+#include <stdalign.h>
+
+int foo = 42;       /* goes to __data, but __data gets page aligned as
+                     * the first section within a segment, so we need
+                     * another section to check the alignment */
+
+alignas(32) int bar = 0;       /* goes to __common that follows __data
+                                * within the same segment */
+
+long isAligned()
+{
+        return ((uintptr_t)&bar & ~(-32)) == 0;
+}
diff --git a/testsuite/tests/rts/linker/section_alignment.stdout b/testsuite/tests/rts/linker/section_alignment.stdout
new file mode 100644
index 0000000..a20cf23
--- /dev/null
+++ b/testsuite/tests/rts/linker/section_alignment.stdout
@@ -0,0 +1,2 @@
+Linking: path = section_alignment.o, symname = _isAligned
+1
\ No newline at end of file



More information about the ghc-commits mailing list