Question about compiled code size

Thread Starter

Stuntman

Joined Mar 28, 2011
222
I have an interesting issue that I am curious if anyone on here has any insight into.

I have been using CooIDE 1.7.8 and ARM GNU compiler (ver 4.7) for developing code on STM32 parts.

I finished a version of code and happened to recollect the "text" size during compilation. I was moving some files around, and again, compiled the code. Hmm, the "text" size did not seem right. I compiled again, still wrong.

Thinking I had gotten the wrong version, I did some moving. Here is what I found:

If I compile the code on a flash drive, I get size A (which happens to be the smallest). If I take this flash drive to another computer with the same IDE/Compiler, I again get size A. If I move the code to the desktop of my computer, I get size B. If I move the file to a project directory, I get size C (the largest). Size A and and size C differ by right over 500 bytes with "O1" optimization. (I assume "text" size is bytes). With optimization OFF, I still see a difference of around 300 bytes.

I did a compare the .hex files are indeed different (one is 39K, the other 41K). Seemingly mostly toward the end.

Thinking perhaps this was just some housekeeping crap, I imported the .hex files into my programming utility and sure enough, the two have different ending addresses in memory.

My understanding of the compilation process does not explain why where the target files resides have any influence on the size of the code going onto the controller. Is this just an IDE issue? Compiler issue?

This project I am trying to keep on a fairly space limited chip. I never thought I'd be forced to keep the source files in a particular location to meet the size requirement. :eek:
 

MrChips

Joined Oct 2, 2009
30,707
You are compiling the code on different computers, correct?

The IDE could have setup the toolset differently. You need the check all your setup and compiler options.
Are you using the same libraries and header files?

After compiling and linking, go and compare the map files for each target. You will see all the addresses and code sizes listed in the map file.
 

Thread Starter

Stuntman

Joined Mar 28, 2011
222
You are compiling the code on different computers, correct?
If I keep the files on a jump drive, I can compile on either computer and get exactly the same file size. However, if I move the file to different directories on the same computer, the compiled file size changes.

I checked the .maps as you suggested. Comparing, the size difference occurs on three types of files (that are repeated numerous times): .rodata, .debug_line, .debug_str.

I am unsure what these are exactly, but I have to assume that these files are referencing the directories on the computer for debugging purposes?

As a test, I compared the .hex that was generated using "rebuild" vs one that is generated using the "debug" button. The .hex files were identical.

When you build "debug" versions of code, does the actual .hex include some information about the source files' locations (perhaps for breakpoints, IDE use, etc)? In my case, could all of my code be getting generated as "debug" so when the source file paths change, the code includes some of these changes.

Reading this:
https://mcuoneclipse.com/2012/06/01/debug-vs-release/
It seems like this is true, but the size on the part memory should not include this extra debug information.

I'm sure there is a an explanation. I just hate not knowing what is going on behind the scenes.
 

MrChips

Joined Oct 2, 2009
30,707
I think you are getting the hang of it.

The debug version and the release version are different. The debug version references information from the compiler and linker in order to show symbol names when doing debug. The release version will have none of that.

I do not know exactly what is going on because I have never had any reason to compare the differences between debug and release versions.
 
Top