<?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 Issue with new linker release BLD-1705: Order or expression evaluation in S32 Design Studio</title>
    <link>https://community.nxp.com/t5/S32-Design-Studio/Issue-with-new-linker-release-BLD-1705-Order-or-expression/m-p/1434269#M8395</link>
    <description>&lt;P&gt;Dear NXP Team,&lt;/P&gt;&lt;P&gt;I run into an issue with the latest PowerPC GCC,&lt;BR /&gt;gcc-4.9.4-Ee200-eabivle-i686-mingw32-g2724867_signed, which is labelled&lt;BR /&gt;BLD-1705. Downloaded a few days ago from your site.&lt;/P&gt;&lt;P&gt;The existing linker script (perfectly fine till BLD-1607) fails.&lt;BR /&gt;A comparison of the map files shows that the problem results from the way,&lt;BR /&gt;the memory regions are defined. They are not set via literals but by&lt;BR /&gt;linker run-time expressions, and the two compilers seem to differ in the&lt;BR /&gt;way, when these expressions are expanded.&lt;/P&gt;&lt;P&gt;Below you find the relevant excerpt from the linker script. Besides&lt;BR /&gt;some likely irrelated stack and heap size assignments (all using literals),&lt;BR /&gt;it is the beginning of the linker script.&lt;/P&gt;&lt;P&gt;The concept is using a flag, ld_linkInRAM, to have different memory&lt;BR /&gt;partitioning. This way, the SW can be loaded either in RAM or in ROM. The&lt;BR /&gt;flag is set from the linker command line using --defsym.&lt;/P&gt;&lt;P&gt;Unfortunately, using this technique, the linker BLD-1705 ends up with&lt;BR /&gt;totally wrong memory regions (see below). My presumption is that this has&lt;BR /&gt;to do with the order of evaluation of the conditional expressions.&lt;/P&gt;&lt;P&gt;I think so because of the observation, that the new linker re-produces&lt;BR /&gt;the behavior of BLD-1607 if I replace all conditional expressions with&lt;BR /&gt;their results (see commented blocks below). Now, the map file shows the&lt;BR /&gt;old, correct figures for memory region origins and lengths - in either&lt;BR /&gt;case, RAM and ROM.&lt;/P&gt;&lt;P&gt;Moreover, the wrong values for origin and length, which I see when using&lt;BR /&gt;the conditional expressions with BLD-1705, can be explained by a value of&lt;BR /&gt;zero for the intermediate variables. It looks much as if origin and length&lt;BR /&gt;of the memory regions were evaluated before the conditional expressions&lt;BR /&gt;are evaluated.&lt;/P&gt;&lt;P&gt;As said, BLD-1607 works as expected, which is expression evaluation in&lt;BR /&gt;strictly sequential order from top to bottom of the linker script, i.e.,&lt;BR /&gt;line after line.&lt;/P&gt;&lt;P&gt;Here is the wrong memory region table, found in the map file with BLD-1705&lt;BR /&gt;and ld_linkInRAM==0:&lt;/P&gt;&lt;P&gt;Name Origin Length Attributes&lt;BR /&gt;memBoot 0x00000000 0x00000008 xr&lt;BR /&gt;memFlash 0x00000008 0xfffffff8 xr&lt;BR /&gt;memData 0x00000000 0xffff0000 xrw&lt;BR /&gt;memDataUncached 0xffff0000 0x00010000 xrw&lt;BR /&gt;*default* 0x00000000 0xffffffff&lt;/P&gt;&lt;P&gt;Here is the same memory region table, found in the map file with BLD-1607&lt;BR /&gt;(ld_linkInRAM==0) and also found with BLD-1705, if the conditional&lt;BR /&gt;expressions are replaced by the code block using unconditional&lt;BR /&gt;assignments:&lt;/P&gt;&lt;P&gt;Name Origin Length Attributes&lt;BR /&gt;memBoot 0x00800000 0x00000008 xr&lt;BR /&gt;memFlash 0x00800008 0x003ffff8 xr&lt;BR /&gt;memData 0x40000000 0x00070000 xrw&lt;BR /&gt;memDataUncached 0x40070000 0x00010000 xrw&lt;BR /&gt;*default* 0x00000000 0xffffffff&lt;/P&gt;&lt;P&gt;Would you please double check the linker's way of expression evaluation?&lt;/P&gt;&lt;P&gt;Would you please try to re-produce the problem?&lt;/P&gt;&lt;P&gt;As a workaround, I can let my makefile take the decision and load&lt;BR /&gt;either/or a ROM/RAM script.&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;Peter&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Down here is the excerpt from the linker script:&lt;/P&gt;&lt;P&gt;/* We use the simple conditional operator the linker script syntax offers for switching&lt;BR /&gt;from normal build of a flashable binary to an equivalent binary that can be loaded into&lt;BR /&gt;RAM by the debugger. Using RAM can have these advantages:&lt;BR /&gt;- We save flash ROM programming cycles, which are limited&lt;BR /&gt;- It reduces the turnaround time between code changes. Loading RAM is faster than&lt;BR /&gt;erasing and re-flashing&lt;BR /&gt;- The risk of bricking the CPU is lower if we work on code, which is critical in this&lt;BR /&gt;respect; e.g. self-tests, security, reset logic, reset escalation&lt;BR /&gt;The major drawback is the software size; code and data need to fit into RAM. We use a&lt;BR /&gt;hardcoded distribution of both, 75% for code, 25% for data.&lt;BR /&gt;Note, the switch ld_linkInRAM is set by the makefile using the linker command line&lt;BR /&gt;option --defsym. */&lt;BR /&gt;ld_textSegStartAddr = ld_linkInRAM==1? 0x40000000 : 0x00800000;&lt;BR /&gt;ld_textSegSize = ld_linkInRAM==1? 3*128k : 0x400000;&lt;BR /&gt;ld_dataSegStartAddr = ld_linkInRAM==1? ld_textSegStartAddr + ld_textSegSize : 0x40000000;&lt;BR /&gt;ld_dataSegSize = ld_linkInRAM==1? 4*128k - ld_textSegSize : 4*128k;&lt;/P&gt;&lt;P&gt;/* ROM */&lt;BR /&gt;/*&lt;BR /&gt;ld_textSegStartAddr = 0x00800000 ;&lt;BR /&gt;ld_textSegSize = 0x400000 ;&lt;BR /&gt;ld_dataSegStartAddr = 0x40000000 ;&lt;BR /&gt;ld_dataSegSize = 4*128k ;&lt;BR /&gt;*/&lt;BR /&gt;/* RAM */&lt;BR /&gt;/*&lt;BR /&gt;ld_textSegStartAddr = 0x40000000 ;&lt;BR /&gt;ld_textSegSize = 3*128k ;&lt;BR /&gt;ld_dataSegStartAddr = ld_textSegStartAddr + ld_textSegSize ;&lt;BR /&gt;ld_dataSegSize = 4*128k - ld_textSegSize ;&lt;BR /&gt;*/&lt;/P&gt;&lt;P&gt;/* On the MPC5775B/E only the MMU can realize uncached memory. This restricts the size and&lt;BR /&gt;adress to powers of two. Our startup code configures the last 64k of RAM as uncached.&lt;BR /&gt;The next settings are not changeable. */&lt;BR /&gt;ASSERT(ld_dataSegSizeTmp &amp;gt;= 128k, "linkerControlFile.ld: Data segment is too little")&lt;BR /&gt;ld_dataSegSize -= 64k;&lt;BR /&gt;ld_dataUncachedSegStartAddr = ld_dataSegStartAddr + ld_dataSegSize ;&lt;BR /&gt;ld_dataUncachedSegSize = 64k ;&lt;/P&gt;&lt;P&gt;/* Definition of memory regions using absolute addresses of physical memories. */&lt;BR /&gt;MEMORY&lt;BR /&gt;{&lt;BR /&gt;memBoot(rx): org = ld_textSegStartAddr, len = 0x8&lt;BR /&gt;memFlash(rx): org = ld_textSegStartAddr + LENGTH(memBoot), len = ld_textSegSize - LENGTH(memBoot)&lt;BR /&gt;memData(rwx): org = ld_dataSegStartAddr, len = ld_dataSegSize&lt;BR /&gt;memDataUncached(rwx): org = ld_dataUncachedSegStartAddr, len = ld_dataUncachedSegSize&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/* Export the location of the (physical) RAM storage space as far as required by the startup&lt;BR /&gt;code.&lt;BR /&gt;Note: For operation of code in RAM, it is essential to not refer to the entire physical&lt;BR /&gt;RAM - otherwise our startup code would erase all the code segments, which had just&lt;BR /&gt;before been loaded by the debugger. */&lt;BR /&gt;ld_memRamStart = ORIGIN(memData);&lt;BR /&gt;ld_memRamSize = LENGTH(memData) + LENGTH(memDataUncached);&lt;BR /&gt;ld_memRamEnd = ld_memRamStart + ld_memRamSize;&lt;BR /&gt;ASSERT(ld_memRamSize == (ld_linkInRAM==1? 128k: 512k), "linkerControlFile.ld: Bad partitioning of RAM");&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2022 17:37:50 GMT</pubDate>
    <dc:creator>peter_vranken</dc:creator>
    <dc:date>2022-03-25T17:37:50Z</dc:date>
    <item>
      <title>Issue with new linker release BLD-1705: Order or expression evaluation</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/Issue-with-new-linker-release-BLD-1705-Order-or-expression/m-p/1434269#M8395</link>
      <description>&lt;P&gt;Dear NXP Team,&lt;/P&gt;&lt;P&gt;I run into an issue with the latest PowerPC GCC,&lt;BR /&gt;gcc-4.9.4-Ee200-eabivle-i686-mingw32-g2724867_signed, which is labelled&lt;BR /&gt;BLD-1705. Downloaded a few days ago from your site.&lt;/P&gt;&lt;P&gt;The existing linker script (perfectly fine till BLD-1607) fails.&lt;BR /&gt;A comparison of the map files shows that the problem results from the way,&lt;BR /&gt;the memory regions are defined. They are not set via literals but by&lt;BR /&gt;linker run-time expressions, and the two compilers seem to differ in the&lt;BR /&gt;way, when these expressions are expanded.&lt;/P&gt;&lt;P&gt;Below you find the relevant excerpt from the linker script. Besides&lt;BR /&gt;some likely irrelated stack and heap size assignments (all using literals),&lt;BR /&gt;it is the beginning of the linker script.&lt;/P&gt;&lt;P&gt;The concept is using a flag, ld_linkInRAM, to have different memory&lt;BR /&gt;partitioning. This way, the SW can be loaded either in RAM or in ROM. The&lt;BR /&gt;flag is set from the linker command line using --defsym.&lt;/P&gt;&lt;P&gt;Unfortunately, using this technique, the linker BLD-1705 ends up with&lt;BR /&gt;totally wrong memory regions (see below). My presumption is that this has&lt;BR /&gt;to do with the order of evaluation of the conditional expressions.&lt;/P&gt;&lt;P&gt;I think so because of the observation, that the new linker re-produces&lt;BR /&gt;the behavior of BLD-1607 if I replace all conditional expressions with&lt;BR /&gt;their results (see commented blocks below). Now, the map file shows the&lt;BR /&gt;old, correct figures for memory region origins and lengths - in either&lt;BR /&gt;case, RAM and ROM.&lt;/P&gt;&lt;P&gt;Moreover, the wrong values for origin and length, which I see when using&lt;BR /&gt;the conditional expressions with BLD-1705, can be explained by a value of&lt;BR /&gt;zero for the intermediate variables. It looks much as if origin and length&lt;BR /&gt;of the memory regions were evaluated before the conditional expressions&lt;BR /&gt;are evaluated.&lt;/P&gt;&lt;P&gt;As said, BLD-1607 works as expected, which is expression evaluation in&lt;BR /&gt;strictly sequential order from top to bottom of the linker script, i.e.,&lt;BR /&gt;line after line.&lt;/P&gt;&lt;P&gt;Here is the wrong memory region table, found in the map file with BLD-1705&lt;BR /&gt;and ld_linkInRAM==0:&lt;/P&gt;&lt;P&gt;Name Origin Length Attributes&lt;BR /&gt;memBoot 0x00000000 0x00000008 xr&lt;BR /&gt;memFlash 0x00000008 0xfffffff8 xr&lt;BR /&gt;memData 0x00000000 0xffff0000 xrw&lt;BR /&gt;memDataUncached 0xffff0000 0x00010000 xrw&lt;BR /&gt;*default* 0x00000000 0xffffffff&lt;/P&gt;&lt;P&gt;Here is the same memory region table, found in the map file with BLD-1607&lt;BR /&gt;(ld_linkInRAM==0) and also found with BLD-1705, if the conditional&lt;BR /&gt;expressions are replaced by the code block using unconditional&lt;BR /&gt;assignments:&lt;/P&gt;&lt;P&gt;Name Origin Length Attributes&lt;BR /&gt;memBoot 0x00800000 0x00000008 xr&lt;BR /&gt;memFlash 0x00800008 0x003ffff8 xr&lt;BR /&gt;memData 0x40000000 0x00070000 xrw&lt;BR /&gt;memDataUncached 0x40070000 0x00010000 xrw&lt;BR /&gt;*default* 0x00000000 0xffffffff&lt;/P&gt;&lt;P&gt;Would you please double check the linker's way of expression evaluation?&lt;/P&gt;&lt;P&gt;Would you please try to re-produce the problem?&lt;/P&gt;&lt;P&gt;As a workaround, I can let my makefile take the decision and load&lt;BR /&gt;either/or a ROM/RAM script.&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;Peter&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Down here is the excerpt from the linker script:&lt;/P&gt;&lt;P&gt;/* We use the simple conditional operator the linker script syntax offers for switching&lt;BR /&gt;from normal build of a flashable binary to an equivalent binary that can be loaded into&lt;BR /&gt;RAM by the debugger. Using RAM can have these advantages:&lt;BR /&gt;- We save flash ROM programming cycles, which are limited&lt;BR /&gt;- It reduces the turnaround time between code changes. Loading RAM is faster than&lt;BR /&gt;erasing and re-flashing&lt;BR /&gt;- The risk of bricking the CPU is lower if we work on code, which is critical in this&lt;BR /&gt;respect; e.g. self-tests, security, reset logic, reset escalation&lt;BR /&gt;The major drawback is the software size; code and data need to fit into RAM. We use a&lt;BR /&gt;hardcoded distribution of both, 75% for code, 25% for data.&lt;BR /&gt;Note, the switch ld_linkInRAM is set by the makefile using the linker command line&lt;BR /&gt;option --defsym. */&lt;BR /&gt;ld_textSegStartAddr = ld_linkInRAM==1? 0x40000000 : 0x00800000;&lt;BR /&gt;ld_textSegSize = ld_linkInRAM==1? 3*128k : 0x400000;&lt;BR /&gt;ld_dataSegStartAddr = ld_linkInRAM==1? ld_textSegStartAddr + ld_textSegSize : 0x40000000;&lt;BR /&gt;ld_dataSegSize = ld_linkInRAM==1? 4*128k - ld_textSegSize : 4*128k;&lt;/P&gt;&lt;P&gt;/* ROM */&lt;BR /&gt;/*&lt;BR /&gt;ld_textSegStartAddr = 0x00800000 ;&lt;BR /&gt;ld_textSegSize = 0x400000 ;&lt;BR /&gt;ld_dataSegStartAddr = 0x40000000 ;&lt;BR /&gt;ld_dataSegSize = 4*128k ;&lt;BR /&gt;*/&lt;BR /&gt;/* RAM */&lt;BR /&gt;/*&lt;BR /&gt;ld_textSegStartAddr = 0x40000000 ;&lt;BR /&gt;ld_textSegSize = 3*128k ;&lt;BR /&gt;ld_dataSegStartAddr = ld_textSegStartAddr + ld_textSegSize ;&lt;BR /&gt;ld_dataSegSize = 4*128k - ld_textSegSize ;&lt;BR /&gt;*/&lt;/P&gt;&lt;P&gt;/* On the MPC5775B/E only the MMU can realize uncached memory. This restricts the size and&lt;BR /&gt;adress to powers of two. Our startup code configures the last 64k of RAM as uncached.&lt;BR /&gt;The next settings are not changeable. */&lt;BR /&gt;ASSERT(ld_dataSegSizeTmp &amp;gt;= 128k, "linkerControlFile.ld: Data segment is too little")&lt;BR /&gt;ld_dataSegSize -= 64k;&lt;BR /&gt;ld_dataUncachedSegStartAddr = ld_dataSegStartAddr + ld_dataSegSize ;&lt;BR /&gt;ld_dataUncachedSegSize = 64k ;&lt;/P&gt;&lt;P&gt;/* Definition of memory regions using absolute addresses of physical memories. */&lt;BR /&gt;MEMORY&lt;BR /&gt;{&lt;BR /&gt;memBoot(rx): org = ld_textSegStartAddr, len = 0x8&lt;BR /&gt;memFlash(rx): org = ld_textSegStartAddr + LENGTH(memBoot), len = ld_textSegSize - LENGTH(memBoot)&lt;BR /&gt;memData(rwx): org = ld_dataSegStartAddr, len = ld_dataSegSize&lt;BR /&gt;memDataUncached(rwx): org = ld_dataUncachedSegStartAddr, len = ld_dataUncachedSegSize&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/* Export the location of the (physical) RAM storage space as far as required by the startup&lt;BR /&gt;code.&lt;BR /&gt;Note: For operation of code in RAM, it is essential to not refer to the entire physical&lt;BR /&gt;RAM - otherwise our startup code would erase all the code segments, which had just&lt;BR /&gt;before been loaded by the debugger. */&lt;BR /&gt;ld_memRamStart = ORIGIN(memData);&lt;BR /&gt;ld_memRamSize = LENGTH(memData) + LENGTH(memDataUncached);&lt;BR /&gt;ld_memRamEnd = ld_memRamStart + ld_memRamSize;&lt;BR /&gt;ASSERT(ld_memRamSize == (ld_linkInRAM==1? 128k: 512k), "linkerControlFile.ld: Bad partitioning of RAM");&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 17:37:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/Issue-with-new-linker-release-BLD-1705-Order-or-expression/m-p/1434269#M8395</guid>
      <dc:creator>peter_vranken</dc:creator>
      <dc:date>2022-03-25T17:37:50Z</dc:date>
    </item>
  </channel>
</rss>

