<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/81657>81657</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [lld] promoting bss sections to progbits may increase runtime memory usage
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          shankarke
      </td>
    </tr>
</table>

<pre>
    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.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE1z4ygQ_TX40iVKQlYsH3RwrPHsVGWS1MR73gLUklgjcAGKx_vrt5CcD-8kW7sXbNHvdT8a-nHvVWcQK1LckqJe8DH01lW-5-bA3QEXwjbnSusGglPoIVg4OjvYgGCsUMGDRxmUNS-h7npTGQg9Qmu1tidlOgjoA2FbkHz08ZuDV38hKCMdco-UpDVJN_O67VEeJpIFjwiqhdArD8oDh8bKcUATsAGBPX9W1oF1wEGMHZxU6GFS3fMAJwTJDZysO4A10FoHrfoZE6twVZCwJeiGR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