Fix minimum alignment for StgClosure (Trac #11395)
ClosedPublic

Authored by trofi on Mar 5 2016, 1:31 PM.

Details

Summary

The bug is observed on m68k-linux target as crash
in RTS:

  • a.hs: main = print 43

    $ inplace/bin/ghc-stage1 --make -debug a.hs

    $ ./a Program terminated with signal SIGSEGV, Segmentation fault. Trac #0 0x80463b0a in LOOKS_LIKE_INFO_PTR_NOT_NULL (p=32858) at includes/rts/storage/ClosureMacros.h:248 (gdb) bt Trac #0 0x80463b0a in LOOKS_LIKE_INFO_PTR_NOT_NULL (p=32858) at includes/rts/storage/ClosureMacros.h:248 Trac #1 0x80463b46 in LOOKS_LIKE_INFO_PTR (p=32858) at includes/rts/storage/ClosureMacros.h:253 Trac #2 0x80463b6c in LOOKS_LIKE_CLOSURE_PTR ( p=0x805aac6e <stg_dummy_ret_closure>) at includes/rts/storage/ClosureMacros.h:258 Trac #3 0x80463e4c in initStorage () at rts/sm/Storage.c:121 Trac #4 0x8043ffb4 in hs_init_ghc (...) at rts/RtsStartup.c:181 Trac #5 0x80455982 in hs_main (...) at rts/RtsMain.c:51 Trac #6 0x80003c1c in main ()

GHC assumes last 2 pointer bits are tags on 32-bit targets.
But here 'stg_dummy_ret_closure' address violates the assumption:

LOOKS_LIKE_CLOSURE_PTR (p=0x805aac6e <stg_dummy_ret_closure>)

I've added compiler hint for static StgClosure objects to
align closures at least by their natural alignment (what GHC assumes).
See Note [StgWord alignment].

Signed-off-by: Sergei Trofimovich <siarheit@google.com>

Test Plan

ran basic test on m68k qemu, it got past ASSERTs

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
trofi updated this revision to Diff 6833.Mar 5 2016, 1:31 PM
trofi retitled this revision from to Fix minimum alignment for StgClosure (Trac #11395).
trofi updated this object.
trofi edited the test plan for this revision. (Show Details)
trofi added a reviewer: simonmar.
trofi updated the Trac tickets for this revision.
bgamari accepted this revision.Mar 5 2016, 2:19 PM
bgamari edited edge metadata.

Tricky. Good catch.

This revision is now accepted and ready to land.Mar 5 2016, 2:19 PM
This revision was automatically updated to reflect the committed changes.