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

    <tr>
        <th>Summary</th>
        <td>
            llvm-objcopy's --change-section-lma does not change the LMA for segments with a file size of 0 and mem size > 0
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            tools:llvm-objcopy/strip
      </td>
    </tr>

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

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

<pre>
    llvm-objcopy does not seem to change the LMA of sections/segments when `--change-section-lma` is specified if the segments in question have a filesize of 0 but a non-0 memsize. GNU objcopy seems to adjust the LMA for such segments.

I assume this is coming out of the check against `Seg.FileSize > 0` in [ElfObjcopy.cpp](https://github.com/llvm/llvm-project/blob/e0c7f081f1582d49f81ec4c6cdbf5d6ef13c58ba/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp#L825)--I'm still trying to understand whether this causes any functional issues in practice, but I was somewhat surprised to see the difference and in the review where this was added there was a comment (IIUC) mentioning that it might be worth modifying empty segments with addresses (https://github.com/llvm/llvm-project/pull/95431#discussion_r1654281869) so I'm not sure if this would be worth changing even if there aren't any functional issues. Any guidance here on whether this is expected or worth fixing would be greatly appreciated!

Small-ish example to hopefully demonstrate what I mean:
```
$ cat test.c
int data[100];

int main(int argc, char *argv[]) {}
$ cat script.t
PHDRS {
  text PT_LOAD;
  bss PT_LOAD;
}

SECTIONS {
  .text : { *(.text) } : text
  .bss : { *(.sbss .bss) } : bss
}
$ clang --target=riscv32-unknown-elf -c test.c
$ ld.lld -T script.t test.o

$ objcopy --change-section-lma *+0x10000 a.out gnu.shifted.a.out
$ llvm-objcopy --change-section-lma *+0x10000 a.out llvm.shifted.a.out

$ llvm-readelf -l gnu.shifted.a.out
...
  LOAD 0x00001c 0x0000001c 0x0001001c 0x00000 0x00190 RW  0x1000
...
$ llvm-readelf -l llvm.shifted.a.out
...
   LOAD           0x00101c 0x0000001c 0x0000001c 0x00000 0x00190 RW  0x1000
...
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVk1z4ygQ_TX40iUVQpYtH3xwPrybquxkajJTe5xC0JLIINACSuL99Vsgx3Zmc5jdVMqSGrrf637QwL1XnUHckuqKVDcLPoXeuu2TNTz01oxo1OuisfKw1fp5yGzzJOx4AGnRg7EBPOIAwYLouekQQo9w_8cObAseRVDWeML2HrsBTfDw0qMBsqJZNs_PjpMyPXCyoqA8-BGFahVKUG0Kd3JWBv6a0Mf50PNnBA6t0ujV3xjxKDRTAA7GmozCgEMcyOG3T9_gjXUk6yNbLp8mH05sW-vAT6I_YeWE7gjd3QH3fhpiWspHcsIOynRgpxARo7voUfwA3nFlfIipPWKX75XGx0iLlLdAU2IGSHV1q9uHmUouxpFUN4TVfQijJ-WOsD1h-06FfmpyYQfC9rHix0c2OvuEIhC2b7RtCNsjFeuW1kVbVDWTy01bFyiWYiVk01ZyhW1Riqpu-EUcFf0emqdrOx4I29_e7-ffS06svK9ZRdgmy-4IWw_gg9IagjvExIOFyUh0PnAjo5qhRzdXR_DJowduDtBOJqnKNSjvJ0zSjY6LoAQSdp2EuoMX7sHbAV96HsBPbnTKo4wYHueVJFXbokMjECKeMsnq8FnhS0R3R2ViJC5ldE7G9B3FimICYfXd3bdrwjYQv5U1KZWIqgIMqusDNAgv1oUeBitVm3LFYQyH8-p7UaGPIA59zPP_KDdOWhO231TLsiCslMqLyXtlzXdXrKolq4t6tYk0vYW5-GmHTQ7nvRAztZOWZ7ZpFyWyz2iOG8YhcIeGsHX4WI0cduYA3aQkj5VNHta8V1N5wNcRRUAJ1h3RWvUasU4cOoc86APwcXQoFA8oCSvmrfM4cK0z5XvAVz6MGqOuvR2xnbQ-gMTBGh8cDwhJ_zsYkJtYTbojK3r8pzvCliB4gIA-5ILQnTIBJA-cVFcFpXEPlVczZBwZuDKE1fGVu07ExSZ67oCwHXfd89zkYonJ-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