llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[lld] promoting bss sections to progbits may increase runtime memory usage

Open shankarke opened this issue 2 years ago • 1 comments

lld tries to promote nobits sections to progbits sections in the following test, causing a size increase.

Checking to see if this is a documented behavior or a bug with lld that we can work on for fixing it.

$ ld.lld --version LLD 18.0.0 (compatible with GNU linkers)

` cat > 1.c << ! int foo() { return 0; }

int bar() { return 0; } !

cat > script.t << ! PHDRS { A PT_LOAD; }

SECTIONS { .foo : { *(.text) *(.text.foo) } :A .b1 : { . = . + 100; } :A .b2 : { . = . + 100; } :A .bar : { *(.text.bar) } :A .b3 : { . = . + 1M;} : A .b4 : { . = . + 1M;} : A } !

clang -target riscv32 -c 1.c -ffunction-sections -fno-asynchronous-unwind-tables ld.lld 1.o -T script.t

`

The sections .b1 and .b2 should get promoted to PROGBITS, but .b3 and .b4 should be left as is as NOBITS.

This increases the size of the image.

For comparison :-

lld generates a 2.1M image bfd generated an image in kilobytes.

shankarke avatar Feb 13 '24 19:02 shankarke

@MaskRay

brad0 avatar Feb 14 '24 01:02 brad0