Search code examples
cldlinker-scripts

What is the memory attribute 'p' in my linker file?


In GCC, the MEMORY command describes the location and size of blocks of memory in the target. The command must be used this way.

MEMORY 
  {
    name [(attr)] : ORIGIN = origin, LENGTH = len
    ...
  }

Now, I have a linker file used by the linker (a GCC based linker for Infineon Tricore microcontrollers, tricore-ld) defining a RAM memory section this way:

MEMORY 
  {
    ram       (w!xp): org = 0x70000000, len = 32k
    ...
  }

Could you explain what 'p' means in (w!xp)? What does 'p' mean in general?


Solution

  • Not a standard linker script, not unusual for a custom micro-controller target of course. Perhaps forked a long time ago. It however can be easily reverse-engineered, GCC has always used the ELF format for object files. Google "elf section attributes", out pops this hit, pretty helpful here.

    So you got alloc, exec, write, progbits. Aha, p == progbits. So (w!xp) surely should be interpreted as "section is writable, not executable, initial data is stored in the executable image".

    Nothing very special, that's the traditional .data section in a C program. Compare to .bss, not p.


    Info added by OP:

    From this presentation on the UNIX ELF Format:

    • PROGBITS: This holds program contents including code, data, and debugger information.

    • NOBITS: Like PROGBITS. However, it occupies no space.

    • SYMTAB and DYNSYM: These hold symbol table.

    • STRTAB: This is a string table, like the one used in a.out.

    • REL and RELA: These hold relocation information.

    • DYNAMIC and HASH: This holds information related to dynamic linking.