Joel Stanley | 8ac6ef0 | 2016-12-14 15:12:16 +1030 | [diff] [blame^] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Nicholas Piggin <npiggin@gmail.com> |
| 3 | Date: Mon, 28 Nov 2016 12:42:26 +1100 |
| 4 | Subject: [PATCH 10/12] powerpc/boot: Request no dynamic linker for boot |
| 5 | wrapper |
| 6 | |
| 7 | The boot wrapper performs its own relocations and does not require |
| 8 | PT_INTERP segment. However currently we don't tell the linker that. |
| 9 | |
| 10 | Prior to binutils 2.28 that works OK. But since binutils commit |
| 11 | 1a9ccd70f9a7 ("Fix the linker so that it will not silently generate ELF |
| 12 | binaries with invalid program headers. Fix readelf to report such |
| 13 | invalid binaries.") binutils tries to create a program header segment |
| 14 | due to PT_INTERP, and the link fails because there is no space for it: |
| 15 | |
| 16 | ld: arch/powerpc/boot/zImage.pseries: Not enough room for program headers, try linking with -N |
| 17 | ld: final link failed: Bad value |
| 18 | |
| 19 | So tell the linker not to do that, by passing --no-dynamic-linker. |
| 20 | |
| 21 | Cc: stable@vger.kernel.org |
| 22 | Reported-by: Anton Blanchard <anton@samba.org> |
| 23 | Signed-off-by: Nicholas Piggin <npiggin@gmail.com> |
| 24 | [mpe: Drop dependency on ld-version.sh and massage change log] |
| 25 | Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> |
| 26 | (cherry picked from commit ff45000fcb56b5b0f1a14a865d3541746d838a0a) |
| 27 | Signed-off-by: Joel Stanley <joel@jms.id.au> |
| 28 | |
| 29 | Signed-off-by: Joel Stanley <joel@jms.id.au> |
| 30 | --- |
| 31 | arch/powerpc/boot/wrapper | 25 ++++++++++++++++++++++++- |
| 32 | 1 file changed, 24 insertions(+), 1 deletion(-) |
| 33 | |
| 34 | diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper |
| 35 | index ceaa75d5a684..8c8394e4e164 100755 |
| 36 | --- a/arch/powerpc/boot/wrapper |
| 37 | +++ b/arch/powerpc/boot/wrapper |
| 38 | @@ -161,6 +161,28 @@ case "$elfformat" in |
| 39 | elf32-powerpc) format=elf32ppc ;; |
| 40 | esac |
| 41 | |
| 42 | +ld_version() |
| 43 | +{ |
| 44 | + # Poached from scripts/ld-version.sh, but we don't want to call that because |
| 45 | + # this script (wrapper) is distributed separately from the kernel source. |
| 46 | + # Extract linker version number from stdin and turn into single number. |
| 47 | + awk '{ |
| 48 | + gsub(".*\\)", ""); |
| 49 | + gsub(".*version ", ""); |
| 50 | + gsub("-.*", ""); |
| 51 | + split($1,a, "."); |
| 52 | + print a[1]*100000000 + a[2]*1000000 + a[3]*10000; |
| 53 | + exit |
| 54 | + }' |
| 55 | +} |
| 56 | + |
| 57 | +# Do not include PT_INTERP segment when linking pie. Non-pie linking |
| 58 | +# just ignores this option. |
| 59 | +LD_VERSION=$(${CROSS}ld --version | ld_version) |
| 60 | +LD_NO_DL_MIN_VERSION=$(echo 2.26 | ld_version) |
| 61 | +if [ "$LD_VERSION" -ge "$LD_NO_DL_MIN_VERSION" ] ; then |
| 62 | + nodl="--no-dynamic-linker" |
| 63 | +fi |
| 64 | |
| 65 | platformo=$object/"$platform".o |
| 66 | lds=$object/zImage.lds |
| 67 | @@ -412,7 +434,8 @@ if [ "$platform" != "miboot" ]; then |
| 68 | if [ -n "$link_address" ] ; then |
| 69 | text_start="-Ttext $link_address" |
| 70 | fi |
| 71 | - ${CROSS}ld -m $format -T $lds $text_start $pie -o "$ofile" \ |
| 72 | +#link everything |
| 73 | + ${CROSS}ld -m $format -T $lds $text_start $pie $nodl -o "$ofile" \ |
| 74 | $platformo $tmp $object/wrapper.a |
| 75 | rm $tmp |
| 76 | fi |
| 77 | -- |
| 78 | 2.11.0 |
| 79 | |