summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/patchelf
diff options
context:
space:
mode:
authorAlex Kiernan <alex.kiernan@gmail.com>2019-05-05 06:22:44 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-05-08 12:15:17 +0100
commit27c497562938d141844e0676227c47241d2af136 (patch)
tree62665e423af5cd1a7f816cc859bb60614c5f49f7 /meta/recipes-devtools/patchelf
parent6c1ddb540944f43784af929d02eb56d7efc350fb (diff)
downloadpoky-27c497562938d141844e0676227c47241d2af136.tar.gz
patchelf: Upgrade 0.9 -> 0.10
Drop patches merged (or redone differently) upstream (From OE-Core rev: e81004fd334a8204852f271101ddcf4a39e9ccb5) Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/patchelf')
-rw-r--r--meta/recipes-devtools/patchelf/patchelf/Increase-maxSize-to-64MB.patch46
-rw-r--r--meta/recipes-devtools/patchelf/patchelf/Skip-empty-section-fixes-66.patch30
-rw-r--r--meta/recipes-devtools/patchelf/patchelf/avoidholes.patch163
-rw-r--r--meta/recipes-devtools/patchelf/patchelf/fix-adjusting-startPage.patch15
-rw-r--r--meta/recipes-devtools/patchelf/patchelf/handle-read-only-files.patch17
-rw-r--r--meta/recipes-devtools/patchelf/patchelf_0.10.bb (renamed from meta/recipes-devtools/patchelf/patchelf_0.9.bb)9
6 files changed, 21 insertions, 259 deletions
diff --git a/meta/recipes-devtools/patchelf/patchelf/Increase-maxSize-to-64MB.patch b/meta/recipes-devtools/patchelf/patchelf/Increase-maxSize-to-64MB.patch
deleted file mode 100644
index 49050a18d2..0000000000
--- a/meta/recipes-devtools/patchelf/patchelf/Increase-maxSize-to-64MB.patch
+++ /dev/null
@@ -1,46 +0,0 @@
1From e3658740ec100e4c8cf83295460b032979e1a99a Mon Sep 17 00:00:00 2001
2From: Fabio Berton <fabio.berton@ossystems.com.br>
3Date: Fri, 9 Sep 2016 18:21:32 -0300
4Subject: [PATCH] Increase maxSize to 64MB
5Organization: O.S. Systems Software LTDA.
6
7Fix error:
8
9/
10|ERROR: qemu-native-2.5.0-r1 do_populate_sysroot_setscene: '('patchelf-uninative',
11|'--set-interpreter', '../build/tmp/sysroots-uninative/x86_64-linux/lib/
12|ld-linux-x86-64.so.2', '../build/tmp/work/x86_64-linux/qemu-native/2.5.0-r1/
13|sstate-install-populate_sysroot/x86_64-linux/usr/bin/qemu-mips64')'
14|failed with exit code 1 and the following output:
15|warning: working around a Linux kernel bug by creating a hole of 36032512
16|bytes in ā€˜../build/tmp/work/x86_64-linux/qemu-native/2.5.0-r1/
17|sstate-install-populate_sysroot/x86_64-linux/usr/bin/qemu-mips64ā€™
18|maximum file size exceeded
19\
20
21Similar issue is discussed here:
22https://github.com/NixOS/patchelf/issues/47
23
24Upstream-Status: Inappropriate [embedded specific]
25
26Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br>
27---
28 src/patchelf.cc | 2 +-
29 1 file changed, 1 insertion(+), 1 deletion(-)
30
31diff --git a/src/patchelf.cc b/src/patchelf.cc
32index a59c12d..0fd7355 100644
33--- a/src/patchelf.cc
34+++ b/src/patchelf.cc
35@@ -279,7 +279,7 @@ static void readFile(string fileName)
36 struct stat st;
37 if (stat(fileName.c_str(), &st) != 0) error("stat");
38 fileSize = st.st_size;
39- maxSize = fileSize + 32 * 1024 * 1024;
40+ maxSize = fileSize + 64 * 1024 * 1024;
41
42 contents = (unsigned char *) malloc(fileSize + maxSize);
43 if (!contents) abort();
44--
452.1.4
46
diff --git a/meta/recipes-devtools/patchelf/patchelf/Skip-empty-section-fixes-66.patch b/meta/recipes-devtools/patchelf/patchelf/Skip-empty-section-fixes-66.patch
deleted file mode 100644
index 9ee8a554a7..0000000000
--- a/meta/recipes-devtools/patchelf/patchelf/Skip-empty-section-fixes-66.patch
+++ /dev/null
@@ -1,30 +0,0 @@
1From 73526cb546ae6b00ea6169e40b01fb7b5f0dbb50 Mon Sep 17 00:00:00 2001
2From: Fabio Berton <fabio.berton@ossystems.com.br>
3Date: Thu, 28 Jul 2016 11:05:06 -0300
4Subject: [PATCH] Skip empty section (fixes #66)
5Organization: O.S. Systems Software LTDA.
6
7Upstream-Status: Pending
8
9Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br>
10---
11 src/patchelf.cc | 3 +++
12 1 file changed, 3 insertions(+)
13
14diff --git a/src/patchelf.cc b/src/patchelf.cc
15index 136098f..2677a26 100644
16--- a/src/patchelf.cc
17+++ b/src/patchelf.cc
18@@ -684,6 +684,9 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
19 for (unsigned int i = 1; i <= lastReplaced; ++i) {
20 Elf_Shdr & shdr(shdrs[i]);
21 string sectionName = getSectionName(shdr);
22+ if (sectionName == "") {
23+ continue;
24+ }
25 debug("looking at section `%s'\n", sectionName.c_str());
26 /* !!! Why do we stop after a .dynstr section? I can't
27 remember! */
28--
292.1.4
30
diff --git a/meta/recipes-devtools/patchelf/patchelf/avoidholes.patch b/meta/recipes-devtools/patchelf/patchelf/avoidholes.patch
deleted file mode 100644
index 0b45c39bda..0000000000
--- a/meta/recipes-devtools/patchelf/patchelf/avoidholes.patch
+++ /dev/null
@@ -1,163 +0,0 @@
1Different types of binaries create challenges for patchelf. In order to extend
2sections they need to be moved within the binary. The current approach to
3handling ET_DYN binaries is to move the INTERP section to the end of the file.
4This means changing PT_PHDR to add an extra PT_LOAD section so that the new section
5is mmaped into memory by the elf loader in the kernel. In order to extend PHDR,
6this means moving it to the end of the file.
7
8Its documented in patchelf there is a kernel 'bug' which means that if you have holes
9in memory between the base load address and the PT_LOAD segment that contains PHDR,
10it will pass an incorrect PHDR address to ld.so and fail to load the binary, segfaulting.
11
12To avoid this, the code currently inserts space into the binary to ensure that when
13loaded into memory there are no holes between the PT_LOAD sections. This inflates the
14binaries by many MBs in some cases. Whilst we could make them sparse, there is a second
15issue which is that strip can fail to process these binaries:
16
17$ strip fixincl
18Not enough room for program headers, try linking with -N
19[.note.ABI-tag]: Bad value
20
21This turns out to be due to libbfd not liking the relocated PHDR section either
22(https://github.com/NixOS/patchelf/issues/10).
23
24Instead this patch implements a different approach, leaving PHDR where it is but extending
25it in place to allow addition of a new PT_LOAD section. This overwrites sections in the
26binary but those get moved to the end of the file in the new PT_LOAD section.
27
28This is based on patches linked from the above github issue, however whilst the idea
29was good, the implementation wasn't correct and they've been rewritten here.
30
31RP
322017/3/7
33
34Upstream-Status: Accepted
35
36Index: patchelf-0.9/src/patchelf.cc
37===================================================================
38--- patchelf-0.9.orig/src/patchelf.cc
39+++ patchelf-0.9/src/patchelf.cc
40@@ -146,6 +146,8 @@ private:
41 string & replaceSection(const SectionName & sectionName,
42 unsigned int size);
43
44+ bool haveReplacedSection(const SectionName & sectionName);
45+
46 void writeReplacedSections(Elf_Off & curOff,
47 Elf_Addr startAddr, Elf_Off startOffset);
48
49@@ -497,6 +499,16 @@ unsigned int ElfFile<ElfFileParamNames>:
50 return 0;
51 }
52
53+template<ElfFileParams>
54+bool ElfFile<ElfFileParamNames>::haveReplacedSection(const SectionName & sectionName)
55+{
56+ ReplacedSections::iterator i = replacedSections.find(sectionName);
57+
58+ if (i != replacedSections.end())
59+ return true;
60+ return false;
61+}
62+
63
64 template<ElfFileParams>
65 string & ElfFile<ElfFileParamNames>::replaceSection(const SectionName & sectionName,
66@@ -595,52 +607,52 @@ void ElfFile<ElfFileParamNames>::rewrite
67
68 debug("last page is 0x%llx\n", (unsigned long long) startPage);
69
70+ /* Because we're adding a new section header, we're necessarily increasing
71+ the size of the program header table. This can cause the first section
72+ to overlap the program header table in memory; we need to shift the first
73+ few segments to someplace else. */
74+ /* Some sections may already be replaced so account for that */
75+ unsigned int i = 1;
76+ Elf_Addr pht_size = sizeof(Elf_Ehdr) + (phdrs.size() + 1)*sizeof(Elf_Phdr);
77+ while( shdrs[i].sh_addr <= pht_size && i < rdi(hdr->e_shnum) ) {
78+ if (not haveReplacedSection(getSectionName(shdrs[i])))
79+ replaceSection(getSectionName(shdrs[i]), shdrs[i].sh_size);
80+ i++;
81+ }
82
83- /* Compute the total space needed for the replaced sections and
84- the program headers. */
85- off_t neededSpace = (phdrs.size() + 1) * sizeof(Elf_Phdr);
86+ /* Compute the total space needed for the replaced sections */
87+ off_t neededSpace = 0;
88 for (ReplacedSections::iterator i = replacedSections.begin();
89 i != replacedSections.end(); ++i)
90 neededSpace += roundUp(i->second.size(), sectionAlignment);
91 debug("needed space is %d\n", neededSpace);
92
93-
94 size_t startOffset = roundUp(fileSize, getPageSize());
95
96 growFile(startOffset + neededSpace);
97
98-
99 /* Even though this file is of type ET_DYN, it could actually be
100 an executable. For instance, Gold produces executables marked
101- ET_DYN. In that case we can still hit the kernel bug that
102- necessitated rewriteSectionsExecutable(). However, such
103- executables also tend to start at virtual address 0, so
104+ ET_DYN as does LD when linking with pie. If we move PT_PHDR, it
105+ has to stay in the first PT_LOAD segment or any subsequent ones
106+ if they're continuous in memory due to linux kernel constraints
107+ (see BUGS). Since the end of the file would be after bss, we can't
108+ move PHDR there, we therefore choose to leave PT_PHDR where it is but
109+ move enough following sections such that we can add the extra PT_LOAD
110+ section to it. This PT_LOAD segment ensures the sections at the end of
111+ the file are mapped into memory for ld.so to process.
112+ We can't use the approach in rewriteSectionsExecutable()
113+ since DYN executables tend to start at virtual address 0, so
114 rewriteSectionsExecutable() won't work because it doesn't have
115- any virtual address space to grow downwards into. As a
116- workaround, make sure that the virtual address of our new
117- PT_LOAD segment relative to the first PT_LOAD segment is equal
118- to its offset; otherwise we hit the kernel bug. This may
119- require creating a hole in the executable. The bigger the size
120- of the uninitialised data segment, the bigger the hole. */
121+ any virtual address space to grow downwards into. */
122 if (isExecutable) {
123 if (startOffset >= startPage) {
124 debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage);
125- } else {
126- size_t hole = startPage - startOffset;
127- /* Print a warning, because the hole could be very big. */
128- fprintf(stderr, "warning: working around a Linux kernel bug by creating a hole of %zu bytes in ā€˜%sā€™\n", hole, fileName.c_str());
129- assert(hole % getPageSize() == 0);
130- /* !!! We could create an actual hole in the file here,
131- but it's probably not worth the effort. */
132- growFile(fileSize + hole);
133- startOffset += hole;
134 }
135 startPage = startOffset;
136 }
137
138-
139- /* Add a segment that maps the replaced sections and program
140- headers into memory. */
141+ /* Add a segment that maps the replaced sections into memory. */
142 phdrs.resize(rdi(hdr->e_phnum) + 1);
143 wri(hdr->e_phnum, rdi(hdr->e_phnum) + 1);
144 Elf_Phdr & phdr = phdrs[rdi(hdr->e_phnum) - 1];
145@@ -653,15 +665,12 @@ void ElfFile<ElfFileParamNames>::rewrite
146
147
148 /* Write out the replaced sections. */
149- Elf_Off curOff = startOffset + phdrs.size() * sizeof(Elf_Phdr);
150+ Elf_Off curOff = startOffset;
151 writeReplacedSections(curOff, startPage, startOffset);
152 assert(curOff == startOffset + neededSpace);
153
154-
155- /* Move the program header to the start of the new area. */
156- wri(hdr->e_phoff, startOffset);
157-
158- rewriteHeaders(startPage);
159+ /* Write out the updated program and section headers */
160+ rewriteHeaders(hdr->e_phoff);
161 }
162
163
diff --git a/meta/recipes-devtools/patchelf/patchelf/fix-adjusting-startPage.patch b/meta/recipes-devtools/patchelf/patchelf/fix-adjusting-startPage.patch
index f64cbed5cb..a0988423fe 100644
--- a/meta/recipes-devtools/patchelf/patchelf/fix-adjusting-startPage.patch
+++ b/meta/recipes-devtools/patchelf/patchelf/fix-adjusting-startPage.patch
@@ -1,6 +1,9 @@
1From 1630d3f846c7721b1e7cd3b005bb2b34816e1d0f Mon Sep 17 00:00:00 2001
2From: Ed Bartosh <ed.bartosh@linux.intel.com>
3Date: Fri, 21 Jul 2017 12:33:53 +0300
4Subject: [PATCH] patchelf: fix segfault for binaries linked by gold
5
1commit 1cc234fea5600190d872329aca60e2365cefc39e 6commit 1cc234fea5600190d872329aca60e2365cefc39e
2Author: Ed Bartosh <ed.bartosh@linux.intel.com>
3Date: Fri Jul 21 12:33:53 2017 +0300
4 7
5fix adjusting startPage 8fix adjusting startPage
6 9
@@ -19,11 +22,15 @@ Github PR: https://github.com/NixOS/patchelf/pull/127
19 22
20Upstream-Status: Submitted 23Upstream-Status: Submitted
21 24
25---
26 src/patchelf.cc | 6 ++----
27 1 file changed, 2 insertions(+), 4 deletions(-)
28
22diff --git a/src/patchelf.cc b/src/patchelf.cc 29diff --git a/src/patchelf.cc b/src/patchelf.cc
23index cbd36c0..e9d7ea5 100644 30index a63e3a11c61f..2483d25d78f1 100644
24--- a/src/patchelf.cc 31--- a/src/patchelf.cc
25+++ b/src/patchelf.cc 32+++ b/src/patchelf.cc
26@@ -720,10 +720,8 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary() 33@@ -756,10 +756,8 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
27 since DYN executables tend to start at virtual address 0, so 34 since DYN executables tend to start at virtual address 0, so
28 rewriteSectionsExecutable() won't work because it doesn't have 35 rewriteSectionsExecutable() won't work because it doesn't have
29 any virtual address space to grow downwards into. */ 36 any virtual address space to grow downwards into. */
diff --git a/meta/recipes-devtools/patchelf/patchelf/handle-read-only-files.patch b/meta/recipes-devtools/patchelf/patchelf/handle-read-only-files.patch
index 9fafec4b59..03b0d18a89 100644
--- a/meta/recipes-devtools/patchelf/patchelf/handle-read-only-files.patch
+++ b/meta/recipes-devtools/patchelf/patchelf/handle-read-only-files.patch
@@ -1,26 +1,26 @@
1From 2a603acb65993698c21f1c6eb7664f93ad830d52 Mon Sep 17 00:00:00 2001 1From 7f1fd10cfebd5ea2f3e1938abe1bd1c4828164a7 Mon Sep 17 00:00:00 2001
2From: Fabio Berton <fabio.berton@ossystems.com.br> 2From: Fabio Berton <fabio.berton@ossystems.com.br>
3Date: Fri, 9 Sep 2016 16:00:42 -0300 3Date: Fri, 9 Sep 2016 16:00:42 -0300
4Subject: [PATCH] handle read-only files 4Subject: [PATCH] handle read-only files
5Organization: O.S. Systems Software LTDA.
6 5
7Patch from: 6Patch from:
8https://github.com/darealshinji/patchelf/commit/40e66392bc4b96e9b4eda496827d26348a503509 7https://github.com/darealshinji/patchelf/commit/40e66392bc4b96e9b4eda496827d26348a503509
9 8
10Upstream-Status: Pending 9Upstream-Status: Denied [https://github.com/NixOS/patchelf/pull/89]
11 10
12Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br> 11Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br>
12
13--- 13---
14 src/patchelf.cc | 16 +++++++++++++++- 14 src/patchelf.cc | 16 +++++++++++++++-
15 1 file changed, 15 insertions(+), 1 deletion(-) 15 1 file changed, 15 insertions(+), 1 deletion(-)
16 16
17diff --git a/src/patchelf.cc b/src/patchelf.cc 17diff --git a/src/patchelf.cc b/src/patchelf.cc
18index 136098f..aea360e 100644 18index 0b4965adff83..b5db2aef0e8a 100644
19--- a/src/patchelf.cc 19--- a/src/patchelf.cc
20+++ b/src/patchelf.cc 20+++ b/src/patchelf.cc
21@@ -388,7 +388,17 @@ void ElfFile<ElfFileParamNames>::sortShdrs() 21@@ -497,7 +497,17 @@ void ElfFile<ElfFileParamNames>::sortShdrs()
22 22
23 static void writeFile(string fileName) 23 static void writeFile(std::string fileName, FileContents contents)
24 { 24 {
25- int fd = open(fileName.c_str(), O_TRUNC | O_WRONLY); 25- int fd = open(fileName.c_str(), O_TRUNC | O_WRONLY);
26+ struct stat st; 26+ struct stat st;
@@ -37,7 +37,7 @@ index 136098f..aea360e 100644
37 if (fd == -1) 37 if (fd == -1)
38 error("open"); 38 error("open");
39 39
40@@ -397,6 +407,10 @@ static void writeFile(string fileName) 40@@ -511,6 +521,10 @@ static void writeFile(std::string fileName, FileContents contents)
41 41
42 if (close(fd) != 0) 42 if (close(fd) != 0)
43 error("close"); 43 error("close");
@@ -48,6 +48,3 @@ index 136098f..aea360e 100644
48 } 48 }
49 49
50 50
51--
522.1.4
53
diff --git a/meta/recipes-devtools/patchelf/patchelf_0.9.bb b/meta/recipes-devtools/patchelf/patchelf_0.10.bb
index d70303963c..580108e8b8 100644
--- a/meta/recipes-devtools/patchelf/patchelf_0.9.bb
+++ b/meta/recipes-devtools/patchelf/patchelf_0.10.bb
@@ -1,16 +1,13 @@
1SRC_URI = "http://nixos.org/releases/${BPN}/${BPN}-${PV}/${BPN}-${PV}.tar.bz2 \ 1SRC_URI = "http://nixos.org/releases/${BPN}/${BPN}-${PV}/${BPN}-${PV}.tar.bz2 \
2 file://Skip-empty-section-fixes-66.patch \
3 file://handle-read-only-files.patch \ 2 file://handle-read-only-files.patch \
4 file://Increase-maxSize-to-64MB.patch \
5 file://avoidholes.patch \
6 file://fix-adjusting-startPage.patch \ 3 file://fix-adjusting-startPage.patch \
7" 4 "
8 5
9LICENSE = "GPLv3" 6LICENSE = "GPLv3"
10SUMMARY = "Tool to allow editing of RPATH and interpreter fields in ELF binaries" 7SUMMARY = "Tool to allow editing of RPATH and interpreter fields in ELF binaries"
11 8
12SRC_URI[md5sum] = "d02687629c7e1698a486a93a0d607947" 9SRC_URI[md5sum] = "6c3f3a06a95705870d129494a6880106"
13SRC_URI[sha256sum] = "a0f65c1ba148890e9f2f7823f4bedf7ecad5417772f64f994004f59a39014f83" 10SRC_URI[sha256sum] = "f670cd462ac7161588c28f45349bc20fb9bd842805e3f71387a320e7a9ddfcf3"
14 11
15LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504" 12LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
16 13