Ho do I Eliminate the Heap?

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm wondering of anyone knows how to get rid of the heap. I am not using it, but I'm thinking that some part of another standard library must be since the linker insists on including it. I finally got rid of sprintf and all of its parts (huge), but I can't seem to eliminate the heap.

Alternatively, does anyone know if there's a way to generate a cross reference file which would tell me what modules/functions are referencing the heap functions? Then I'd know what else I have to get rid of in order to lose the heap.

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Isn't there some heapsize variable in a linker/make script or so?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

add this to your linker options ;
-Wl,-Map=yourmap.map
or
-Wl,-Map=yourmap.map,--cref

You could also run avr32-objdump.exe or avr32-nm.exe or avr32-readelf.exe against the .ELF file

But I have to ask., why do you want to get rid of the heap ?
The heap is the unallocated RAM between the end of your static/global/initialised variables and the stack, as determined at link time.
If you don't use malloc() or similar during runtime then the heap will remain unused.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Put " __heap_size__ = 0;" under the line "__max_heap_size__ = -1;" in your linker .lds file. But beware, I searched for some hours, till I found that the printf family uses the heap, and will crash if the heap is zero.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the suggestions. I had already generated the map file (that’s how I knew the heap was still in there), but I hadn’t realized that this file is also a cross-reference. It appears that strtok is what’s using the heap.

I just tweaked my program to not use strtok, and the resulting binary decreased by 4K. That’s insane. Strtok itself seems to be only a couple hundred bytes, but apparently it brings in several kilobytes of other stuff.

To answer mikech’s question: I want to get rid of the heap because it brings in too much code. I don’t care about the RAM; it’s the flash space I’m concerned about. I’m making a small boot loader program for loading new firmware and I want it to fit in 16K. Currently it does, but not with enough extra space for my comfort level to allow for possible growth down the road.

It apears this is solved. Thanks everyone!