summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2021-05-01 17:10:21 +0100
committerAnuj Mittal <anuj.mittal@intel.com>2021-05-06 10:09:37 +0800
commit8a051bf055623f1ef5ca94d9291162ac7ce871c6 (patch)
tree60e80db8a6ee16a48cbf62bc9f7d4dd957882528
parente24510fbb1439d56a278e2b5fc036d11a24e23df (diff)
downloadopenembedded-core-8a051bf055623f1ef5ca94d9291162ac7ce871c6.tar.gz
patchelf: Fix note section alignment issues
Improve note section normalization was added to patchelf in recent versions however if fails if there are two note sections which aren't sized to match section alignment. Tweak the code to account for section alignment. This fixes patchelf failures on the autobuilder, particularly to ccache-native. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit fee8dde0d597b511b37d8dcf215e8355980d5f2b) Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
-rw-r--r--meta/recipes-devtools/patchelf/patchelf/alignmentfix.patch42
-rw-r--r--meta/recipes-devtools/patchelf/patchelf_0.12.bb1
2 files changed, 43 insertions, 0 deletions
diff --git a/meta/recipes-devtools/patchelf/patchelf/alignmentfix.patch b/meta/recipes-devtools/patchelf/patchelf/alignmentfix.patch
new file mode 100644
index 0000000000..62e11a5e7f
--- /dev/null
+++ b/meta/recipes-devtools/patchelf/patchelf/alignmentfix.patch
@@ -0,0 +1,42 @@
+If a binary has multiple SHT_NOTE sections and corresponding PT_NOTE
+headers, we can see the error:
+
+patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections
+
+if the SHT_NOTE sections aren't sized to end on aligned boundaries. An example
+would be a binary with:
+
+ [ 2] .note.ABI-tag NOTE 00000000000002f4 000002f4
+ 0000000000000020 0000000000000000 A 0 0 4
+ [ 3] .note.gnu.propert NOTE 0000000000000318 00000318
+ 0000000000000030 0000000000000000 A 0 0 8
+ [ 4] .note.gnu.build-i NOTE 0000000000000348 00000348
+ 0000000000000024 0000000000000000 A 0 0 4
+
+ NOTE 0x0000000000000318 0x0000000000000318 0x0000000000000318
+ 0x0000000000000030 0x0000000000000030 R 0x8
+ NOTE 0x00000000000002f4 0x00000000000002f4 0x00000000000002f4
+ 0x0000000000000078 0x0000000000000074 R 0x4
+
+since the PT_NOTE section at 2f4 covers [2] and [3] but the code
+calclates curr_off should be 314, not the 318 in the binary. This
+is an alignment issue.
+
+To fix this, we need to round curr_off to the next section alignment.
+
+Upstream-Status: Submitted [https://github.com/NixOS/patchelf/pull/274]
+Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
+
+Index: git/src/patchelf.cc
+===================================================================
+--- git.orig/src/patchelf.cc
++++ git/src/patchelf.cc
+@@ -1035,6 +1035,8 @@ void ElfFile<ElfFileParamNames>::normali
+ phdrs.push_back(new_phdr);
+
+ curr_off += size;
++ /* The next section offset would be aligned */
++ curr_off = roundUp(curr_off, sectionAlignment);
+ }
+ }
+ wri(hdr->e_phnum, phdrs.size());
diff --git a/meta/recipes-devtools/patchelf/patchelf_0.12.bb b/meta/recipes-devtools/patchelf/patchelf_0.12.bb
index 2eb09aee32..7c97ea0789 100644
--- a/meta/recipes-devtools/patchelf/patchelf_0.12.bb
+++ b/meta/recipes-devtools/patchelf/patchelf_0.12.bb
@@ -7,6 +7,7 @@ LICENSE = "GPLv3"
SRC_URI = "git://github.com/NixOS/patchelf;protocol=https \
file://handle-read-only-files.patch \
file://6edec83653ce1b5fc201ff6db93b966394766814.patch \
+ file://alignmentfix.patch \
"
SRCREV = "8d3a16e97294e3c5521c61b4c8835499c9918264"