[PATCH] D111871: [ELF] Let sections reach the end of the address space

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 5 02:52:17 PDT 2021


jhenderson added a comment.

In D111871#3109228 <https://reviews.llvm.org/D111871#3109228>, @hvenev wrote:

> In D111871#3108247 <https://reviews.llvm.org/D111871#3108247>, @jhenderson wrote:
>
>> In D111871#3107393 <https://reviews.llvm.org/D111871#3107393>, @hvenev wrote:
>>
>>> There already are test cases for overflowing by 1 byte. These two tests are more or less copies of those, except that we exactly reach the end.
>>>
>>> Regarding the empty section thing, that's a problem with setting the base address rather than the size. It is something that the linker script interpreter does not handle well, especially in the 64-bit case.
>>
>> I'm not sure that it is? You can have an empty section immediately following a non-empty section after all, so you'd just need a non-empty section that ends at the end of the address space, followed by an empty section.
>
> The current linker script logic does no overflow checking. Instead, it always truncates addresses to 64 bits. This means that e.g. a section that starts at the end of the 64-bit address space is actually moved to address 0. I think this is a bug.
>
> An empty section at the end of the address space has an invalid base address no matter the section size. Ideally such addresses should not be produced by the linker script interpreter, so in such a test case we should not even reach Writer<ELFT>::checkSections.
>
> If I add tests with empty sections at the end of the address space, should I have the 64-bit case expect an error and add XFAIL?

I think we may be misunderstanding each other. By "base address" I thought you meant the initial linker script address, but you mean the section start address.

I realised I was being silly, as there's no way to represent a section with an address at the end of the address space (what would its sh_addr be?). What I actually originally meant was an empty section with `address == max(Elf_Addr)`, i.e. 0xffffffff on 32-bit and 0xffffffffffffffff on 64-bit, because of the new `os->size` check in the Writer.cpp changes (line 2787 in the current version of the diff). An empty section is needed to exercise that change (and show it's not accidentally treated as a section of size `max(size)`. Please add that test case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111871/new/

https://reviews.llvm.org/D111871



More information about the llvm-commits mailing list