Gentoo Archives: gentoo-commits

From: Sergei Trofimovich <slyfox@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-boot/gnu-efi/files/, sys-boot/gnu-efi/
Date: Sun, 28 Jan 2018 22:59:50
Message-Id: 1517180321.c62fc5c0068b7cf27a79700cf9f0e7f20a625641.slyfox@gentoo
1 commit: c62fc5c0068b7cf27a79700cf9f0e7f20a625641
2 Author: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
3 AuthorDate: Sun Jan 28 22:54:24 2018 +0000
4 Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
5 CommitDate: Sun Jan 28 22:58:41 2018 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c62fc5c0
7
8 sys-boot/gnu-efi: fix linker script on .gnu.hash systems, bug #575300
9
10 Two patches here:
11 - gnu-hash.patch: fix linker script to work on .gnu.hash-only systems
12 - ia64-setjmp.patch: fix build breakage on ia64 systems
13
14 Reported-by: Émeric Maschino
15 Closes: https://bugs.gentoo.org/575300
16 Package-Manager: Portage-2.3.20, Repoman-2.3.6
17
18 .../files/gnu-efi-3.0.6-ia64-gnu-hash.patch | 149 +++++++++++++++++++
19 .../gnu-efi/files/gnu-efi-3.0.6-ia64-setjmp.patch | 163 +++++++++++++++++++++
20 sys-boot/gnu-efi/gnu-efi-3.0.6-r2.ebuild | 93 ++++++++++++
21 3 files changed, 405 insertions(+)
22
23 diff --git a/sys-boot/gnu-efi/files/gnu-efi-3.0.6-ia64-gnu-hash.patch b/sys-boot/gnu-efi/files/gnu-efi-3.0.6-ia64-gnu-hash.patch
24 new file mode 100644
25 index 00000000000..9487ba4c673
26 --- /dev/null
27 +++ b/sys-boot/gnu-efi/files/gnu-efi-3.0.6-ia64-gnu-hash.patch
28 @@ -0,0 +1,149 @@
29 +https://sourceforge.net/p/gnu-efi/code/merge-requests/1/
30 +
31 +From 2cc0b085fb82e80d43cc08c8376dff9f9532a72d Mon Sep 17 00:00:00 2001
32 +From: Sergei Trofimovich <slyfox@g.o>
33 +Date: Sat, 27 Jan 2018 20:29:05 +0000
34 +Subject: [PATCH] gnuefi: preserve .gnu.hash sections (unbreaks elilo on IA-64)
35 +
36 +Gentoo has slightly modified linker defaults: --hash-style=gnu
37 +This means all ELF files in system have '.gnu.hash' section
38 +but no '.hash' section.
39 +
40 +gnuefi's ldscript did not account for it and as a result
41 +one symbol 'ImageBase' did not resolve locally for elilo.so
42 +and caused 'elilo' to fail to load by ia64 EFI:
43 + Loading.: Gentoo (try new elilo)
44 + ImageAddress: pointer is outside of image
45 + ImageAddress: pointer is outside of image
46 +
47 +Those two relocations come from crt0-efi-ia64.S PE32 entry point
48 +fdescr:
49 +
50 +```
51 + #define IMAGE_REL_BASED_DIR64<->10
52 + .section .reloc, "a"
53 + data4 _start_plabel // Page RVA
54 + data4 12 // Block Size (2*4+2*2)
55 + data2 (IMAGE_REL_BASED_DIR64<<12) + 0 // reloc for plabel's entry point
56 + data2 (IMAGE_REL_BASED_DIR64<<12) + 8 // reloc for plabel's global pointer
57 +```
58 +
59 +These refer ImageBase.
60 +
61 +The change adds '.gnu.hash' collection (follows existing '.hash'
62 +collection).
63 +
64 +Tested on IA-64 by successfully booting elilo-3.16.
65 +
66 +Bug: https://bugs.gentoo.org/575300
67 +Signed-off-by: Sergei Trofimovich <slyfox@g.o>
68 +---
69 + README.gnuefi | 8 +++++++-
70 + gnuefi/elf_ia32_efi.lds | 4 +++-
71 + gnuefi/elf_ia32_fbsd_efi.lds | 4 +++-
72 + gnuefi/elf_ia64_efi.lds | 4 +++-
73 + gnuefi/elf_x86_64_efi.lds | 4 +++-
74 + gnuefi/elf_x86_64_fbsd_efi.lds | 4 +++-
75 + 6 files changed, 22 insertions(+), 6 deletions(-)
76 +
77 +diff --git a/README.gnuefi b/README.gnuefi
78 +index a7feec0..512698c 100644
79 +--- a/README.gnuefi
80 ++++ b/README.gnuefi
81 +@@ -231,11 +231,17 @@ and page sized.These eight sections are used to group together the much
82 + greater number of sections that are typically present in ELF object files.
83 + Specifically:
84 +
85 +- .hash
86 ++ .hash (and/or .gnu.hash)
87 + Collects the ELF .hash info (this section _must_ be the first
88 + section in order to build a shared object file; the section is
89 + not actually loaded or used at runtime).
90 +
91 ++ GNU binutils provides a mechanism to generate different hash info
92 ++ via --hash-style=<sysv|gnu|both> option. In this case output
93 ++ shared object will contain .hash section, .gnu.hash section or
94 ++ both. In order to generate correct output linker script preserves
95 ++ both types of hash sections.
96 ++
97 + .text
98 + Collects all sections containing executable code.
99 +
100 +diff --git a/gnuefi/elf_ia32_efi.lds b/gnuefi/elf_ia32_efi.lds
101 +index 6cc4ce1..f27fe5f 100644
102 +--- a/gnuefi/elf_ia32_efi.lds
103 ++++ b/gnuefi/elf_ia32_efi.lds
104 +@@ -5,7 +5,9 @@ SECTIONS
105 + {
106 + . = 0;
107 + ImageBase = .;
108 +- .hash : { *(.hash) } /* this MUST come first! */
109 ++ /* .hash and/or .gnu.hash MUST come first! */
110 ++ .hash : { *(.hash) }
111 ++ .gnu.hash : { *(.gnu.hash) }
112 + . = ALIGN(4096);
113 + .text :
114 + {
115 +diff --git a/gnuefi/elf_ia32_fbsd_efi.lds b/gnuefi/elf_ia32_fbsd_efi.lds
116 +index 77d6fad..cd309e2 100644
117 +--- a/gnuefi/elf_ia32_fbsd_efi.lds
118 ++++ b/gnuefi/elf_ia32_fbsd_efi.lds
119 +@@ -5,7 +5,9 @@ SECTIONS
120 + {
121 + . = 0;
122 + ImageBase = .;
123 +- .hash : { *(.hash) } /* this MUST come first! */
124 ++ /* .hash and/or .gnu.hash MUST come first! */
125 ++ .hash : { *(.hash) }
126 ++ .gnu.hash : { *(.gnu.hash) }
127 + . = ALIGN(4096);
128 + .text :
129 + {
130 +diff --git a/gnuefi/elf_ia64_efi.lds b/gnuefi/elf_ia64_efi.lds
131 +index baca962..190792a 100644
132 +--- a/gnuefi/elf_ia64_efi.lds
133 ++++ b/gnuefi/elf_ia64_efi.lds
134 +@@ -5,7 +5,9 @@ SECTIONS
135 + {
136 + . = 0;
137 + ImageBase = .;
138 +- .hash : { *(.hash) } /* this MUST come first! */
139 ++ /* .hash and/or .gnu.hash MUST come first! */
140 ++ .hash : { *(.hash) }
141 ++ .gnu.hash : { *(.gnu.hash) }
142 + . = ALIGN(4096);
143 + .text :
144 + {
145 +diff --git a/gnuefi/elf_x86_64_efi.lds b/gnuefi/elf_x86_64_efi.lds
146 +index 942d1f3..7be5902 100644
147 +--- a/gnuefi/elf_x86_64_efi.lds
148 ++++ b/gnuefi/elf_x86_64_efi.lds
149 +@@ -6,7 +6,9 @@ SECTIONS
150 + {
151 + . = 0;
152 + ImageBase = .;
153 +- .hash : { *(.hash) } /* this MUST come first! */
154 ++ /* .hash and/or .gnu.hash MUST come first! */
155 ++ .hash : { *(.hash) }
156 ++ .gnu.hash : { *(.gnu.hash) }
157 + . = ALIGN(4096);
158 + .eh_frame :
159 + {
160 +diff --git a/gnuefi/elf_x86_64_fbsd_efi.lds b/gnuefi/elf_x86_64_fbsd_efi.lds
161 +index 6fd2031..fe1f334 100644
162 +--- a/gnuefi/elf_x86_64_fbsd_efi.lds
163 ++++ b/gnuefi/elf_x86_64_fbsd_efi.lds
164 +@@ -6,7 +6,9 @@ SECTIONS
165 + {
166 + . = 0;
167 + ImageBase = .;
168 +- .hash : { *(.hash) } /* this MUST come first! */
169 ++ /* .hash and/or .gnu.hash MUST come first! */
170 ++ .hash : { *(.hash) }
171 ++ .gnu.hash : { *(.gnu.hash) }
172 + . = ALIGN(4096);
173 + .eh_frame :
174 + {
175 +--
176 +2.16.1
177 +
178
179 diff --git a/sys-boot/gnu-efi/files/gnu-efi-3.0.6-ia64-setjmp.patch b/sys-boot/gnu-efi/files/gnu-efi-3.0.6-ia64-setjmp.patch
180 new file mode 100644
181 index 00000000000..b0964426500
182 --- /dev/null
183 +++ b/sys-boot/gnu-efi/files/gnu-efi-3.0.6-ia64-setjmp.patch
184 @@ -0,0 +1,163 @@
185 +https://sourceforge.net/p/gnu-efi/code/merge-requests/2/
186 +
187 +From 0e6995a96b0f5867c8d85fbd251cfbc295a3fc4d Mon Sep 17 00:00:00 2001
188 +From: Sergei Trofimovich <slyfox@g.o>
189 +Date: Sun, 28 Jan 2018 16:44:21 +0000
190 +Subject: [PATCH] gnu-efi: fix lib/ia64/setjmp.S IA-64 build failure
191 +
192 +The build failed as:
193 + lib/ia64/setjmp.S:171: Error: Unknown opcode `ldf.nt1 f26=[r10],8'
194 + lib/ia64/setjmp.S:178: Error: Operand 1 of `ldf.fill.nt1' should be a floating-point register
195 +
196 +The change syncs longjmp definition with
197 + edk2/EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ipf/setjmp.s
198 +pulling in:
199 +- branch in the end of function
200 +- registers used wrong instruction for float restore
201 +
202 +Signed-off-by: Sergei Trofimovich <slyfox@g.o>
203 +---
204 + lib/ia64/setjmp.S | 61 +++++++++++++++++++++++++++----------------------------
205 + 1 file changed, 30 insertions(+), 31 deletions(-)
206 +
207 +diff --git a/lib/ia64/setjmp.S b/lib/ia64/setjmp.S
208 +index c806fbc..bbb29d8 100644
209 +--- a/lib/ia64/setjmp.S
210 ++++ b/lib/ia64/setjmp.S
211 +@@ -16,11 +16,11 @@ BASIS,
212 + .globl setjmp
213 + .type setjmp, @function
214 + setjmp:
215 +- alloc loc = ar.pfs, 1, 2, 1, 0
216 ++ alloc loc0 = ar.pfs, 1, 2, 1, 0
217 + ;;
218 + mov r14 = ar.unat
219 + mov r15 = ar.bsp
220 +- add r10 = 0x10 * 20, in0
221 ++ add r10 = 0x10*20, in0
222 + ;;
223 + stf.spill.nta [in0] = f2, 0x10
224 + st8.spill.nta [r10] = r4, 8
225 +@@ -98,29 +98,25 @@ setjmp:
226 +
227 + .globl longjmp
228 + .type longjmp, @function
229 +- .regstk
230 ++ .regstk 2, 0, 0, 0
231 + longjmp:
232 +- add r10 = 0x10 * 20 + 8*14, in0
233 +- movl r2 = ~(((1<<14) - 1) << 16) | 3)
234 ++ add r10 = 0x10*20 + 8*14, in0
235 ++ movl r2 = ~((((1<<14) - 1) << 16) | 3)
236 + ;;
237 + ld8.nt1 r14 = [r10], -8*2
238 + mov r15 = ar.bspstore
239 + ;;
240 + ld8.nt1 r17 = [r10], -8
241 + mov r16 = ar.rsc
242 +- cmp.leu p6 = r14, r15
243 ++ cmp.leu p6 = r14, r15
244 + ;;
245 + ld8.nt1 r18 = [r10], -8
246 + ld8.nt1 r25 = [r10], -8
247 +- and r2 = r16, r2
248 ++ and r2 = r16, r2
249 + ;;
250 +- ldf.fill.nt1 f2 = [in0], 0x10
251 ++ ldf.fill.nt1 f2 = [in0], 0x10
252 + ld8.nt1 r24 = [r10], -8
253 +- mov b5 = r25
254 +- ;;
255 +- mov ar.rsc = r2
256 +- ld8.nt1 r23 = [r10], -8
257 +- mov b5 = r25
258 ++ mov b5 = r25
259 + ;;
260 + mov ar.rsc = r2
261 + ld8.nt1 r23 = [r10], -8
262 +@@ -137,51 +133,51 @@ _skip_flushrs:
263 + mov r31 = ar.rnat
264 + loadrs
265 + ;;
266 +- ldf.fill.nt1 f4 = [in0], 0x10
267 ++ ldf.fill.nt1 f4 = [in0], 0x10
268 + ld8.nt1 r22 = [r10], -8
269 +- dep r2 = -1, r14, 3, 6
270 ++ dep r2 = -1, r14, 3, 6
271 + ;;
272 +- ldf.fill.nt1 f5 = [in0], 0x10
273 +- ld8.nt1 f21 = [r10], -8
274 +- cmp p6 = r2, r15
275 ++ ldf.fill.nt1 f5 = [in0], 0x10
276 ++ ld8.nt1 r21 = [r10], -8
277 ++ cmp.ltu p6 = r2, r15
278 + ;;
279 + ld8.nt1 r20 = [r10], -0x10
280 + (p6) ld8.nta r31 = [r2]
281 +- mov b3 = r23
282 ++ mov b3 = r23
283 + ;;
284 + ldf.fill.nt1 f16 = [in0], 0x10
285 +- ld8.fill.nt1 r7 = [r10], -8
286 +- mov b2 = r22
287 ++ ld8.fill.nt1 r7 = [r10], -8
288 ++ mov b2 = r22
289 + ;;
290 + ldf.fill.nt1 f17 = [in0], 0x10
291 +- ld8.fill.nt1 r6 = [r10], -8
292 +- mov b1 = r21
293 ++ ld8.fill.nt1 r6 = [r10], -8
294 ++ mov b1 = r21
295 + ;;
296 + ldf.fill.nt1 f18 = [in0], 0x10
297 +- ld8.fill.nt1 r5 = [r10], -8
298 +- mov b0 = r20
299 ++ ld8.fill.nt1 r5 = [r10], -8
300 ++ mov b0 = r20
301 + ;;
302 + ldf.fill.nt1 f19 = [in0], 0x10
303 +- ld8.fill.nt1 r4 = [r10], 8*13
304 ++ ld8.fill.nt1 r4 = [r10], 8*13
305 + ;;
306 + ldf.fill.nt1 f20 = [in0], 0x10
307 + ld8.nt1 r19 = [r10], 0x10
308 + ;;
309 + ldf.fill.nt1 f21 = [in0], 0x10
310 +- ldf.nt1 f26 = [r10], 8
311 ++ ld8.nt1 r26 = [r10], 8
312 + mov ar.pfs = r19
313 + ;;
314 + ldf.fill.nt1 f22 = [in0], 0x10
315 + ld8.nt1 r27 = [r10], 8
316 +- mov pr = r26, -1
317 ++ mov pr = r26, -1
318 + ;;
319 +- ldf.fill.nt1 r23 = [in0], 0x10
320 ++ ldf.fill.nt1 f23 = [in0], 0x10
321 + ld8.nt1 r28 = [r10], -17*8 - 0x10
322 + mov ar.lc = r27
323 + ;;
324 + ldf.fill.nt1 f24 = [in0], 0x10
325 + ldf.fill.nt1 f25 = [in0], 0x10
326 +- mov r8 = in1
327 ++ mov r8 = in1
328 + ;;
329 + ldf.fill.nt1 f26 = [in0], 0x10
330 + ldf.fill.nt1 f31 = [r10], -0x10
331 +@@ -192,9 +188,12 @@ _skip_flushrs:
332 + ldf.fill.nt1 f28 = [in0]
333 + ldf.fill.nt1 f29 = [r10], 0x10*3 + 8*4
334 + ;;
335 +- ld8.fill.nt1 sp = [r10]
336 ++ ld8.fill.nt1 sp = [r10]
337 + mov ar.unat = r18
338 + ;;
339 + mov ar.bspstore = r14
340 + mov ar.rnat = r31
341 + ;;
342 ++ invala
343 ++ mov ar.rsc = r16
344 ++ br.ret.sptk b0
345 +--
346 +2.16.1
347 +
348
349 diff --git a/sys-boot/gnu-efi/gnu-efi-3.0.6-r2.ebuild b/sys-boot/gnu-efi/gnu-efi-3.0.6-r2.ebuild
350 new file mode 100644
351 index 00000000000..d30fd4771bd
352 --- /dev/null
353 +++ b/sys-boot/gnu-efi/gnu-efi-3.0.6-r2.ebuild
354 @@ -0,0 +1,93 @@
355 +# Copyright 1999-2018 Gentoo Foundation
356 +# Distributed under the terms of the GNU General Public License v2
357 +
358 +EAPI=6
359 +
360 +inherit flag-o-matic toolchain-funcs
361 +
362 +DESCRIPTION="Library for build EFI Applications"
363 +HOMEPAGE="http://gnu-efi.sourceforge.net/"
364 +SRC_URI="mirror://sourceforge/gnu-efi/${P}.tar.bz2"
365 +
366 +# inc/, lib/ dirs (README.efilib)
367 +# - BSD-2
368 +# gnuefi dir:
369 +# - BSD (3-cluase): crt0-efi-ia32.S
370 +# - GPL-2+ : setjmp_ia32.S
371 +LICENSE="GPL-2+ BSD BSD-2"
372 +SLOT="0"
373 +KEYWORDS="-* ~amd64 ~arm ~arm64 ~ia64 ~x86"
374 +IUSE="abi_x86_32 abi_x86_64 -custom-cflags"
375 +
376 +DEPEND="sys-apps/pciutils"
377 +RDEPEND=""
378 +
379 +# These objects get run early boot (i.e. not inside of Linux),
380 +# so doing these QA checks on them doesn't make sense.
381 +QA_EXECSTACK="usr/*/lib*efi.a:* usr/*/crt*.o"
382 +RESTRICT="strip"
383 +
384 +PATCHES=(
385 + "${FILESDIR}"/${P}-ia64-gnu-hash.patch
386 + "${FILESDIR}"/${P}-ia64-setjmp.patch
387 +)
388 +
389 +src_prepare() {
390 + sed -i -e "s/-Werror//" Make.defaults || die
391 + default
392 +}
393 +
394 +efimake() {
395 + local arch=
396 + case ${CHOST} in
397 + arm*) arch=arm ;;
398 + aarch64*) arch=aarch64 ;;
399 + ia64*) arch=ia64 ;;
400 + i?86*) arch=ia32 ;;
401 + x86_64*) arch=x86_64 ;;
402 + *) die "Unknown CHOST" ;;
403 + esac
404 +
405 + local args=(
406 + ARCH="${arch}"
407 + HOSTCC="${BUILD_CC}"
408 + CC="${CC}"
409 + AS="${AS}"
410 + LD="${LD}"
411 + AR="${AR}"
412 + PREFIX="${EPREFIX}/usr"
413 + LIBDIR='$(PREFIX)'/$(get_libdir)
414 + )
415 + emake -j1 "${args[@]}" "$@"
416 +}
417 +
418 +src_compile() {
419 + tc-export BUILD_CC AR AS CC LD
420 +
421 + if use custom-cflags; then
422 + # https://bugs.gentoo.org/607992
423 + filter-mfpmath sse
424 +
425 + # https://bugs.gentoo.org/619628
426 + append-flags $(test-flags-CC -mno-avx)
427 + else
428 + unset CFLAGS CPPFLAGS LDFLAGS
429 + fi
430 +
431 + if [[ ${CHOST} == x86_64* ]]; then
432 + use abi_x86_32 && CHOST=i686 ABI=x86 efimake
433 + use abi_x86_64 && efimake
434 + else
435 + efimake
436 + fi
437 +}
438 +
439 +src_install() {
440 + if [[ ${CHOST} == x86_64* ]]; then
441 + use abi_x86_32 && CHOST=i686 ABI=x86 efimake INSTALLROOT="${D}" install
442 + use abi_x86_64 && efimake INSTALLROOT="${D}" install
443 + else
444 + efimake INSTALLROOT="${D}" install
445 + fi
446 + einstalldocs
447 +}