Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.
This repository was archived by the owner on Nov 28, 2023. It is now read-only.

ELF output contains lots of zero data: linker script issue? #60

Closed
@laanwj

Description

@laanwj

It could be that something is going wrong with the linker script. A binary of a small example is almost 7 MB in size:

-rwxrwxr-x 2 user user 6.7M Jun  2 18:13 target/riscv64gc-unknown-none-elf/release/interrupt

Using size, this seems to be allocated to data sections:

$ size target/riscv64gc-unknown-none-elf/release/interrupt
   text    data     bss     dec     hex filename
  38522 6176916   73732 6289170  5ff712 target/riscv64gc-unknown-none-elf/release/interrupt

Digigng further:

$ riscv64-unknown-elf-objdump -x target/riscv64gc-unknown-none-elf/release/interrupt
  4 .bss          00012004  000000008000a000  000000008000a000  0000abf8  2**12
                  ALLOC
  5 .heap         00000000  000000008001c004  000000008001c004  0000abf8  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  6 .stack        005e3ffc  000000008001c004  000000008001c004  0000abf8  2**0
                  CONTENTS, ALLOC, LOAD, DATA

It seems the stack section is in the binary, padded fully with zeros:

riscv64-unknown-elf-objdump --section=.stack -s target/riscv64gc-unknown-none-elf/release/interrupt
Contents of section .stack:
 8001c004 00000000 00000000 00000000 00000000  ................
…
 805ffff4 00000000 00000000 00000000           ............    

I'm not sure why this is not treated like the .bss section, implicitly implied to be filled with zeros (the section is correctly labeled NOLOAD, but are not generated with ELF section type SHT_NOBITS).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions