This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: Section header flags for NOLOAD and COPY

Tool/software: TI C/C++ Compiler

I am parsing section headers trying to distinguish between COPY and NOLOAD sections. From http://processors.wiki.ti.com/index.php/Linker_Special_Section_Types, it seems to me that COPY sections should have SHF_ALLOC set to 0 because space is not allocated in memory for these sections, while NOLOADs should have 1 because space is allocated for them. But, I can see that both have SHF_ALLOC set to 0.

Am I misinterpreting SHF_ALLOC? The tools are Arm tools 18.1.1. Is there any other way to figure out the difference between these section types? 

  • I need to confirm the following is correct.  

    A NOLOAD section has these properties:

    • Section type: SHT_NOBITS
    • Size: non-zero
    • SHF_ALLOC = 0

    A COPY section has these properties:

    • Section type: SHT_PROGBITS
    • Size: non-zero
    • SHF_ALLOC = 0

    Thanks and regards,

    -George

  • GCC, more specifically Linaro GCC Arm compiler 7.2.1 sets SHF_ALLOC bit to 1 for NOLOAD sections, which is what I expected for sections that have memory space allocated to them. Also, a NOLOAD section has a non-zero base address, also expected because it does occupy memory on that address.
    It seems to me it's a bug in TI tools, but I could also understand that it would be a low priority one, even if it were a bug.
  • The discussion continued offline.  It turns out the ELF specification is silent regarding how a NOLOAD section is handled.  The TI and GCC toolsets do it differently, particularly with regard to whether SHF_ALLOC is set.  Therefore, you cannot rely on SHF_ALLOC to know whether a section was marked NOLOAD.

    Thanks and regards,

    -George