Search code examples
linkerld

size of a input section GNU ld


How do you get the size of an input section in ld? I would assume its just SIZEOF(.section); however ld gives an error upon trying to run that. Is there any way I can do this? .section would be defined in a .asm file like so

section .section
    mov al, 15

Here's the linker script I have so far:

SECTIONS {
    boot : {
        *( .boot );
        . += SECTOR_SIZE - SIZEOF( .boot_header );
        *( .boot_header );
    }
}

Solution

  • I have no problem with SIZEOF.

    Just tested:

      .data : 
      {
        . = ALIGN(4);
        _sdata = .;        /* create a global symbol at data start */
        *(.data)           /* .data sections */
        *(.data*)          /* .data* sections */
    
        . = ALIGN(4);
        _edata = .;        /* define a global symbol at data end */
      } >RAM AT> FLASH
      
        _datasize = SIZEOF(.data); 
    

    Works as expected.