<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Override malloc and free in LPCXpresso IDE</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528298#M877</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by rocketdawg on Wed Oct 07 06:28:53 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: TheFallGuy&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Btw: what is special about your implementation that means you don't want to use the standard version?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The library version of malloc and free might not be thread safe.&amp;nbsp; Printf might not be either.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 23:01:48 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T23:01:48Z</dc:date>
    <item>
      <title>Override malloc and free</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528294#M873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by robertpalmerjr on Fri Oct 02 12:01:56 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I am wanting to override malloc and free in my project.&amp;nbsp; I am using freeRTOS and RedLib.&amp;nbsp; RedLib has functions that call malloc (various printf variants, are there others?) I would like my code to override malloc so that when RedLib calls malloc it calls my code which calls the freeRTOS implementation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In standard gcc, I see that there is a -wrap,object linker flag.&amp;nbsp; That does not appear to work in LPCxpresso.&amp;nbsp; I know if a symbol is WEAK linked, it can be overridden by just defining the symbol in your own code, but it appears that malloc and free are not weak linked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way to do this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:01:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528294#M873</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Override malloc and free</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528295#M874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by TheFallGuy on Fri Oct 02 16:36:57 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Just provide your own implementations in your sources. The linker wil, resolve yours and not use the ones from the redlib library.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Btw: what is special about your implementation that means you don't want to use the standard version?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:01:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528295#M874</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: Override malloc and free</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528296#M875</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by robertpalmerjr on Mon Oct 05 10:39:01 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I have already tried that but providing my own implementation in the sources leads to a linker error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I added this to my main.c:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
void *malloc(size_t size)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; return NULL;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and the resulting compile generated this error.&amp;nbsp; By the way, I have also tested this with version 7.7.2 with the same result.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/Applications/lpcxpresso_5.2.4_2122/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m/libcr_c.a(alloc.o): In function `malloc':
alloc.c:(.text.malloc+0x0): multiple definition of `malloc'
./src_codered/retarget.o:/Volumes/Ingenutec/Active Project Code/IPS/workspace/Meter/Release/../src_codered/retarget.c:77: first defined here
collect2: ld returned 1 exit status
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As for what's so special - not a thing.&amp;nbsp; I just want to use only ONE memory allocation scheme, the one in freeRTOS.&amp;nbsp; This allows me to better manage the RAM rather than having freeRTOS allocations for some things (in the freeRTOS "heap") and malloc allocations in a different heap.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:01:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528296#M875</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Override malloc and free</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528297#M876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by lpcxpresso-support on Mon Oct 05 13:14:48 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;You might want to consider coming at this from a different direction. If you define CR_PRINTF_CHAR in the properties for your project, then this should avoid the printf variant that uses malloc. Thus avoiding the malloc version from Redlib altogether.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fwww.lpcware.com%2Fcontent%2Ffaq%2Flpcxpresso%2Fusing-printf" rel="nofollow" target="_blank"&gt;https://www.lpcware.com/content/faq/lpcxpresso/using-printf&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LPCXpresso Support&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:01:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528297#M876</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Override malloc and free</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528298#M877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by rocketdawg on Wed Oct 07 06:28:53 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: TheFallGuy&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Btw: what is special about your implementation that means you don't want to use the standard version?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The library version of malloc and free might not be thread safe.&amp;nbsp; Printf might not be either.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:01:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Override-malloc-and-free/m-p/528298#M877</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:01:48Z</dc:date>
    </item>
  </channel>
</rss>

