[GHC] #15482: the_gc_thread variable from GC.c is not aligned to 64

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Keywords: | Operating System: Unknown/Multiple Architecture: x86_64 | Type of failure: None/Unknown (amd64) | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- When compiling GHC with clang and -march=native flag, the compiler emits vmovaps instruction with unaligned operand for this code: {{{ * thread #1, name = 'ghc-pkg', stop reason = signal SIGBUS: hardware error frame #0: 0x0000000804e476c6 libHSrts-ghc8.0.2.so`initGcThreads [inlined] new_gc_thread(n=0) at GC.c:818 815 ws->todo_q = newWSDeque(128); 816 ws->todo_overflow = NULL; 817 ws->n_todo_overflow = 0; -> 818 ws->todo_large_objects = NULL; 819 820 ws->part_list = NULL; 821 ws->n_part_blocks = 0; }}} Research done by another FreeBSD developer suggested that this is due {{{ StgWord8 the_gc_thread[sizeof(gc_thread) + 64 * sizeof(gen_workspace)]; }}} not being aligned to 64 bytes, because struct gc_thread have no alignment specifier. Detailed information can be found in FreeBSD bugzilla: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=226059 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64
-------------------------------------+-------------------------------------
Reporter: arrowd | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone: 8.6.1
Component: Compiler | Version: 8.4.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: x86_64
| (amd64)
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Merged in 87a79e394013e5f722496900227b126015d0d780. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1):
Merged in 87a79e394013e5f722496900227b126015d0d780.
This commit isn't in the git repo. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): I'm not sure what you mean; it surely is. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): It now is, it wasn't when I posted my comment. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Unfortunately it seems that comment:1 causes segfaults on Darwin; reverting. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by arrowd): Conrad Meyer, the FreeBSD guy that initially come with this suggestion also says that this fix is incorrect. Quoting him: Their change c6cc93bca only aligns the array to W_ aka StgWord aka StgWord64 aka unsigned long (8 bytes). This is insufficient for AVX2 alignment[1] (16 bytes for xmm, 32 for ymm) and still violates the guarantee attached to the gen_workspace structure (64 byte alignment). They need to remove the 64-byte gen_workspace alignment or add 64-byte alignment to the array to remove their UB. (They could align both to the smaller 32 bytes and still allow the compiler to take advantage of AVX2.) I don't know what lead them to believe an 8-byte alignment would fix an unaligned 32-byte AVX access. [1]: https://www.felixcloutier.com/x86/MOVAPS.html -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5052 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: closed => new * differential: => Phab:D5052 * resolution: fixed => Comment: Ahh, I see the issue now. We explicitly claim that `gen_workspace` should be 64-byte aligned. I was previously under the mistaken impression that the problem was merely that `the_gc_thread`, a `StgWord8[]`, wasn't aligned to 8-bytes as `gc_thread` would require. I pushed a new fix as Phab:D5052 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5052 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64
-------------------------------------+-------------------------------------
Reporter: arrowd | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone: 8.6.1
Component: Compiler | Version: 8.4.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: x86_64
| (amd64)
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D5052
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5052 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15482: the_gc_thread variable from GC.c is not aligned to 64 -------------------------------------+------------------------------------- Reporter: arrowd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5052 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Merged with c3e50b053cd49c465bfd2d095e3f681510993d2b. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15482#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC