|
#4211: LLVM: Stack alignment on OSX
------------------------+--------------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Component: Compiler (LLVM) Version: 6.13 | Keywords: Os: MacOS X | Testcase: Architecture: x86 | Failure: None/Unknown ------------------------+--------------------------------------------------- On OSX the ABI requires that the stack is 16 byte aligned when making function calls. (Although this only really needs to be obeyed when making calls that will go through the dynamic linker, so FFI calls). Since the stack is 16 byte aligned at the site of the call, on entry to a function most compilers (both llvm and gcc) expect the stack to now be aligned to 16n - 4, since 4 bytes should have been pushed for the return address as part of the call instruction. GHC though since it uses jumps everywhere keeps that stack at 16 byte aligned on function entrance. This means that LLVM generates incorrect stack alignment code, always off by 4. For the moment I have handled this by using the LLvm Mangler (which is only needed on OS X already for TNTC) to simply correctly fix up the stack alignment code. E.g Asm generated by LLVM: {{{ _func: subl $12, %esp ... call _sin ... addl $12, %esp }}} The mangler will change this to: {{{ _func: subl $16, %esp ... call _sin ... addl $16, %esp }}} The better solution would be to change GHC to keep the stack at 16n - 4 alignment on function. This will require changing the RTS (StgCRun.hs) to set the stack properly before calling into Stg land and also fixing up the NCG to align code properly. There may also be a problem with the C backend as currently all function prolouge and epilouge code is stripped out, which means all the stack manipulation code generated by GCC is removed. This works fine now since the stack is already 16 byte aligned on entry, but if it is now 16n - 4 byte aligned then some stack manipulation will be required. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 6.14.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Changes (by igloo): * milestone: => 6.14.1 -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.0.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Changes (by PHO): * cc: pho@… (added) -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.2.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Comment(by simonmar): I'm changing the code that handles stack alignment as a result of #5250, I think this change would be easy to make too. David, ping me if you want help with this. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.2.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Comment(by dterei): Yes that would be great Simon, there shouldn't be any issues now that we don't support the registerised C backend. Only concern I can think of with this change is there may now be cases where the NCG didn't need to do any sp manipulation but now will. (E.g for any C calls the NCG will need to fix up alignment by subtracting 12 (or 8 on x64), while in the past if no system stack was used the sp was already correctly aligned). I can't see this causing any performance regression though. If you are happy to just take over this ticket thats great, otherwise just point me to what needs to be changed and I'll finish it off. I think when I had a very brief go at this ticket ages back the main problem was just finding all the locations involved in Sp tracking and manipulation. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.2.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Comment(by simonmar): Right, C calls with no arguments will now need an esp adjustment, but I don't think it's a big deal (and it's only for calls with no arguments, those with arguments already need an Sp adjustment). Do you want to have a go? There are only two places that need to be changed: `StgCRun.c`, where we currently add 12 to esp to align it, we can just drop that. The other place is `X86.CodeGen.genCCall` where we pad the stack offset if necessary. Urgh, I just realised that we probably need to do something in `rts/Adjustor.c` too. I looked at the code there, and the Darwin/x86 version is vastly more complicated than the non-Darwin x86 version, and I'm surprised if all that complexity is needed just to get the stack pointer aligned... -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.2.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Comment(by dterei): OK. Yep I'll have a go at this sometime soon when I get some spare time. Probably won't have any for at least the next 10 days. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.2.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Comment(by simonmar): I just added a test for stack alignment for #5250, and sure enough it fails with LLVM: {{{ =====> 5250(optllvm) 23 of 23 [0, 0, 0] cd . && '/64playpen/simonmar/validate/inplace/bin/ghc-stage2' -fforce- recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-package-conf -rtsopts -o 5250 5250.hs -O -fllvm spalign.c >5250.comp.stderr 2>&1 cd . && ./5250 </dev/null >5250.run.stdout 2>5250.run.stderr Wrong exit code (expected 0 , actual 1 ) Stdout: esp not aligned correctly: c39c5d30 }}} -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.4.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Changes (by dmp): * cc: dmp@… (added) Comment: I have made the changes to keep the stack 16+8 byte aligned throughout STG code for x86_64 targets. The changes are available in my github repo on the 4211 branch https://github.com/dmpots/ghc/tree/4211 I can also attach the patches to this ticket if that would work better. The results look promising. I get no new regressions on a validate run and a testsuite run with `WAY=optllvm` goes from 36 failures to 6 failures, plus two unexpected passes (one of which is the 5250 test simonmar mentioned above). I would love to see these changes merged to the mainline GHC. I suppose that the main sticking point is probably that I made the change for 64-bit targets, but not the 32-bit targets. Is there any chance it will get merged for the 64-bit targets? My motivation (and therefore availble time) is much less for 32-bit targets and I'm worried that dealing with the `stdcall` convetion could be a bit more compilicated. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.4.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Comment(by dterei): Great! I'll have a look at the patch and hopefully merge. If you can handle the 32bit case that would be greatly appreciated though. I assume you disabled the llvm mangler stack fixup in the 64bit case but not 32bit? -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.4.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Comment(by dmp): Yes the stack mangling has been disabled for the 64bit case so it's now only used for the 32bit darwin target. I might get some time to make the changes for the 32bit case too. Perhaps my reservations about the difficulties handling stdcall are unfounded. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:13> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.4.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Comment(by dmp@…): commit a9ce36118f0de3aeb427792f8f2c5ae097c94d3f {{{ Author: David M Peixotto <[hidden email]> Date: Wed Oct 19 15:49:06 2011 -0500 Change stack alignment to 16+8 bytes in STG code This patch changes the STG code so that %rsp to be aligned to a 16-byte boundary + 8. This is the alignment required by the x86_64 ABI on entry to a function. Previously we kept %rsp aligned to a 16-byte boundary, but this was causing problems for the LLVM backend (see #4211). We now don't need to invoke llvm stack mangler on x86_64 targets. Since the stack is now 16+8 byte algined in STG land on x86_64, we don't need to mangle the stack manipulations with the llvm mangler. This patch only modifies the alignement for x86_64 backends. Signed-off-by: David Terei <[hidden email]> compiler/llvmGen/LlvmMangler.hs | 6 +++- compiler/nativeGen/X86/CodeGen.hs | 16 +++++++----- rts/StgCRun.c | 46 +++++++++++++++++++++---------------- 3 files changed, 39 insertions(+), 29 deletions(-) }}} -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:14> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
--------------------------------+------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.4.1 Component: Compiler (LLVM) | Version: 6.13 Keywords: | Testcase: Blockedby: | Difficulty: Os: MacOS X | Blocking: Architecture: x86 | Failure: None/Unknown --------------------------------+------------------------------------------- Comment(by dterei): Thanks for the patch, applied! Leaving ticket open though to trac fixing this on 32bit. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:15> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
------------------------------+--------------------------------------------- Reporter: dterei | Owner: Type: task | Status: new Priority: normal | Milestone: 7.4.1 Component: Compiler (LLVM) | Version: 6.13 Resolution: | Keywords: Os: MacOS X | Architecture: x86 Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: ------------------------------+--------------------------------------------- Changes (by simonmar): * owner: dterei => * difficulty: => Unknown * status: closed => new * resolution: fixed => Comment: Re-opening this ticket as the test rts/5250(llvm) is failing on x86/linux, indicating that the stack pointer is not aligned correctly on that platform. (David: I thought I had mentioned this before, but I searched around and can't find another ticket). -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:18> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
------------------------------+--------------------------------------------- Reporter: dterei | Owner: Type: task | Status: new Priority: normal | Milestone: 7.4.1 Component: Compiler (LLVM) | Version: 6.13 Resolution: | Keywords: Os: MacOS X | Architecture: x86 Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: ------------------------------+--------------------------------------------- Comment(by dterei): Argh! OK thanks Simon, will take a look when I get the time. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:19> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
------------------------------+--------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.4.1 Component: Compiler (LLVM) | Version: 6.13 Resolution: | Keywords: Os: MacOS X | Architecture: x86 Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: ------------------------------+--------------------------------------------- Changes (by dterei): * owner: => dterei -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:20> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
------------------------------+--------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.4.2 Component: Compiler (LLVM) | Version: 6.13 Resolution: | Keywords: Os: MacOS X | Architecture: x86 Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: ------------------------------+--------------------------------------------- Changes (by simonmar): * milestone: 7.4.1 => 7.4.2 -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:21> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
------------------------------+--------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: new Priority: normal | Milestone: 7.4.3 Component: Compiler (LLVM) | Version: 6.13 Resolution: | Keywords: Os: MacOS X | Architecture: x86 Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: ------------------------------+--------------------------------------------- Changes (by dterei): * cc: dmp@… (removed) * cc: dmp@…, rice.edu (added) Comment: Simon I can't reproduce. Just tested on Linux both 32bit and 64 bit machine and 5250 passes for llvm with current HEAD. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:23> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
------------------------------+--------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: infoneeded Priority: normal | Milestone: 7.4.3 Component: Compiler (LLVM) | Version: 6.13 Resolution: | Keywords: Os: MacOS X | Architecture: x86 Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: ------------------------------+--------------------------------------------- Changes (by dterei): * status: new => infoneeded -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:24> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#4211: LLVM: Stack alignment on OSX
------------------------------+--------------------------------------------- Reporter: dterei | Owner: dterei Type: task | Status: infoneeded Priority: normal | Milestone: 7.4.3 Component: Compiler (LLVM) | Version: 6.13 Resolution: | Keywords: Os: MacOS X | Architecture: x86 Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: ------------------------------+--------------------------------------------- Changes (by dterei): * cc: dmp@…, rice.edu (removed) * cc: dmp@… (added) -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4211#comment:25> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
| Powered by Nabble | Edit this page |
