Closed JaciBrunning closed 3 months ago
My assumption was that all PT_LOAD segment were page aligned, but that's clearly wrong. load_align
would be better named page_size
, and the requirement for all PT_LOAD segments to use it should be changed. We'll need a new way of determining the page size for cases where PT_LOAD segments don't use it as their alignment.
It seems that the program headers you gave don't satisfy the requirement that "loadable process segments must have congruent values for p_vaddr and p_offset, modulo the page size", so I guess there are some processors for which this is not a requirement?
I don't have much experience in this area, so if I have further wrong assumptions here then please correct me.
To elaborate, the congruence requirement comes from https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-83432.html, but it does seem to be talking about something that is likely processor specific. We currently implement that requirement in Segments::add_load_segment
, and the alignment passed in there is expected to be builder.load_align
, as is done in the rewrite
crate, so whatever fix we do will need to still handle this requirement for cases where it is needed.
I think you're right in that it's processor-dependent. This is specifically for the Cortex M4F (thumbv7em-none-eabihf), as found on the STM32G4 lineup. I've got something workable for now but it breaks the rewrite
crate, so I'll have a look and see if I can fix whatever's required on the other side to make that work, too
See if #659 meets your needs.
When calling
object::build::elf::Builder::read32(...)
on an ELF file that contains different alignments in its load sections (e.g. the below), the following error is raised: "Unsupported alignments for PT_LOAD segments"From
objdump -x myelf
:I may be missing something, but I don't see a reason for this restriction, and causes the elf builder to fail to load a subset of files that are valid. In my case, this prevents us from being able to read ELF files that perform floating point trigonometric methods on a 32-bit platform with hard-float support.
The issue seems to originate in
src/build/elf.rs:146
and onwards, where the alignment of the first section with PT_LOAD is latched throughbuilder.load_align
.The alignments are stored per-segment in the lines following, so it seems odd to be storing it at the builder level when I can only find references to
builder.load_align
in therewrite
crate.Is there a reason that I'm missing for the PT_LOAD segments to be homogenous in alignment as a requirement? If not, I'm happy to open a PR to fix this issue.
Thanks!