patchelf
patchelf copied to clipboard
Compute program header flags in rewriteSectionsLibrary
Instead of using fixed flags of RW for the new program header, holding the replaced sections, check if the write or execute flags is required by any accompanying section.
If many sections are going to be replaced a more strict method would be to split them up and add up-to 4 new program headers if necessary: read-only, read-write, read-execute, read-write-execute.
p.s.:
also the harded flags for executables seems suspicious:
https://github.com/NixOS/patchelf/blob/e37f892b12ff900ab5e733f688548c87cd14ef02/src/patchelf.cc#L562
Maybe that should be wri(phdr.p_flags, rdi(phdrs.at(splitIndex).p_flags));?
p.p.s: Should these lines convert the read data https://github.com/NixOS/patchelf/blob/e37f892b12ff900ab5e733f688548c87cd14ef02/src/patchelf.cc#L558-L560 e.g.
wri(phdr.p_offset, rdi(phdrs.at(splitIndex).p_offset) - splitShift - shift);
wri(phdr.p_paddr, rdi(phdrs.at(splitIndex).p_paddr) - splitShift - shift);
wri(phdr.p_vaddr, rdi(phdrs.at(splitIndex).p_vaddr) - splitShift - shift);
?
cc @brenoguim
also the harded flags for executables seems suspicious:
Since these flags are not being tracked, RW is the "works for all". I don't think we ever move executable sessions (because they are usually progbits) so we never needed.
Should these lines convert the read data
I think so. I would expect things to break drastically if endianess is not respected. Do you know if we have tests for that?