[GHC] #16186: Segfault when embedding data via file-embed.

#16186: Segfault when embedding data via file-embed. ----------------------------------------+--------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Keywords: | Operating System: Linux Architecture: Unknown/Multiple | Type of failure: None/Unknown Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: ----------------------------------------+--------------------------------- I made a minimal reproducible-ish example here: https://github.com/NorfairKing/nix-segfault-haskell and described it at length here: https://github.com/NixOS/nixpkgs/issues/52439#issuecomment-453872693 The problem seems to occur (randomly) when literal strings are embedded via TH. By the way: to embed about 10MiB of data, 12 cores are being used at 100% which seems mildly absurd. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by mpickering): Why are you embedding a 10mb file inside a program? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Description changed by syd: Old description:
I made a minimal reproducible-ish example here:
https://github.com/NorfairKing/nix-segfault-haskell
and described it at length here:
https://github.com/NixOS/nixpkgs/issues/52439#issuecomment-453872693
The problem seems to occur (randomly) when literal strings are embedded via TH. By the way: to embed about 10MiB of data, 12 cores are being used at 100% which seems mildly absurd.
New description: GHC segfaults when embedding a bunch of data via `file-embed`: {{{ /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf-ghc-8.4.3/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -isrc -idist/build/autogen -idist/build/global- autogen -Idist/build/autogen -Idist/build/global-autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -this-unit-id segfault-0.0.0-G2YKYaaGIenGdA1YODfaB0 -hide-all-packages -Wmissing-home- modules -no-user-package-db -package-db /tmp/nix-build- segfault-0.0.0.drv-2/package.conf.d -package-db dist/package.conf.inplace -package-id base-4.11.1.0 -package-id bytestring-0.10.8.2 -package-id file-embed-0.0.10.1-JBj0CTa3b3pL2aTV19QFZK -XHaskell2010 Lib Paths_segfault -j12 -split-sections [2 of 2] Compiling Lib ( src/Lib.hs, dist/build/Lib.o ) Segmentation fault (core dumped) }}} I made a minimal reproducible-ish example here: https://github.com/NorfairKing/nix-segfault-haskell and described it at length here: https://github.com/NixOS/nixpkgs/issues/52439#issuecomment-453872693 The problem seems to occur (randomly) when literal strings are embedded via TH. By the way: to embed about 10MiB of data, 12 cores are being used at 100% which seems mildly absurd. It is relatively easy to obtain a core-dump file for it, and then we see the following in `gdb`: {{{ $ /usr/sbin/gdb /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/ghc core.3212 GNU gdb (GDB) 8.2.1 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/ghc...(no debugging symbols found)...done. [New LWP 3232] [New LWP 3244] [New LWP 3252] [New LWP 3230] [New LWP 3231] [New LWP 3212] [New LWP 3213] [New LWP 3242] [New LWP 3226] [New LWP 3227] [New LWP 3233] [New LWP 3251] [New LWP 3225] [New LWP 3241] [New LWP 3245] [New LWP 3224] [New LWP 3214] [New LWP 3237] [New LWP 3235] [New LWP 3215] [New LWP 3238] [New LWP 3216] [New LWP 3248] [New LWP 3253] [New LWP 3234] [New LWP 3266] [New LWP 3239] [New LWP 3247] [New LWP 3250] [New LWP 3249] [New LWP 3240] [New LWP 3228] [New LWP 3229] [New LWP 3246] [New LWP 3236] [New LWP 3243] warning: File "/nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv- glibc-2.27/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". To enable execution of this file add add-auto-load-safe-path /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libthread_db-1.0.so line to your configuration file "/homeless-shelter/.gdbinit". To completely disable this security protection add set auto-load safe-path / line to your configuration file "/homeless-shelter/.gdbinit". For more information about this security protection see the "Auto-loading safe path" section in the GDB manual. E.g., run from the shell: info "(gdb)Auto-loading safe path" warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available. warning: File "/nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv- glibc-2.27/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available. Core was generated by `/nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/ghc -B/'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00007fad21c9ae9f in abort () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 [Current thread is 1 (LWP 3232)] (gdb) bt #0 0x00007fad21c9ae9f in abort () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 #1 0x00007fad21cdb2ac in __libc_message () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 #2 0x00007fad21cdb2ce in __libc_fatal () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 #3 0x00007fad21a536a6 in pthread_cond_wait@@GLIBC_2.3.2 () from /nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv- glibc-2.27/lib/libpthread.so.0 #4 0x00007fad22d7fdd9 in waitCondition () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #5 0x00007fad22d6243b in yieldCapability () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #6 0x00007fad22d66e23 in schedule () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #7 0x00007fad22d6868c in scheduleWorker () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #8 0x00007fad21a4d5a7 in start_thread () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libpthread.so.0 #9 0x00007fad21d5722f in clone () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by syd):
Why are you embedding a 10mb file inside a program?
We are seeing similar problems when compiling other things, this just happened to be the most easy to reproduce. Maybe figuring this one out might help with other similar problems. In any case, GHC should never segfault but rather throw some sort of error. To answer your question: I'm embedding assets (pictures) in a web server. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by syd): I have tried to make the example more minimal. Now I'm at the point where I used `ddump-splices` to replace the TH invocation entirely. Now I get a stack overflow: {{{ /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf-ghc-8.4.3/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -isrc -idist/build/autogen -idist/build/global- autogen -Idist/build/autogen -Idist/build/global-autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -this-unit-id segfault-0.0.0-G2YKYaaGIenGdA1YODfaB0 -hide-all-packages -Wmissing-home- modules -no-user-package-db -package-db /tmp/nix-build- segfault-0.0.0.drv-2/package.conf.d -package-db dist/package.conf.inplace -package-id base-4.11.1.0 -package-id bytestring-0.10.8.2 -package-id file-embed-0.0.10.1-JBj0CTa3b3pL2aTV19QFZK -XHaskell2010 Lib Paths_segfault -j12 -split-sections [2 of 2] Compiling Lib ( src/Lib.hs, dist/build/Lib.o ) <no location info>: error: stack overflow }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by syd): If I add `+RTS -K` to the original invocation, and now there is no longer a stack overflow error, but still a segfault. This time without any TH involved: {{{ /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf-ghc-8.4.3/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -isrc -idist/build/autogen -idist/build/global- autogen -Idist/build/autogen -Idist/build/global-autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -this-unit-id segfault-0.0.0-G2YKYaaGIenGdA1YODfaB0 -hide-all-packages -Wmissing-home- modules -no-user-package-db -package-db /tmp/nix-build- segfault-0.0.0.drv-2/package.conf.d -package-db dist/package.conf.inplace -package-id base-4.11.1.0 -package-id bytestring-0.10.8.2 -package-id file-embed-0.0.10.1-JBj0CTa3b3pL2aTV19QFZK -XHaskell2010 Lib Paths_segfault -j12 -split-sections +RTS -K [2 of 2] Compiling Lib ( src/Lib.hs, dist/build/Lib.o ) Segmentation fault (core dumped) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by syd): I got it down to a much smaller command that still fails: {{{ /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf-ghc-8.4.3/bin/ghc --make -hide-all-packages -no-user-package-db -package-db /tmp/nix-build- segfault-0.0.0.drv-2/package.conf.d -package-db dist/package.conf.inplace -package-id base-4.11.1.0 -package-id bytestring-0.10.8.2 src/Lib.hs -j12 +RTS -K [1 of 1] Compiling Lib ( src/Lib.hs, src/Lib.o ) Segmentation fault (core dumped) }}} Also, if I remove the `-j12`, it no longer segfaults. I also tried with `-j2` and that seems to work as well (no segfaults as far as I can tell). I also tried with `-j256` and it segfaults a _lot_ faster. The same goes for `-j4098`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by syd): I uploaded the smallest I could make the example here: https://raw.githubusercontent.com/NorfairKing/nix-segfault- haskell/master/Lib.hs Documentation about it here: https://github.com/NorfairKing/nix-segfault- haskell -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by hsyl20):
By the way: to embed about 10MiB of data, 12 cores are being used at 100% which seems mildly absurd.
Incidentally, I've been working on this today: https://hsyl20.fr/home/posts/2019-01-15-fast-file-embedding-with-ghc.html -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by mpickering): Nice post Sylvain. Really good motivation for #16180 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by nh2): Yes, indeed the linker approach solves that. Note though that this ticket isn't really about embedding files, it's about there being a code path in GHC that leads to segfaults (which should never happen); embedding files is just the way we managed to reproduce the issue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by RyanGlScott): It's a bit hard to say with certainty that this is GHC's fault, especially since the program referenced in comment:7 uses a function from `bytestring` library that's explicitly labeled as unsafe. My first inclination would be to label this as a `bytestring` bug, not a GHC one. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. ---------------------------------+---------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by bgamari): syd, very interesting. Can you reproduce this with 8.6? If not, is it possible that you are running out of memory? This sounds very much like #14329 although I believe this was fixed in 8.4.3. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. -------------------------------------+------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 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 nh2): * failure: None/Unknown => Compile-time crash or panic Old description:
GHC segfaults when embedding a bunch of data via `file-embed`:
{{{ /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf-ghc-8.4.3/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -isrc -idist/build/autogen -idist/build /global-autogen -Idist/build/autogen -Idist/build/global-autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -this- unit-id segfault-0.0.0-G2YKYaaGIenGdA1YODfaB0 -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /tmp/nix-build- segfault-0.0.0.drv-2/package.conf.d -package-db dist/package.conf.inplace -package-id base-4.11.1.0 -package-id bytestring-0.10.8.2 -package-id file-embed-0.0.10.1-JBj0CTa3b3pL2aTV19QFZK -XHaskell2010 Lib Paths_segfault -j12 -split-sections [2 of 2] Compiling Lib ( src/Lib.hs, dist/build/Lib.o ) Segmentation fault (core dumped) }}}
I made a minimal reproducible-ish example here:
https://github.com/NorfairKing/nix-segfault-haskell
and described it at length here:
https://github.com/NixOS/nixpkgs/issues/52439#issuecomment-453872693
The problem seems to occur (randomly) when literal strings are embedded via TH. By the way: to embed about 10MiB of data, 12 cores are being used at 100% which seems mildly absurd.
It is relatively easy to obtain a core-dump file for it, and then we see the following in `gdb`:
{{{ $ /usr/sbin/gdb /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/ghc core.3212 GNU gdb (GDB) 8.2.1 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/.
For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/ghc...(no debugging symbols found)...done. [New LWP 3232] [New LWP 3244] [New LWP 3252] [New LWP 3230] [New LWP 3231] [New LWP 3212] [New LWP 3213] [New LWP 3242] [New LWP 3226] [New LWP 3227] [New LWP 3233] [New LWP 3251] [New LWP 3225] [New LWP 3241] [New LWP 3245] [New LWP 3224] [New LWP 3214] [New LWP 3237] [New LWP 3235] [New LWP 3215] [New LWP 3238] [New LWP 3216] [New LWP 3248] [New LWP 3253] [New LWP 3234] [New LWP 3266] [New LWP 3239] [New LWP 3247] [New LWP 3250] [New LWP 3249] [New LWP 3240] [New LWP 3228] [New LWP 3229] [New LWP 3246] [New LWP 3236] [New LWP 3243]
warning: File "/nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv- glibc-2.27/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". To enable execution of this file add add-auto-load-safe-path /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libthread_db-1.0.so line to your configuration file "/homeless-shelter/.gdbinit". To completely disable this security protection add set auto-load safe-path / line to your configuration file "/homeless-shelter/.gdbinit". For more information about this security protection see the "Auto-loading safe path" section in the GDB manual. E.g., run from the shell: info "(gdb)Auto-loading safe path"
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: File "/nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv- glibc-2.27/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available. Core was generated by `/nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/ghc -B/'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00007fad21c9ae9f in abort () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 [Current thread is 1 (LWP 3232)] (gdb) bt #0 0x00007fad21c9ae9f in abort () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 #1 0x00007fad21cdb2ac in __libc_message () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 #2 0x00007fad21cdb2ce in __libc_fatal () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 #3 0x00007fad21a536a6 in pthread_cond_wait@@GLIBC_2.3.2 () from /nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv- glibc-2.27/lib/libpthread.so.0 #4 0x00007fad22d7fdd9 in waitCondition () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #5 0x00007fad22d6243b in yieldCapability () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #6 0x00007fad22d66e23 in schedule () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #7 0x00007fad22d6868c in scheduleWorker () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #8 0x00007fad21a4d5a7 in start_thread () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libpthread.so.0 #9 0x00007fad21d5722f in clone () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 }}}
[...] since the program [...] uses a function from `bytestring` library
New description: GHC itself segfaults when embedding a bunch of data via `file-embed`: {{{ /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf-ghc-8.4.3/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -isrc -idist/build/autogen -idist/build/global- autogen -Idist/build/autogen -Idist/build/global-autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -this-unit-id segfault-0.0.0-G2YKYaaGIenGdA1YODfaB0 -hide-all-packages -Wmissing-home- modules -no-user-package-db -package-db /tmp/nix-build- segfault-0.0.0.drv-2/package.conf.d -package-db dist/package.conf.inplace -package-id base-4.11.1.0 -package-id bytestring-0.10.8.2 -package-id file-embed-0.0.10.1-JBj0CTa3b3pL2aTV19QFZK -XHaskell2010 Lib Paths_segfault -j12 -split-sections [2 of 2] Compiling Lib ( src/Lib.hs, dist/build/Lib.o ) Segmentation fault (core dumped) }}} I made a minimal reproducible-ish example here: https://github.com/NorfairKing/nix-segfault-haskell and described it at length here: https://github.com/NixOS/nixpkgs/issues/52439#issuecomment-453872693 The problem seems to occur (randomly) when literal strings are embedded via TH. By the way: to embed about 10MiB of data, 12 cores are being used at 100% which seems mildly absurd. It is relatively easy to obtain a core-dump file for it, and then we see the following in `gdb`: {{{ $ /usr/sbin/gdb /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/ghc core.3212 GNU gdb (GDB) 8.2.1 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/ghc...(no debugging symbols found)...done. [New LWP 3232] [New LWP 3244] [New LWP 3252] [New LWP 3230] [New LWP 3231] [New LWP 3212] [New LWP 3213] [New LWP 3242] [New LWP 3226] [New LWP 3227] [New LWP 3233] [New LWP 3251] [New LWP 3225] [New LWP 3241] [New LWP 3245] [New LWP 3224] [New LWP 3214] [New LWP 3237] [New LWP 3235] [New LWP 3215] [New LWP 3238] [New LWP 3216] [New LWP 3248] [New LWP 3253] [New LWP 3234] [New LWP 3266] [New LWP 3239] [New LWP 3247] [New LWP 3250] [New LWP 3249] [New LWP 3240] [New LWP 3228] [New LWP 3229] [New LWP 3246] [New LWP 3236] [New LWP 3243] warning: File "/nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv- glibc-2.27/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". To enable execution of this file add add-auto-load-safe-path /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libthread_db-1.0.so line to your configuration file "/homeless-shelter/.gdbinit". To completely disable this security protection add set auto-load safe-path / line to your configuration file "/homeless-shelter/.gdbinit". For more information about this security protection see the "Auto-loading safe path" section in the GDB manual. E.g., run from the shell: info "(gdb)Auto-loading safe path" warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available. warning: File "/nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv- glibc-2.27/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available. Core was generated by `/nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/ghc -B/'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00007fad21c9ae9f in abort () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 [Current thread is 1 (LWP 3232)] (gdb) bt #0 0x00007fad21c9ae9f in abort () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 #1 0x00007fad21cdb2ac in __libc_message () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 #2 0x00007fad21cdb2ce in __libc_fatal () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 #3 0x00007fad21a536a6 in pthread_cond_wait@@GLIBC_2.3.2 () from /nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv- glibc-2.27/lib/libpthread.so.0 #4 0x00007fad22d7fdd9 in waitCondition () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #5 0x00007fad22d6243b in yieldCapability () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #6 0x00007fad22d66e23 in schedule () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #7 0x00007fad22d6868c in scheduleWorker () from /nix/store/6j6slxdhbbzxvhkn6yf7afm62r8n9fmf- ghc-8.4.3/lib/ghc-8.4.3/bin/../rts/libHSrts_thr-ghc8.4.3.so #8 0x00007fad21a4d5a7 in start_thread () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libpthread.so.0 #9 0x00007fad21d5722f in clone () from /nix/store /g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib/libc.so.6 }}} -- Comment: Replying to [comment:11 RyanGlScott]: that's explicitly labeled as unsafe. My first inclination would be to label this as a `bytestring` bug, not a GHC one. There's a misunderstanding: The segfault is at **compile time**, the `bytestring` function in question is never executed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

syd, very interesting. Can you reproduce this with 8.6? If not, is it
#16186: Segfault when embedding data via file-embed. -------------------------------------+------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 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 syd): Replying to [comment:12 bgamari]: possible that you are running out of memory? This sounds very much like #14329 although I believe this was fixed in 8.4.3. I wasn't running out of memory, but I tried gain with 8.6.3 and the problem doesn't seem to exist anymore. I didn't try it out in entirely the same but now it works with stack and even `100MiB` of random data and that seems to work. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. -------------------------------------+------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 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 syd): I just tried with 8.6.3 but via nix and that also works with `100MiB` now. So I'll close this here. Thanks for the help @bgamari -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16186: Segfault when embedding data via file-embed. -------------------------------------+------------------------------------- Reporter: syd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.4.3 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 syd): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16186#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC