<?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: Does MCUXpresso support __attribute__((constructor)) declaration? in MCUXpresso IDE</title>
    <link>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1714134#M9147</link>
    <description>&lt;P&gt;I'm using the latest IDE 11.8.0 (see &lt;A href="https://mcuoneclipse.com/2023/08/06/mcuxpresso-ide-11-8-0/" target="_blank" rel="noopener"&gt;https://mcuoneclipse.com/2023/08/06/mcuxpresso-ide-11-8-0/&lt;/A&gt; ), and here I see that it gets linked:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;.text._ZL9fipsEntryv&lt;/P&gt;&lt;P&gt;0x00000c7c 0xe ./source/main.o&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;I had not a chance to see how it looks for your older IDE version, but for sure 11.4.0 includes older GNU tools.&lt;/P&gt;&lt;P&gt;Just few things to note:&lt;/P&gt;&lt;P&gt;- the code with the attribute needs to be compiled as C++&lt;/P&gt;&lt;P&gt;- the startup code needs to support C++ constructor/destructor calls. See &lt;A href="https://mcuoneclipse.com/2020/07/11/from-c-to-c-converting-eclipse-c-projekts/" target="_blank" rel="noopener"&gt;https://mcuoneclipse.com/2020/07/11/from-c-to-c-converting-eclipse-c-projekts/&lt;/A&gt; for details.&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;</description>
    <pubDate>Wed, 30 Aug 2023 16:16:32 GMT</pubDate>
    <dc:creator>ErichStyger</dc:creator>
    <dc:date>2023-08-30T16:16:32Z</dc:date>
    <item>
      <title>Does MCUXpresso support __attribute__((constructor)) declaration?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1713781#M9144</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;We are using RT1050 with MCUXpresso v11.4.0, we recently introduced a 3rd part library, which declares his entry as&lt;/P&gt;&lt;P&gt;static void __attribute__((constructor)) fipsEntry(void);&lt;/P&gt;&lt;P&gt;The constructor attribute causes the function to be called automatically before execution enters main(), it works well with GCC compiler, but when I tried to build it in IDE, this function always gets discarded by the linker because nobody refers it, I cannot even call it explicitly because it's static.&lt;/P&gt;&lt;P&gt;My question is why the compiler in MCUXpresso&amp;nbsp;doesn't support / recognize the constructor attribute?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 06:57:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1713781#M9144</guid>
      <dc:creator>mark_li</dc:creator>
      <dc:date>2023-08-30T06:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Does MCUXpresso support __attribute__((constructor)) declaration?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1714134#M9147</link>
      <description>&lt;P&gt;I'm using the latest IDE 11.8.0 (see &lt;A href="https://mcuoneclipse.com/2023/08/06/mcuxpresso-ide-11-8-0/" target="_blank" rel="noopener"&gt;https://mcuoneclipse.com/2023/08/06/mcuxpresso-ide-11-8-0/&lt;/A&gt; ), and here I see that it gets linked:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;.text._ZL9fipsEntryv&lt;/P&gt;&lt;P&gt;0x00000c7c 0xe ./source/main.o&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;I had not a chance to see how it looks for your older IDE version, but for sure 11.4.0 includes older GNU tools.&lt;/P&gt;&lt;P&gt;Just few things to note:&lt;/P&gt;&lt;P&gt;- the code with the attribute needs to be compiled as C++&lt;/P&gt;&lt;P&gt;- the startup code needs to support C++ constructor/destructor calls. See &lt;A href="https://mcuoneclipse.com/2020/07/11/from-c-to-c-converting-eclipse-c-projekts/" target="_blank" rel="noopener"&gt;https://mcuoneclipse.com/2020/07/11/from-c-to-c-converting-eclipse-c-projekts/&lt;/A&gt; for details.&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 16:16:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1714134#M9147</guid>
      <dc:creator>ErichStyger</dc:creator>
      <dc:date>2023-08-30T16:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: Does MCUXpresso support __attribute__((constructor)) declaration?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1714605#M9149</link>
      <description>&lt;P&gt;Erich, thanks for your reply.&lt;/P&gt;&lt;P&gt;Unfortunately we cannot afford to switch the whole project to C++, it has already been in mass production. I tried IDE 11.8 and got the same result (compiled as C).&lt;/P&gt;&lt;P&gt;However I doubt that this can only be done in C++, we keep both GCC build (for firmware release) and IDE build (for bug diagnosis) environments for the same project, in GCC environment it's also compiled as C and works well, that entry function get linked in elf and called from startup code with the help of crt0.o&lt;/P&gt;&lt;P&gt;Below are the build result from both map files, in IDE it's thrown into discarded section.&lt;/P&gt;&lt;P&gt;GCC:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; .text.fipsEntry&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 0x0000000060105f28 0x58 ./fips.c.obj&lt;/P&gt;&lt;P&gt;IDE:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; .text.fipsEntry&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &lt;FONT color="#FF0000"&gt;0x00000000&lt;/FONT&gt; 0x58 ./fips.o&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 03:35:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1714605#M9149</guid>
      <dc:creator>mark_li</dc:creator>
      <dc:date>2023-08-31T03:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: Does MCUXpresso support __attribute__((constructor)) declaration?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1719014#M9161</link>
      <description>&lt;P class="lia-align-justify"&gt;Hello &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/193920"&gt;@mark_li&lt;/a&gt;,&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;Could you please try out enabling &lt;EM&gt;All Warnings (-Wall) directive in Properties -&amp;gt; C/C++ Build -&amp;gt; Settings -&amp;gt; MCU C Compiler -&amp;gt; Warnings&lt;/EM&gt;? Which optimization level and dialect are you using?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RaulRomero_0-1694115606440.png" style="width: 417px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/240086i7C5783D42F554EB9/image-dimensions/417x168?v=v2" width="417" height="168" role="button" title="RaulRomero_0-1694115606440.png" alt="RaulRomero_0-1694115606440.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;[MCUXpresso IDE Properties]&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;Also, if possible, could you please share a demo code with &lt;EM&gt;static void __attribute__((constructor)) fipsEntry(void);&lt;/EM&gt; entry to show me the issue?&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;Best regards, Raul.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 19:40:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1719014#M9161</guid>
      <dc:creator>RaRo</dc:creator>
      <dc:date>2023-09-07T19:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Does MCUXpresso support __attribute__((constructor)) declaration?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1719211#M9164</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/193920"&gt;@mark_li&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;C++: I did a quick test with my standard C++ project and the updated C++ startup code, and it worked there. Yes, it very likely will work with C code too, as long as the startup code calls the needed initialization (which it does in my example for C++).&lt;/P&gt;&lt;P&gt;If time permits, I'll check with plain C in the next days and report back.&lt;/P&gt;&lt;P&gt;Would that help?&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 03:37:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1719211#M9164</guid>
      <dc:creator>ErichStyger</dc:creator>
      <dc:date>2023-09-08T03:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Does MCUXpresso support __attribute__((constructor)) declaration?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1736217#M9235</link>
      <description>&lt;P&gt;I wrote an article about using the constructor and destructor attribute here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://mcuoneclipse.com/2023/10/09/global-constructors-and-destructors-with-c-not-c/" target="_blank"&gt;https://mcuoneclipse.com/2023/10/09/global-constructors-and-destructors-with-c-not-c/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It works perfectly, but you have to make sure that your startup code is calling the constructor and destructor hooks, which is not the case for the C startup code provided by the MCUXpresso SDK.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 04:12:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Does-MCUXpresso-support-attribute-constructor-declaration/m-p/1736217#M9235</guid>
      <dc:creator>ErichStyger</dc:creator>
      <dc:date>2023-10-10T04:12:55Z</dc:date>
    </item>
  </channel>
</rss>

