blob: 7fffa8172469c7f38b8c07c86b68bef489588b94 [file] [log] [blame]
Andrew Geisslerc5535c92023-01-27 16:10:19 -06001From 25e715730ddcca37021fa4876aed4fa91d5dea25 Mon Sep 17 00:00:00 2001
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002From: Khem Raj <raj.khem@gmail.com>
3Date: Mon, 2 Mar 2015 01:58:54 +0000
Andrew Geisslerd1e89492021-02-12 15:35:20 -06004Subject: [PATCH] binutils-crosssdk: Generate relocatable SDKs
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005
6This patch will modify the ELF linker scripts so that the crosssdk
7linker will generate binaries with a 4096 bytes PT_INTERP section. When the binaries
8will be relocated, at SDK install time, the interpreter path can be easily
9changed by the relocating script.
10
Andrew Geissler635e0e42020-08-21 15:58:33 -050011generate larger .interp section for gold linker as well
12
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013Upstream-Status: Inappropriate [SDK specific]
14
15Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com>
16Signed-off-by: Khem Raj <raj.khem@gmail.com>
17---
Andrew Geissler635e0e42020-08-21 15:58:33 -050018 gold/layout.cc | 2 +-
Brad Bishop6e60e8b2018-02-01 10:27:11 -050019 ld/genscripts.sh | 3 +++
20 ld/scripttempl/elf.sc | 4 ++--
Andrew Geissler635e0e42020-08-21 15:58:33 -050021 3 files changed, 6 insertions(+), 3 deletions(-)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050022
Andrew Geissler635e0e42020-08-21 15:58:33 -050023diff --git a/gold/layout.cc b/gold/layout.cc
Andrew Geisslerc5535c92023-01-27 16:10:19 -060024index 899d4af0707..7c31b1bef6e 100644
Andrew Geissler635e0e42020-08-21 15:58:33 -050025--- a/gold/layout.cc
26+++ b/gold/layout.cc
Andrew Geisslerc5535c92023-01-27 16:10:19 -060027@@ -5083,7 +5083,7 @@ Layout::create_interp(const Target* target)
Andrew Geissler635e0e42020-08-21 15:58:33 -050028 gold_assert(interp != NULL);
29 }
30
31- size_t len = strlen(interp) + 1;
32+ size_t len = 4096;
33
34 Output_section_data* odata = new Output_data_const(interp, len, 1);
35
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036diff --git a/ld/genscripts.sh b/ld/genscripts.sh
Andrew Geisslerc5535c92023-01-27 16:10:19 -060037index 382bd07ffe2..9fbd0c4cb8a 100755
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038--- a/ld/genscripts.sh
39+++ b/ld/genscripts.sh
Andrew Geissler82c905d2020-04-13 13:39:40 -050040@@ -304,6 +304,7 @@ DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041 LD_FLAG=r
42 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
43 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
44+PARTIAL_LINKING=" "
Andrew Geissler82c905d2020-04-13 13:39:40 -050045 ( echo "/* Script for -r */"
46 source_sh ${CUSTOMIZER_SCRIPT}
47 source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
48@@ -312,10 +313,12 @@ DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049 LD_FLAG=u
50 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
51 CONSTRUCTING=" "
52+PARTIAL_LINKING=" "
Andrew Geissler82c905d2020-04-13 13:39:40 -050053 ( echo "/* Script for -Ur */"
54 source_sh ${CUSTOMIZER_SCRIPT}
55 source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Brad Bishop316dfdd2018-06-25 12:45:53 -040056 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
Brad Bishop6e60e8b2018-02-01 10:27:11 -050057+unset PARTIAL_LINKING
58
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
Brad Bishop316dfdd2018-06-25 12:45:53 -040060 RELOCATING=" "
Brad Bishop6e60e8b2018-02-01 10:27:11 -050061diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
Andrew Geisslerc5535c92023-01-27 16:10:19 -060062index 5d3b0d31b1b..2163909cd56 100644
Brad Bishop6e60e8b2018-02-01 10:27:11 -050063--- a/ld/scripttempl/elf.sc
64+++ b/ld/scripttempl/elf.sc
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000065@@ -148,8 +148,8 @@ if test -z "$DATA_SEGMENT_ALIGN"; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -050066 DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);"
67 fi
68 fi
69-if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then
70- INITIAL_READONLY_SECTIONS=".interp ${RELOCATING-0} : { *(.interp) }"
71+if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}${PARTIAL_LINKING}"; then
72+ INITIAL_READONLY_SECTIONS=".interp ${RELOCATING-0} : { *(.interp); . = 0x1000; }"
73 fi
74 if test -z "$PLT"; then
75 IPLT=".iplt ${RELOCATING-0} : { *(.iplt) }"