[GHC] #15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Keywords: | Operating System: Linux Architecture: | Type of failure: Compile-time Unknown/Multiple | crash or panic Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- When compiling this simple program: {{{#!hs main = pure () }}} Using the `-staticlib` flag on GHC 8.4.3 on Linux, it panics if using a certain toolchain: {{{ $ uname -a Linux gearloose 4.2.0-42-generic #49~14.04.1-Ubuntu SMP Wed Jun 29 20:22:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux $ /opt/ghc/8.4.3/bin/ghc -staticlib Bug.hs Linking Bug.a ... ghc: panic! (the 'impossible' happened) (GHC version 8.4.3 for x86_64-unknown-linux): Data.Binary.Get.runGet at position 27462987: Invalid archive header end marker CallStack (from HasCallStack): error, called at libraries/binary/src/Data/Binary/Get.hs:351:5 in binary-0.8.5.1:Data.Binary.Get }}} I say "certain toolchain" since I am able to reproduce this issue on Ubuntu 14.04, but not 18.04: {{{ $ uname -a Linux Linux-T450 4.15.0-24-generic #26-Ubuntu SMP Wed Jun 13 08:44:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux $ ghc -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... }}} This issue does not occur on GHC 8.2 and earlier: {{{ $ /opt/ghc/8.2.2/bin/ghc -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... Static archive creation only supported on Darwin/OS X/iOS }}} Commit b8f33bc6b738b0378976e42b79369f0e53b680c7 allowed the use of `-staticlib` on all platforms. angerman, do you know what might be happening here? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by RyanGlScott: Old description:
When compiling this simple program:
{{{#!hs main = pure () }}}
Using the `-staticlib` flag on GHC 8.4.3 on Linux, it panics if using a certain toolchain:
{{{ $ uname -a Linux gearloose 4.2.0-42-generic #49~14.04.1-Ubuntu SMP Wed Jun 29 20:22:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux $ /opt/ghc/8.4.3/bin/ghc -staticlib Bug.hs Linking Bug.a ... ghc: panic! (the 'impossible' happened) (GHC version 8.4.3 for x86_64-unknown-linux): Data.Binary.Get.runGet at position 27462987: Invalid archive header end marker CallStack (from HasCallStack): error, called at libraries/binary/src/Data/Binary/Get.hs:351:5 in binary-0.8.5.1:Data.Binary.Get }}}
I say "certain toolchain" since I am able to reproduce this issue on Ubuntu 14.04, but not 18.04:
{{{ $ uname -a Linux Linux-T450 4.15.0-24-generic #26-Ubuntu SMP Wed Jun 13 08:44:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux $ ghc -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... }}}
This issue does not occur on GHC 8.2 and earlier:
{{{ $ /opt/ghc/8.2.2/bin/ghc -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... Static archive creation only supported on Darwin/OS X/iOS }}}
Commit b8f33bc6b738b0378976e42b79369f0e53b680c7 allowed the use of `-staticlib` on all platforms. angerman, do you know what might be happening here?
New description: When compiling this simple program: {{{#!hs main = pure () }}} Using the `-staticlib` flag on GHC 8.4.3 on Linux, it panics if using a certain toolchain: {{{ $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.5 LTS Release: 14.04 Codename: trusty $ /opt/ghc/8.4.3/bin/ghc -staticlib Bug.hs Linking Bug.a ... ghc: panic! (the 'impossible' happened) (GHC version 8.4.3 for x86_64-unknown-linux): Data.Binary.Get.runGet at position 27462987: Invalid archive header end marker CallStack (from HasCallStack): error, called at libraries/binary/src/Data/Binary/Get.hs:351:5 in binary-0.8.5.1:Data.Binary.Get }}} I say "certain toolchain" since I am able to reproduce this issue on Ubuntu 14.04, but not 18.04: {{{ $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04 LTS Release: 18.04 Codename: bionic $ ghc -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... }}} This issue does not occur on GHC 8.2 and earlier: {{{ $ /opt/ghc/8.2.2/bin/ghc -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... Static archive creation only supported on Darwin/OS X/iOS }}} Commit b8f33bc6b738b0378976e42b79369f0e53b680c7 allowed the use of `-staticlib` on all platforms. angerman, do you know what might be happening here? -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by RyanGlScott: Old description:
When compiling this simple program:
{{{#!hs main = pure () }}}
Using the `-staticlib` flag on GHC 8.4.3 on Linux, it panics if using a certain toolchain:
{{{ $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.5 LTS Release: 14.04 Codename: trusty $ /opt/ghc/8.4.3/bin/ghc -staticlib Bug.hs Linking Bug.a ... ghc: panic! (the 'impossible' happened) (GHC version 8.4.3 for x86_64-unknown-linux): Data.Binary.Get.runGet at position 27462987: Invalid archive header end marker CallStack (from HasCallStack): error, called at libraries/binary/src/Data/Binary/Get.hs:351:5 in binary-0.8.5.1:Data.Binary.Get }}}
I say "certain toolchain" since I am able to reproduce this issue on Ubuntu 14.04, but not 18.04:
{{{ $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04 LTS Release: 18.04 Codename: bionic $ ghc -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... }}}
This issue does not occur on GHC 8.2 and earlier:
{{{ $ /opt/ghc/8.2.2/bin/ghc -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... Static archive creation only supported on Darwin/OS X/iOS }}}
Commit b8f33bc6b738b0378976e42b79369f0e53b680c7 allowed the use of `-staticlib` on all platforms. angerman, do you know what might be happening here?
New description: When compiling this simple program: {{{#!hs main = pure () }}} Using the `-staticlib` flag on GHC 8.4.3 on Linux, it panics if using a certain toolchain: {{{ $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.5 LTS Release: 14.04 Codename: trusty $ /opt/ghc/8.4.3/bin/ghc -fforce-recomp -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... ghc: panic! (the 'impossible' happened) (GHC version 8.4.3 for x86_64-unknown-linux): Data.Binary.Get.runGet at position 27462987: Invalid archive header end marker CallStack (from HasCallStack): error, called at libraries/binary/src/Data/Binary/Get.hs:351:5 in binary-0.8.5.1:Data.Binary.Get }}} I say "certain toolchain" since I am able to reproduce this issue on Ubuntu 14.04, but not 18.04: {{{ $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04 LTS Release: 18.04 Codename: bionic $ /opt/ghc/8.4.3/bin/ghc -fforce-recomp -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... }}} This issue does not occur on GHC 8.2 and earlier: {{{ $ /opt/ghc/8.2.2/bin/ghc -staticlib Bug.hs [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... Static archive creation only supported on Darwin/OS X/iOS }}} Commit b8f33bc6b738b0378976e42b79369f0e53b680c7 allowed the use of `-staticlib` on all platforms. angerman, do you know what might be happening here? -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * Attachment "v3-output.txt" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Note that I originally tried this with GHCs obtained https://launchpad.net/~hvr/+archive/ubuntu/ghc , but the same thing happens even if you use the official bindist (albeit with a ever-so- slightly different location in the panic): {{{ $ ~/Software/ghc-8.4.3/bin/ghc -fforce-recomp -staticlib Bug.hs /u/rgscott/Software/ghc-8.4.3/lib/ghc-8.4.3/bin/ghc: /lib/x86_64-linux- gnu/libtinfo.so.5: no version information available (required by /home/rgscott/Software/ghc-8.4.3/lib/ghc-8.4.3/bin/../haskeline-0.7.4.2/libHShaskeline-0.7.4.2-ghc8.4.3.so) /u/rgscott/Software/ghc-8.4.3/lib/ghc-8.4.3/bin/ghc: /lib/x86_64-linux- gnu/libtinfo.so.5: no version information available (required by /home/rgscott/Software/ghc-8.4.3/lib/ghc-8.4.3/bin/../ghc-8.4.3/libHSghc-8.4.3-ghc8.4.3.so) /u/rgscott/Software/ghc-8.4.3/lib/ghc-8.4.3/bin/ghc: /lib/x86_64-linux- gnu/libtinfo.so.5: no version information available (required by /home/rgscott/Software/ghc-8.4.3/lib/ghc-8.4.3/bin/../terminfo-0.4.1.1/libHSterminfo-0.4.1.1-ghc8.4.3.so) [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Linking Bug.a ... ghc: panic! (the 'impossible' happened) (GHC version 8.4.3 for x86_64-unknown-linux): Data.Binary.Get.runGet at position 27462451: Invalid archive header end marker CallStack (from HasCallStack): error, called at libraries/binary/src/Data/Binary/Get.hs:351:5 in binary-0.8.5.1:Data.Binary.Get }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by angerman):
Each data section is 2 byte aligned. If it would end on an odd offset, a newline ('\n', 0x0A) is used as filler. (from [https://en.wikipedia.org/wiki/Ar_%28Unix%29 wikipedia:ar (Unix)])
That's pretty much what the `Ar` module fails to account for. For some reason `libHSbase-4.11.1.0.a` ends up having odd byte long object files. As such parsing the archive falls apart. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by angerman): * Attachment "0001-Fix-Ar-to-respect-two-byte-aligned-sections.patch" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by angerman): * status: new => patch Comment: @bgamari, @RyanGlScott, I've attached a patch. Let me know if this helps. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Thanks for the quick work, angerman! I just tried this patch out on my Ubuntu 14.04 machine, and it appears to work quite beautifully. The original program in this ticket no longer panics, and it seems to scale up to building a larger package (in my case, `th-absraction`, where I first noticed this bug) as well. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by monoidal): Is it possible to add a test? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Sure, I think compiling `main = pure ()` with `-staticlib` would be sufficient (as that's broken without this patch). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone: 8.6.1
Component: Compiler | Version: 8.4.3
(Linking) |
Resolution: | Keywords:
Operating System: Linux | Architecture:
Type of failure: Compile-time | Unknown/Multiple
crash or panic | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Krzysztof Gogolewski

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by monoidal): * status: patch => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15396: -staticlib is broken on GHC 8.4.3 on Linux under certain conditions -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 (Linking) | Resolution: fixed | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Merged with 04805078763d6c7347d4cecf33d7e14099790793. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15396#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC