Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty program segfaulting

I have an empty program (module Main where main = return ()) which segfaults if I include a specific library in build-depends, in cabal file.

The library is my own, and the segfault is some sort of interaction of bumblebee drivers with opengl and haskell (the segfault only occurs if I optirun, which works with other programs, in stack trace I only see libGL.so), but that isn't my question.

My question is, how can a program with no code segfault? More precisely, what code of my library runs just because it's in build-depends? How do I debug this nonsense?

Edit. If I change the order in which extra-libraries are listed, when compiling my library, the problem goes away. Specifically, I moved GL, GLEW before sfml-*. The question remains, though. How could I have discovered this, apart form aimlessly fiddling with build files?

like image 516
Karolis Juodelė Avatar asked Jun 09 '14 09:06

Karolis Juodelė


People also ask

What causes a segfault?

A segfault occurs when a reference to a variable falls outside the segment where that variable resides, or when a write is attempted to a location that is in a read-only segment.

How do I fix SIGSEGV error?

Make sure you aren't using variables that haven't been initialised. These may be set to 0 on your computer, but aren't guaranteed to be on the judge. Check every single occurrence of accessing an array element and see if it could possibly be out of bounds. Make sure you aren't declaring too much memory.


1 Answers

In Bland GCC compiles I have noticed > 75 % of Segment faults under linux are methods that define a return type and don't have one in the flow of the code.

I'd say when making something hop into existence with uncertainty, be really aware of returns and give then unused nominal values... not 'nulls' or fancy stuffola, just something to get in the game.

If as you progress this is uncool you can delete or revise them.

There's not enough detail in your message to understand your context, but GCC compiles with debug info added help hugely if you can run pdb. after it crashes in there there commands like frame and bt ( backtrace ) to help you.

like image 66
Dan Kolis Avatar answered Sep 19 '22 19:09

Dan Kolis