Compiler Segmentation Faults

I have a very large program that is no generating lots of internal compiler error Segmentation faults. The frequency of the failures seems at least loosely tied to the size of the program.

I am using Visual Micro add-in to Visual Studio and am compiling on a Mega board.

I have way too much code to post here, but I am hoping someone can let me know what (in general) causes a compiler segmentation fault?

(deleted)

Every time I've seen that, it's been a compiler or linker bug. What version of IDE are you using? I stopped updating at version 1.8.4, which I've found to be pretty stable. Seems like every time I update to a "new and improved" version, I just run face-first into new bugs.

Regards,
Ray L.

(deleted)

spycatcher2k:
No Arduino IDE! :slight_smile:

Are you at all familiar with VisualMicro? It REQUIRES the Arduino IDE, and uses the Arduino build process. Most importantly it uses the Arduino compiler and linker and libraries, in exactly the same way the Arduino IDE does. I have been using it exclusively for many years, and have not ONCE found a bug that was present when using VisualMicro and NOT present when using the IDE. Visual Micro is simply a VisualStudio plug-in that provides graphical source file management and provides an interface to the Arduino build system from VisualStudio.
Besides, a segmentation fault can ONLY be caused an internal compiler bug. There is NOTHING in the OPs code or Visual Micro that can cause that to happen.
Regards,
Ray L

This bug is specific to the 5.4.0-atmel3.6.1-arduino2 version of avr-gcc used by Arduino AVR Boards 1.6.22 and newer. It has been reported here:

Here's the traditional workaround:

  • Tools > Board > Boards Manager
  • Wait for downloads to finish.
  • When you move the mouse pointer over "Arduino AVR Boards", you will see a "Select version" dropdown menu appear. Select "1.6.21".
  • Click "Install".
  • Wait for installation to finish.
  • Click "Close".

Due to a bug, this workaround doesn't work with Arduino IDE 1.8.6, but it will work with any other version of the Arduino IDE.

If you have File > Preferences > Check for updates on startup checked, the Arduino IDE may occasionally notify you that a new version of Arduino AVR Boards is available, you'll need to refrain from updating back to the new Arduino AVR Boards version, otherwise you'll be back to seeing the segmentation fault error again.

Alternate workaround:
One of the Arduino developers recently worked on this and claims to have fixed it. There is a special beta testing hardware package you can install via the Arduino IDE's Boards Manager that has the fix:

  • (In the Arduino IDE) File > Preferences
  • In the "Additional Boards Manager URLs" field, enter: http://downloads.arduino.cc/packages/package_avr_7.3.0_index.json
  • If you already have an additional Boards Manager URL in that field, you can separate multiple URLs with commas or click the button on the right side of the field to open a dialog that allows you to add each on its own line.
  • Click "OK"
  • Tools > Board > Boards Manager
  • Wait for the downloads to finish
  • Click on "Arduino AVR Boards by Arduino"
  • Click the "Update" button.
  • Wait for the update to finish.
  • Click "Close".

Now the question is whether Visual Micro will use the installed avr-gcc 7.3.0-atmel3.6.1-arduino3 instead of the avr-gcc 5.4.0-atmel3.6.1-arduino2 bundled with the IDE? You should be able to check by looking at the output to see whether the path to the compiler is under the Arduino IDE installation folder or your Arduino15 folder. I don't Use Visual Micro so I can't tell you.

pert:
Now the question is whether Visual Micro will use the installed avr-gcc 7.3.0-atmel3.6.1-arduino3 instead of the avr-gcc 5.4.0-atmel3.6.1-arduino2 bundled with the IDE? You should be able to check by looking at the output to see whether the path to the compiler is under the Arduino IDE installation folder or your Arduino15 folder. I don't Use Visual Micro so I can't tell you.

VisualMicro will use whatever version(s) of the tools the user tells it to use. The user tells it where to find the Arduino tools as part of its configuration.

Regards,
Ray L.

I normally develop and test incrementally, so it is usually clear what caused the problem by a small amount of backtracking. However I did once attempt to use someone else's code (a huge DCF77 simulator) which gave a segmentation fault and the only way I could find it was to do a repeated binary chop of the program until I found what caused it.
In that specific case, it turned out to be the qualifier 'attribute((always_inline))' on this definition:

inline uint8_t days_per_month(const DCF77::time_data_t &now) __attribute__((always_inline));

Of course, in any specific case, it could be anything.

With the avr-gcc 5.4.0-atmel3.6.1-arduino2 specific segmentation faults, I tried that but it was not consistent. I'd chop the program back until the fault went away, then add back the last removed section and the fault would still not occur! Sometimes just restarting my computer would make the code that was previously causing a segmentation fault to successfully compile.

This inability to create a MCVE has made it very difficult to deal with this issue. When the Arduino developer published the beta test package, I first attempted to reproduce the error by compiling two programs I had previously encountered the segmentation fault with, using avr-gcc 5.4.0-atmel3.6.1-arduino2, but the issue didn't occur! Without being able to reproduce the problem, I can't say whether the fix works. The Arduino developer had the same problem.