Skip to main content
Commonmark migration
Source Link

Does part of the main sketch transfer through in the compilation of malloc.c and realloc.c (as well as the c/c++ files)?

 

I would think so, being that it is compiled every time we change the main sketch.

Does part of the main sketch transfer through in the compilation of malloc.c and realloc.c (as well as the c/c++ files)?

 

I would think so, being that it is compiled every time we change the main sketch.

Does part of the main sketch transfer through in the compilation of malloc.c and realloc.c (as well as the c/c++ files)?

I would think so, being that it is compiled every time we change the main sketch.

replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/
Source Link
Added stuff about where malloc is located.
Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126

Are malloc.c and realloc.c being used anymore?

They are being used, the trick is to find them.

I can't see them being directly linked in a 1.6.5 compiler output, so I am assuming (I can't prove it right now) that they are linked in by default from libc.a (the default C library). Being a default library it is not mentioned on the linker line.

In my (Linux) installation I found that library here:

~/Development/arduino-1.6.5-r5/hardware/tools/avr/avr/lib/libc.a

If you do a nm on it you find this (amongst other things):

malloc.o:
00000002 C __brkval
         U __do_clear_bss
         U __do_copy_data
00000002 C __flp
00000146 T free
         U __heap_end
         U __heap_start
00000000 T malloc
00000000 D __malloc_heap_end
00000002 D __malloc_heap_start
00000004 D __malloc_margin
0000003e a __SP_H__
0000003d a __SP_L__
0000003f a __SREG__
00000000 a __tmp_reg__
00000001 a __zero_reg__

From man nm:

  "D"
  "d" The symbol is in the initialized data section.
 ...
  "T"
  "t" The symbol is in the text (code) section.

See http://www.linuxtopia.org/online_books/an_introduction_to_gcc/gccintro_17.html :

The C standard library itself is stored in '/usr/lib/libc.a' and contains functions specified in the ANSI/ISO C standard, such as 'printf'---this library is linked by default for every C program.


I am guessing here that malloc and free moved into the standard (default) library since version 1.0.6 (or they wanted to override it with a bugfix) and it is now being found, by default, in the standard C library as described above.

You should be able to find more about AVR libc at its page: http://www.nongnu.org/avr-libc/


Are malloc.c and realloc.c being used anymore?

They are being used, the trick is to find them.

I can't see them being directly linked in a 1.6.5 compiler output, so I am assuming (I can't prove it right now) that they are linked in by default from libc.a (the default C library). Being a default library it is not mentioned on the linker line.

In my (Linux) installation I found that library here:

~/Development/arduino-1.6.5-r5/hardware/tools/avr/avr/lib/libc.a

If you do a nm on it you find this (amongst other things):

malloc.o:
00000002 C __brkval
         U __do_clear_bss
         U __do_copy_data
00000002 C __flp
00000146 T free
         U __heap_end
         U __heap_start
00000000 T malloc
00000000 D __malloc_heap_end
00000002 D __malloc_heap_start
00000004 D __malloc_margin
0000003e a __SP_H__
0000003d a __SP_L__
0000003f a __SREG__
00000000 a __tmp_reg__
00000001 a __zero_reg__

From man nm:

  "D"
  "d" The symbol is in the initialized data section.
 ...
  "T"
  "t" The symbol is in the text (code) section.

See http://www.linuxtopia.org/online_books/an_introduction_to_gcc/gccintro_17.html :

The C standard library itself is stored in '/usr/lib/libc.a' and contains functions specified in the ANSI/ISO C standard, such as 'printf'---this library is linked by default for every C program.


I am guessing here that malloc and free moved into the standard (default) library since version 1.0.6 (or they wanted to override it with a bugfix) and it is now being found, by default, in the standard C library as described above.

You should be able to find more about AVR libc at its page: http://www.nongnu.org/avr-libc/

Added more explanations.
Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126
Loading
Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126
Loading