Usamoi
Usamoi

Reputation: 148

How can I specify a section as NOBITS in linker scripts?

My linker script is like this:

SECTIONS {
    .uninit : {
        PROVIDE(_uninit_start = .);

        PROVIDE(_stack_start = .);
        . += CONFIG_STACK_SIZE * CONSTS_HARTS_NUMBER;
        PROVIDE(_stack_end = .);

        . = ALIGN(4K);
        PROVIDE(_uninit_end = .);
    }
}

However, the output sections are like this:

  [ 7] .bss              NOBITS           0000000080357000  00158000
       0000000000034000  0000000000000000  WA       0     0     4096
  [ 8] .uninit           PROGBITS         000000008038b000  0018c000
       0000000001020000  0000000000000000  WA       0     0     1

If I use objcopy to copy the elf file to the binary file, the output size would be much larger than it should be.

Now my question is: how can I set a NOBITS flag for my custom section in the linker script?

Upvotes: 2

Views: 1362

Answers (2)

LennyB
LennyB

Reputation: 369

Just use NOLOAD linker directive.

SECTIONS {
    .uninit (NOLOAD) : {
    ...

Upvotes: 1

yugr
yugr

Reputation: 21954

You can not specify section attributes in linker scripts, only in assembly:

.section    .uninit,"wa",@nobits

Upvotes: 1

Related Questions