[llvm] [llvm-objcopy] Support SREC output format (PR #75874)

Simon Tatham via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 9 03:55:22 PST 2024


================
@@ -324,6 +324,14 @@ Expected<IHexRecord> IHexRecord::parse(StringRef Line) {
   return Rec;
 }
 
+static uint64_t sectionLMA(const SectionBase *Sec) {
----------------
statham-arm wrote:

OK, so in this example ELF file, there are _three_ address layouts. (`llvm-readelf` or GNU `readelf` are better for showing this than `objdump`.)

Going by the addresses in the section header table, this image is highly non-contiguous, with `.text` going at 0, some data around 0x10000, some more data just below 0x200000 and more still just below 0x300000. Each section is only a few bytes long, and the gaps between them are many Kb or even Mb.

But then those sections are packed into a single `PT_LOAD` segment much more tightly, so that the only gaps between them are a few bytes for alignment. That segment has two different addresses: a virtual address (`p_vaddr`) of 0xF00000000, and a physical address (`p_paddr`) of 0x100000.

GNU objcopy, in both `ihex` and `srec` output mode, is using the layout from the section addresses, so that it emits records with addresses near 0, near 0x10000, near 0x200000 and near 0x300000.

`llvm-objcopy -O ihex` is using the layout from the segment's physical address, so that everything it emits is tightly packed near 0x100000.

`llvm-objcopy -O srec` with your patch is using the section addresses again, so that LLVM's two hex formats produce different addresses.

(And nothing is using the _virtual_ address of the segment, which is just as well, because it's greater than 2^32, and wouldn't fit into these 32-bit hex file formats in any case.)

I can see that you might want to be able to generate hex output based on the section addresses. But I think that the choice of addressing scheme should not depend on which hex format you're outputting. The two hex formats are used for similar purposes; there's no reason why one should be right for `srec` and the other one for `ihex`.

So I'd prefer that we use the same section-address function for both hex formats, and separately, introduce an option to control how that function decides on addresses.

https://github.com/llvm/llvm-project/pull/75874


More information about the llvm-commits mailing list