[PATCH] D43228: [ELF] Allow redefining LMA for a section inside a segment.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 16:59:39 PST 2018


The use case of a ROM image is a bit different. You don't have an OS, you don't have a loader, you even don't have an ELF file with ELF headers. All you have is an image, and a computer just starts execution from a predefined address. Everything else has to be done by the code in that image itself, including, in particular, initialization of R/W data by copying the corresponding block from ROM to RAM.

When you prepare a ROM image, an ELF file is only an intermediate step. Other tools extract the final image, and it is much more convenient for them if there is only one PT_LOAD segment in the ELF file, because it is closer to the final layout.

Please note, that if a linker script does not explicitly define desired segments for output sections, the generated output will still have separate PT_LOADs for each customized LMA. Nothing is changed here. The patch just allows a user to accurately specify their needs. As you may see, all the existing tests stay intact, and I merely add a new use case, which was not covered.

By the way, where does the idea of the uniform difference between VMAs, LMAs, and offsets within one segment come from? It might seem logical and natural, but I cannot find it as a requirement in the ELF specs.

Best Regards,
Igor Kudrin
C++ Developer, Access Softek, Inc.

________________________________________
From: Rafael Avila de Espindola <rafael.espindola at gmail.com>
Sent: Friday, February 23, 2018 5:50 AM
To: Igor Kudrin; reviews+D43228+public+3f65b968bcd3310a at reviews.llvm.org; ruiu at google.com
Cc: Evgeny Leviant; George Rimar; emaste at freebsd.org; llvm-commits at lists.llvm.org; arichardson.kde at gmail.com; pshung807 at gmail.com; adhemerval.zanella at linaro.org
Subject: Re: [PATCH] D43228: [ELF] Allow redefining LMA for a section inside a segment.

Igor Kudrin <ikudrin at accesssoftek.com> writes:

> Hi Rafael,
>
> GNU ld's doc has a nice example of this https://sourceware.org/binutils/docs/ld/Output-Section-LMA.html.
>
> For a ROM image, everything goes in one big chunk. There are linker script symbols which help to find where the blocks, which to be copied to the actual memory, are located.

At runtime the ELF file should be parsed based on the program
headers. The example in the manual works by creating multiple PT_LOADs,
which is fine.

The problem is when both sections should be in a single PT_LOAD:

--------------------------------
| ... | SecA | .... | SecB| ...|
--------------------------------

SecB and can be at offset from SecA, but the difference in offsets,
virtual addresses and physical addresses will all be the same.

Cheers,
Rafael


More information about the llvm-commits mailing list