[Git][ghc/ghc][wip/T21191] 5 commits: rts: Fix size of StgOrigThunkInfo frames

Peter Trommler (@trommler) gitlab at gitlab.haskell.org
Wed May 22 20:24:50 UTC 2024



Peter Trommler pushed to branch wip/T21191 at Glasgow Haskell Compiler / GHC


Commits:
6d7e6ad8 by Ben Gamari at 2024-05-22T13:40:05-04:00
rts: Fix size of StgOrigThunkInfo frames

Previously the entry code of the `stg_orig_thunk` frame failed to
account for the size of the profiling header as it hard-coded the frame
size. Fix this.

Fixes #24809.

- - - - -
c645fe40 by Fendor at 2024-05-22T13:40:05-04:00
Add regression test T24809 for stg_orig_thunk_info_frame size

- - - - -
4181aa40 by Andreas Klebinger at 2024-05-22T13:40:42-04:00
bindists: Check for existence of share folder before trying to copy it.

This folder isn't distributed in windows bindists

A lack of doing so resulted us copying loads of files twice.

- - - - -
d216510e by Matthew Pickering at 2024-05-22T13:40:42-04:00
Remove ad-hoc installation of mingw toolchain in relocatable bindists

This reverts 616ac30026e8dd7d2ebb98d92dde071eedf5d951

The choice about whether to install mingw is taken in the installation
makefile.

This is also broken on non-windows systems.

The actual issue was the EnableDistroToolchain variable wasn't declared
in mk/config.mk and therefore the check to install mingw was failing.

- - - - -
3677d06f by Peter Trommler at 2024-05-22T20:24:44+00:00
PPC: Support ELF v2 on powerpc64 big-endian

Detect ELF v2 on PowerPC 64-bit systems. Check for `_CALL_ELF`
preprocessor macro.

Fixes #21191

- - - - -


15 changed files:

- compiler/GHC/CmmToAsm/PPC/CodeGen.hs
- hadrian/bindist/Makefile
- hadrian/bindist/config.mk.in
- hadrian/src/Rules/BinaryDist.hs
- libraries/ghc-platform/src/GHC/Platform/ArchOS.hs
- m4/fptools_set_haskell_platform_vars.m4
- + m4/ghc_get_power_abi.m4
- rts/AdjustorAsm.S
- rts/StgCRun.c
- rts/StgCRunAsm.S
- rts/StgMiscClosures.cmm
- rts/adjustor/NativePowerPC.c
- + testsuite/tests/codeGen/should_run/T24809.hs
- + testsuite/tests/codeGen/should_run/T24809.stdout
- testsuite/tests/codeGen/should_run/all.T


Changes:

=====================================
compiler/GHC/CmmToAsm/PPC/CodeGen.hs
=====================================
@@ -1912,8 +1912,15 @@ genCCall' config gcp target dest_regs args
                          -- "Single precision floating point values
                          -- are mapped to the second word in a single
                          -- doubleword"
-                         GCP64ELF 1      -> stackOffset' + 4
-                         _               -> stackOffset'
+                         GCP64ELF 1 -> stackOffset' + 4
+                         -- ELF v2 ABI Revision 1.5 Section 2.2.3.3. requires
+                         -- a single-precision floating-point value
+                         -- to be mapped to the least-significant
+                         -- word in a single doubleword.
+                         GCP64ELF 2 -> case platformByteOrder platform of
+                                       BigEndian    -> stackOffset' + 4
+                                       LittleEndian -> stackOffset'
+                         _          -> stackOffset'
                      | otherwise = stackOffset'
 
                 stackSlot = AddrRegImm sp (ImmInt stackOffset'')


=====================================
hadrian/bindist/Makefile
=====================================
@@ -55,10 +55,11 @@ show:
 
 .PHONY: install_extra
 ifeq "$(EnableDistroToolchain)" "NO"
+ifeq "$(Windows_Host)" "YES"
 install_extra: install_mingw
-else
-install_extra:
 endif
+endif
+install_extra:
 
 .PHONY: install_bin
 ifeq "$(RelocatableBuild)" "YES"
@@ -211,10 +212,12 @@ install_docs:
 install_data:
 	@echo "Copying data to $(DESTDIR)share"
 	$(INSTALL_DIR) "$(DESTDIR)$(datadir)"
-	cd share; $(FIND) . -type f -exec sh -c \
-		'$(INSTALL_DIR) "$(DESTDIR)$(datadir)/`dirname $$1`" && \
-		$(INSTALL_DATA) "$$1" "$(DESTDIR)$(datadir)/`dirname $$1`"' \
-		sh '{}' ';';
+	if [ -d share ]; then \
+		cd share; $(FIND) . -type f -exec sh -c \
+			'$(INSTALL_DIR) "$(DESTDIR)$(datadir)/`dirname $$1`" && \
+			$(INSTALL_DATA) "$$1" "$(DESTDIR)$(datadir)/`dirname $$1`"' \
+			sh '{}' ';'; \
+	fi
 
 MAN_SECTION := 1
 MAN_PAGES := manpage/ghc.1


=====================================
hadrian/bindist/config.mk.in
=====================================
@@ -133,6 +133,7 @@ INSTALL_DIR     = $(INSTALL) -m 755 -d
 CrossCompiling        = @CrossCompiling@
 CrossCompilePrefix    = @CrossCompilePrefix@
 GhcUnregisterised     = @Unregisterised@
+EnableDistroToolchain = @SettingsUseDistroMINGW@
 
 # The THREADED_RTS requires `BaseReg` to be in a register and the
 # `GhcUnregisterised` mode doesn't allow that.
@@ -226,3 +227,4 @@ SettingsOptCommand = @SettingsOptCommand@
 SettingsLlvmAsCommand = @SettingsLlvmAsCommand@
 SettingsUseDistroMINGW = @SettingsUseDistroMINGW@
 
+


=====================================
hadrian/src/Rules/BinaryDist.hs
=====================================
@@ -135,8 +135,6 @@ bindistRules = do
         let ghcVersionPretty = "ghc-" ++ version ++ "-" ++ targetPlatform
         let prefix = cwd -/- root -/- "reloc-bindist" -/- ghcVersionPretty
         installTo Relocatable prefix
-        copyDirectory (root -/- "mingw") prefix
-        liftIO $ IO.removeDirectoryRecursive (prefix -/- "lib" -/- "mingw")
 
     phony "install" $ do
         need ["binary-dist-dir"]


=====================================
libraries/ghc-platform/src/GHC/Platform/ArchOS.hs
=====================================
@@ -126,8 +126,7 @@ stringEncodeArch = \case
   ArchX86           -> "i386"
   ArchX86_64        -> "x86_64"
   ArchPPC           -> "powerpc"
-  ArchPPC_64 ELF_V1 -> "powerpc64"
-  ArchPPC_64 ELF_V2 -> "powerpc64le"
+  ArchPPC_64 _      -> "powerpc64"
   ArchS390X         -> "s390x"
   ArchARM ARMv5 _ _ -> "armv5"
   ArchARM ARMv6 _ _ -> "armv6"


=====================================
m4/fptools_set_haskell_platform_vars.m4
=====================================
@@ -14,11 +14,9 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS],
         powerpc)
             test -z "[$]2" || eval "[$]2=ArchPPC"
             ;;
-        powerpc64)
-            test -z "[$]2" || eval "[$]2=\"ArchPPC_64 ELF_V1\""
-            ;;
-        powerpc64le)
-            test -z "[$]2" || eval "[$]2=\"ArchPPC_64 ELF_V2\""
+        powerpc64*)
+            GHC_GET_POWER_ABI()
+            test -z "[$]2" || eval "[$]2=\"ArchPPC_64 $POWER_ABI\""
             ;;
         s390x)
             test -z "[$]2" || eval "[$]2=ArchS390X"


=====================================
m4/ghc_get_power_abi.m4
=====================================
@@ -0,0 +1,19 @@
+# GHC_GET_POWER_ABI
+# ----------------------------------
+# Get version of the PowerPC ABI
+AC_DEFUN([GHC_GET_POWER_ABI],
+[
+    AC_COMPILE_IFELSE([
+        AC_LANG_PROGRAM(
+            [],
+            [#if defined(_CALL_ELF) && _CALL_ELF == 2
+                 return 0;
+             #else
+                 not ELF v2
+             #endif]
+        )],
+        [POWER_ABI=ELF_V2],
+        [POWER_ABI=ELF_V1])
+
+        AC_SUBST(POWER_ABI)
+])


=====================================
rts/AdjustorAsm.S
=====================================
@@ -2,8 +2,7 @@
 
 /* ******************************** PowerPC ******************************** */
 
-#if defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH)
-#if !(defined(powerpc_HOST_ARCH) && defined(linux_HOST_OS))
+#if defined(powerpc_HOST_ARCH) && defined(aix_HOST_OS) || defined(powerpc64_HOST_ARCH) && defined(__ELF__) && (!defined(_CALL_ELF) || _CALL_ELF == 1)
     /* The following code applies, with some differences,
        to all powerpc platforms except for powerpc32-linux,
        whose calling convention is annoyingly complex.
@@ -60,12 +59,12 @@ adjustorCode:
         /* save the link */
     mflr    0
     STORE   0, LINK_SLOT(1)
-    
+
         /* set up stack frame */
     LOAD    12, FRAMESIZE_OFF(2)
 #if defined(powerpc64_HOST_ARCH)
     stdux   1, 1, 12
-#else   
+#else
     stwux   1, 1, 12
 #endif /* defined(powerpc64_HOST_ARCH) */
 
@@ -108,7 +107,7 @@ L2:
     LOAD    12, WPTR_OFF(2)
     LOAD    0, 0(12)
         /* The function we're calling will never be a nested function,
-           so we don't load r11. 
+           so we don't load r11.
         */
     mtctr   0
     LOAD    2, WS(12)
@@ -118,8 +117,7 @@ L2:
     LOAD    0, LINK_SLOT(1)
     mtlr    0
     blr
-#endif /* !(defined(powerpc_HOST_ARCH) && defined(linux_HOST_OS)) */
-#endif /* defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) */
+#endif
 
 /* mark stack as nonexecutable */
 #if defined(__linux__) && defined(__ELF__)


=====================================
rts/StgCRun.c
=====================================
@@ -670,7 +670,7 @@ StgRunIsImplementedInAssembler(void)
    Everything is in assembler, so we don't have to deal with GCC...
    -------------------------------------------------------------------------- */
 
-#if defined(powerpc64_HOST_ARCH)
+#if defined(powerpc64_HOST_ARCH) && (!defined _CALL_ELF || _CALL_ELF == 1)
 /* 64-bit PowerPC ELF ABI 1.9
  *
  * Stack frame organization (see Figure 3-17, ELF ABI 1.9, p 14)


=====================================
rts/StgCRunAsm.S
=====================================
@@ -5,11 +5,11 @@
  * then functions StgRun/StgReturn are implemented in file StgCRun.c */
 #if !defined(USE_MINIINTERPRETER)
 
-#if defined(powerpc64le_HOST_ARCH)
-# if defined(linux_HOST_OS)
-/* 64-bit PowerPC ELF V2 ABI Revision 1.4
+#if defined(powerpc64le_HOST_ARCH) || defined(powerpc64_HOST_ARCH)
+# if defined(_CALL_ELF) && _CALL_ELF == 2
+/* 64-bit PowerPC ELF V2 ABI Revision 1.5
  *
- * Stack frame organization (see Figure 2.18, ELF V2 ABI Revision 1.4, p 31)
+ * Stack frame organization (see Figure 2.18, ELF V2 ABI Revision 1.5, p 34)
  *
  * +-> Back Chain (points to the prevoius stack frame)
  * |   Floating point register save area (f14-f31)
@@ -66,8 +66,10 @@ StgReturn:
         addi 12,1,-(8*18)
         bl _restgpr1_14
         b _restfpr_14
-# else // linux_HOST_OS
-# error Only Linux support for power64 little endian right now.
+
+	.section	.note.GNU-stack,"", at progbits
+# else // Not ELF v2
+# error Only ELF v2 supported.
 # endif
 
 #elif defined(powerpc_HOST_ARCH)
@@ -449,7 +451,7 @@ StgReturn:
 	ld.d	$fp,$sp,144
 	.cfi_restore 22
 	ld.d	$s0,$sp,136
-	.cfi_restore 23 
+	.cfi_restore 23
 	ld.d	$s1,$sp,128
 	.cfi_restore 24
 	ld.d	$s2,$sp,120


=====================================
rts/StgMiscClosures.cmm
=====================================
@@ -51,8 +51,8 @@ INFO_TABLE_RET (stg_orig_thunk_info_frame, RET_SMALL,
                 W_ thunk_info_ptr)
     /* no args => explicit stack */
 {
-    unwind Sp = W_[Sp + WDS(2)];
-    Sp_adj(2);
+    unwind Sp = W_[Sp + SIZEOF_StgOrigThunkInfoFrame];
+    Sp = Sp + SIZEOF_StgOrigThunkInfoFrame;
     jump %ENTRY_CODE(Sp(0)) [*]; // NB. all registers live!
 }
 


=====================================
rts/adjustor/NativePowerPC.c
=====================================
@@ -29,8 +29,7 @@ __asm__("obscure_ccall_ret_code:\n\t"
 extern void obscure_ccall_ret_code(void);
 #endif /* defined(linux_HOST_OS) */
 
-#if defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH)
-#if !(defined(powerpc_HOST_ARCH) && defined(linux_HOST_OS))
+#if defined(powerpc_HOST_ARCH) && defined(aix_HOST_OS) || defined(powerpc64_HOST_ARCH) && defined(__ELF__) && (!defined(_CALL_ELF) || _CALL_ELF == 1)
 
 /* !!! !!! WARNING: !!! !!!
  * This structure is accessed from AdjustorAsm.s
@@ -50,8 +49,7 @@ typedef struct AdjustorStub {
     StgInt          extrawords_plus_one;
 } AdjustorStub;
 
-#endif /* !(defined(powerpc_HOST_ARCH) && defined(linux_HOST_OS)) */
-#endif /* defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) */
+#endif
 
 void initAdjustors(void) { }
 


=====================================
testsuite/tests/codeGen/should_run/T24809.hs
=====================================
@@ -0,0 +1,2 @@
+
+main = putStrLn "hi"


=====================================
testsuite/tests/codeGen/should_run/T24809.stdout
=====================================
@@ -0,0 +1 @@
+hi


=====================================
testsuite/tests/codeGen/should_run/all.T
=====================================
@@ -226,6 +226,7 @@ test('T22296',[only_ways(llvm_ways)
 test('T22798', normal, compile_and_run, ['-fregs-graph'])
 test('CheckBoundsOK', normal, compile_and_run, ['-fcheck-prim-bounds'])
 test('OrigThunkInfo', normal, compile_and_run, ['-forig-thunk-info'])
+test('T24809', req_profiling, compile_and_run, ['-forig-thunk-info -prof'])
 
 # TODO: Enable more architectures here. N.B. some code generation backends are
 # not implemeted correctly (according to



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/260e5439e03923bcc417ec00db62c11604f317e9...3677d06f77328545bfd94dbf076554b164bae106

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/260e5439e03923bcc417ec00db62c11604f317e9...3677d06f77328545bfd94dbf076554b164bae106
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/20240522/b09a94ef/attachment-0001.html>


More information about the ghc-commits mailing list