Skip to content

empty segment created when the image has only tbss #353

@quic-seaswara

Description

@quic-seaswara

An empty segment is created when the image has only tbss.

Test


cat > 1.c << \!
__thread int b = 0;
int data = 100;
int foo() { return 0; }
int main() { return 0; }
!

cat > script.t << \!
MEMORY
{
  RAM (rw) : ORIGIN = 10000, LENGTH = 5000
}

SECTIONS {
 .foo : { *(.text.foo) } > RAM
 .empty : {} > RAM
 tbss : { *(.tbss*) } > RAM
 .empty : {} > RAM
 .main : { *(.text.main) } > RAM
 output_data : { BYTE(0x0) *(.data*) } > RAM
 /DISCARD/ : { *(.riscv.attributes) }
}
!

clang -c -target riscv32 -c  1.c -ffunction-sections -fdata-sections
ld.eld 1.o -T script.t
llvm-readelf -l -W a.out

Bug

$ llvm-readelf -l -W a.out

Elf file type is EXEC (Executable file)
Entry point 0x0
There are 5 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000710 0x00002710 0x00002710 0x00012 0x00012 R E 0x1000
  LOAD           0x000724 0x00002724 0x00002724 0x00000 0x00000 RW  0x1000
  LOAD           0x000724 0x00002724 0x00002724 0x00016 0x00016 R E 0x1000
  LOAD           0x00073c 0x0000273c 0x0000273c 0x00008 0x00008 RW  0x1000
  TLS            0x000724 0x00002724 0x00002724 0x00000 0x00004 R   0x4

 Section to Segment mapping:
  Segment Sections...
   00     .foo
   01
   02     .main
   03     output_data
   04     tbss
   None   .comment .shstrtab .symtab .strtab

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions