Particle Electron fails to compile using Eclipse with -Os optimizations off

Hello,
I followed the directions here to get my Particle Electron up and running:
https://docs.particle.io/faq/particle-tools/eclipse-debug/core/

However, when debugging, I’d like to remove optimizations from my code to better see where it’s stepping through. When I followed these directions:
https://docs.particle.io/faq/particle-tools/eclipse-debug/core/#changing-the-gcc-optimization-level

I’m getting the following error in Eclipse:

/firmware/hal/src/stm32f2xx/usb_hal.c:435: undefined reference to `HAL_ServicedIRQn’
collect2: error: ld returned 1 exit status
make[1]: *** [/target/.elf] Error 1
…/build/module.mk:222: recipe for target ‘/target/.elf’ failed
make: *** [target/.bin] Error 2
make[1]: Leaving directory ‘/firmware/main’

It’s literally the difference of switching the little optimization flag on or off, I’m not sure why I’m getting this error at all.
Makefile:16: recipe for target ‘target/smartfin.bin’ failed

I’m using the release/v0.7.0-rc.1 branch.

The comment in the doc also says:

This is probably best done only for monolithic debug builds, since you may run out of space for some system parts in a modular build without optimization.

Are you building monolithic firmware?

The problem is that the linker failed. The cause could be that it could not provide linkage from system firmware compiled with -Os to user-code compiled without it, but I'm not sure.

You can eliminate this problem by using a monolithic build which will recompile everything without the -Os but you may have trouble fitting into memory without the optimizations.

I’m building the project with the following env flags:

program-dfu PLATFORM=electron MODULAR=n DEBUG_BUILD=y USE_SWD_JTAG=y

I assume MODULAR=n is the correct way to make the build monolithic since it’s the only thing that the guide linked above mentions.

The Makefile can be found on that guide as well, but pretty much on a make it does the following:

cd “$(FIRMWARE)/main” && make all PLATFORM=$(PLATFORM) APPDIR="$(APPDIR)" $(MAKEOPTS)

One suspicious thing is that when I try to issue the build commands listed in the Makefile for clean, ie

cd “$(FIRMWARE)/modules” && make clean all make PLATFORM=electron MODULAR=n DEBUG_BUILD=y USE_SWD_JTAG=y APPDIR=…/…/…/my_project

I can see it trying to flash the Electron 3 separate times. I suspect when it’s building the modules, it’s not building them in a monolithic fashion.

Which makefile is Eclipse using?
On the command line you’d need to build from the correct directory - meaning with the respective makefile. For Eclipse I suppose you need to select the correct one some other way.

The instructions say to just copy and paste the following into the Eclipse Makefile
https://docs.particle.io/faq/particle-tools/eclipse-debug/core/#create-an-eclipse-project-all-operating-systems

Basically this:

$(TARGETBIN) : $(source)
cd “$(FIRMWARE)/main” && make all PLATFORM=$(PLATFORM) APPDIR="$(APPDIR)" $(MAKEOPTS)

clean :
cd “$(FIRMWARE)/modules” && make clean all PLATFORM=$(PLATFORM) APPDIR="$(APPDIR)" $(MAKEOPTS)

(sorry I don’t know how to format code here)

So when you execute a make, you cd into the firmware_dir/main and make with the appropriate arguments.
Upon a clean, you cd into modules and make clean that? (I think that part is weird, but I don’t really know).

But I can just cd and execute the commands from the command line, the output is the same.

You can wrap your code block in a set of these

 ```text
  // your block of text (for C++ you'd use ```cpp)
where each set of these accent graves lives on its own line without anything else (including blanks) on the same line

And for the `makefile` I'm not an expert, but I think it's just the first one that provides the entry point and then traverses from `makefile` to `makefile` as long the relative references can be solved.