Skip to content

Commit

Permalink
Fix alignment bug in patchelf-0.18.0 by patch
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelToman committed Oct 16, 2024
1 parent 7f1f0e6 commit 40d2488
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ toolchain = {'name': 'GCCcore', 'version': '12.3.0'}

source_urls = ['https://github.com/NixOS/patchelf/archive/']
sources = ['%(version)s.tar.gz']
checksums = ['1451d01ee3a21100340aed867d0b799f46f0b1749680028d38c3f5d0128fb8a7']
patches = ['patchelf-0.18.0_fix-alignment.patch']
checksums = [
{'0.18.0.tar.gz': '1451d01ee3a21100340aed867d0b799f46f0b1749680028d38c3f5d0128fb8a7'},
{'patchelf-0.18.0_fix-alignment.patch': '87936627643b2212e8261b0f3d5905f12d0fc91f73503e12124f93ff972e0a03'},
]

builddependencies = [
('binutils', '2.40'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Author - Pavel Tománek
Fix alignment problem when rewriting sections
https://github.com/NixOS/patchelf/pull/566
--- src/patchelf.cc.orig 2024-10-07 16:45:17.515584318 +0200
+++ src/patchelf.cc 2024-10-07 16:47:14.622270000 +0200
@@ -843,7 +843,7 @@
neededSpace += headerTableSpace;
debug("needed space is %d\n", neededSpace);

- Elf_Off startOffset = roundUp(fileContents->size(), getPageSize());
+ Elf_Off startOffset = roundUp(fileContents->size(), alignStartPage);

// In older version of binutils (2.30), readelf would check if the dynamic
// section segment is strictly smaller than the file (and not same size).
@@ -879,7 +879,7 @@
rdi(lastSeg.p_type) == PT_LOAD &&
rdi(lastSeg.p_flags) == (PF_R | PF_W) &&
rdi(lastSeg.p_align) == alignStartPage) {
- auto segEnd = roundUp(rdi(lastSeg.p_offset) + rdi(lastSeg.p_memsz), getPageSize());
+ auto segEnd = roundUp(rdi(lastSeg.p_offset) + rdi(lastSeg.p_memsz), alignStartPage);
if (segEnd == startOffset) {
auto newSz = startOffset + neededSpace - rdi(lastSeg.p_offset);
wri(lastSeg.p_filesz, wri(lastSeg.p_memsz, newSz));
@@ -898,6 +898,7 @@
wri(phdr.p_filesz, wri(phdr.p_memsz, neededSpace));
wri(phdr.p_flags, PF_R | PF_W);
wri(phdr.p_align, alignStartPage);
+ assert(startPage % alignStartPage == startOffset % alignStartPage);
}

normalizeNoteSegments();

0 comments on commit 40d2488

Please sign in to comment.