PR27226, ld.bfd contains huge .rodata section
authorAlan Modra <amodra@gmail.com>
Tue, 26 Jan 2021 00:18:09 +0000 (10:48 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 26 Jan 2021 10:24:43 +0000 (20:54 +1030)
This makes it possible to build ld without any compiled-in scripts,
by setting COMPILE_IN=no in the environment.  pe, beos and pdp11
targets didn't support scripts from the file system, with pdp11
nastily editing the ld/ldscripts file so that the built-in script
didn't match.

PR 27226
* emulparams/alphavms.sh: Don't set COMPILE_IN.
* emulparams/elf64_ia64_vms.sh: Likewise.
* emulparams/elf64mmix.sh: Likewise.
* emulparams/elf_iamcu.sh: Likewise.
* emulparams/elf_k1om.sh: Likewise.
* emulparams/elf_l1om.sh: Likewise.
* emulparams/mmo.sh: Likewise.
* emulparams/pdp11.sh: Set DATA_SEG_ADDR.
* scripttempl/pdp11.sc: Use it.
* emultempl/pdp11.em: Don't edit .xn script for separate_code,
instead use .xe script.  Support scripts from file system.
* emultempl/beos.em: Support scripts from file system.
* emultempl/pe.em: Likewise.
* emultempl/pep.em: Likewise.
* testsuite/ld-bootstrap/bootstrap.exp: Make tmpdir/ldscripts link.

15 files changed:
ld/ChangeLog
ld/emulparams/alphavms.sh
ld/emulparams/elf64_ia64_vms.sh
ld/emulparams/elf64mmix.sh
ld/emulparams/elf_iamcu.sh
ld/emulparams/elf_k1om.sh
ld/emulparams/elf_l1om.sh
ld/emulparams/mmo.sh
ld/emulparams/pdp11.sh
ld/emultempl/beos.em
ld/emultempl/pdp11.em
ld/emultempl/pe.em
ld/emultempl/pep.em
ld/scripttempl/pdp11.sc
ld/testsuite/ld-bootstrap/bootstrap.exp

index befdf5bceb52811ac84793e703b458fd4f4b9585..638f42df990f01c7e884c320a928deab24383aee 100644 (file)
@@ -1,3 +1,22 @@
+2021-01-26  Alan Modra  <amodra@gmail.com>
+
+       PR 27226
+       * emulparams/alphavms.sh: Don't set COMPILE_IN.
+       * emulparams/elf64_ia64_vms.sh: Likewise.
+       * emulparams/elf64mmix.sh: Likewise.
+       * emulparams/elf_iamcu.sh: Likewise.
+       * emulparams/elf_k1om.sh: Likewise.
+       * emulparams/elf_l1om.sh: Likewise.
+       * emulparams/mmo.sh: Likewise.
+       * emulparams/pdp11.sh: Set DATA_SEG_ADDR.
+       * scripttempl/pdp11.sc: Use it.
+       * emultempl/pdp11.em: Don't edit .xn script for separate_code,
+       instead use .xe script.  Support scripts from file system.
+       * emultempl/beos.em: Support scripts from file system.
+       * emultempl/pe.em: Likewise.
+       * emultempl/pep.em: Likewise.
+       * testsuite/ld-bootstrap/bootstrap.exp: Make tmpdir/ldscripts link.
+
 2021-01-25  Fangrui Song  <maskray@google.com>
 
        PR ld/27230
index ac9b3a2e6b74caeb1971172d8acf426cb4ef34e9..ab69c26e3eb552f018ff83398fb2ef487f8a3a59 100644 (file)
@@ -3,5 +3,4 @@ SCRIPT_NAME=alphavms
 OUTPUT_FORMAT="vms-alpha"
 ARCH=alpha
 
-COMPILE_IN=yes
-EXTRA_EM_FILE=vms
\ No newline at end of file
+EXTRA_EM_FILE=vms
index 068840281f6703003bf9ed2767c598b4402b3748..53a6a14d2d476697de783d05d1bfc9be55bb78ee 100644 (file)
@@ -3,5 +3,4 @@ SCRIPT_NAME=ia64vms
 OUTPUT_FORMAT="elf64-ia64-vms"
 ARCH=ia64
 
-COMPILE_IN=yes
 EXTRA_EM_FILE=vms
index 75e24be2e2a4ad56bf7da7bccb150becd597fff6..fb7c4e31b3e8aaba8da91da4303f81d2a196ac69 100644 (file)
@@ -16,7 +16,6 @@ DATA_ADDR='DEFINED (__.MMIX.start..data) ? __.MMIX.start..data : 0x2000000000000
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 ARCH=mmix
 MACHINE=
-COMPILE_IN=yes
 EXTRA_EM_FILE=mmixelf
 
 # The existence of a symbol __start (or _start) should overrule Main, so
index 1cc07cc720ab0750b6ccfd2248abd7edb6f64c67..c1582235eda0faeb6ccbb7f4037a34e07dbffff2 100644 (file)
@@ -10,7 +10,6 @@ MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
 ARCH=iamcu
 MACHINE=
-COMPILE_IN=yes
 TEMPLATE_NAME=elf
 EXTRA_EM_FILE="elf-x86"
 GENERATE_SHLIB_SCRIPT=yes
index 6f15bdc0572b91bc89f2a57e352326b8000b53c3..b27f5ea861afe8e6ef7089d48dd795dd48292f65 100644 (file)
@@ -11,7 +11,6 @@ MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
 ARCH="k1om"
 MACHINE=
-COMPILE_IN=yes
 TEMPLATE_NAME=elf
 EXTRA_EM_FILE="elf-x86"
 GENERATE_SHLIB_SCRIPT=yes
index 7348c95787f951f3ee69b0f50ffac85383b4cc9c..70d76829d7b436bc99a08cb5d262f73a11f5259c 100644 (file)
@@ -11,7 +11,6 @@ MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
 ARCH="l1om"
 MACHINE=
-COMPILE_IN=yes
 TEMPLATE_NAME=elf
 EXTRA_EM_FILE="elf-x86"
 GENERATE_SHLIB_SCRIPT=yes
index ca98013cafcfee03d8b6d22728ad9d22e7cafd92..6bd84d2e396c1eba52215aa6e61d058f15fac4f3 100644 (file)
@@ -7,5 +7,4 @@ DATA_ADDR='DEFINED (__.MMIX.start..data) ? __.MMIX.start..data : 0x2000000000000
 OUTPUT_FORMAT=mmo
 RELOCATEABLE_OUTPUT_FORMAT=elf64-mmix
 ARCH=mmix
-COMPILE_IN=yes
 EXTRA_EM_FILE=mmo
index 3f3326d121aae8f1bdd90b2c3c39414d9a42fbbc..d79bb8355144be114869ef61b65993362f27b2ec 100644 (file)
@@ -4,3 +4,8 @@ TEXT_START_ADDR=0
 TARGET_PAGE_SIZE=8192
 EXTRA_EM_FILE=pdp11
 ARCH=pdp11
+
+case "$LD_FLAG" in
+  *textonly) DATA_SEG_ADDR=0 ;;
+  *) DATA_SEG_ADDR=$DATA_ALIGNMENT ;;
+esac
index bb4395f63ae964e5e71333cc4629417af770d799..fc43ce146771fad0c63714f45fb732becdde9bdb 100644 (file)
@@ -712,7 +712,11 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
 static char *
 gld_${EMULATION_NAME}_get_script (int *isfile)
 EOF
+
+if test x"$COMPILE_IN" = xyes
+then
 # Scripts compiled in.
+
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
@@ -734,6 +738,27 @@ echo '  ; else return'                                 >> e${EMULATION_NAME}.c
 sed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
 echo '; }'                                             >> e${EMULATION_NAME}.c
 
+else
+# Scripts read from the filesystem.
+
+fragment <<EOF
+{
+  *isfile = 1;
+
+  if (bfd_link_relocatable (&link_info) && config.build_constructors)
+    return "ldscripts/${EMULATION_NAME}.xu";
+  else if (bfd_link_relocatable (&link_info))
+    return "ldscripts/${EMULATION_NAME}.xr";
+  else if (!config.text_read_only)
+    return "ldscripts/${EMULATION_NAME}.xbn";
+  else if (!config.magic_demand_paged)
+    return "ldscripts/${EMULATION_NAME}.xn";
+  else
+    return "ldscripts/${EMULATION_NAME}.x";
+}
+EOF
+fi
+
 fragment <<EOF
 
 
index f725e7337e99bd45b722c79299c5630e0aeb84a3..6a3cacb37038c5bccc989cd21b09fc75fb69b379 100644 (file)
@@ -94,7 +94,11 @@ gld${EMULATION_NAME}_handle_option (int optc)
 static char *
 gld${EMULATION_NAME}_get_script (int *isfile)
 EOF
+
+if test x"$COMPILE_IN" = xyes
+then
 # Scripts compiled in.
+
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
@@ -109,8 +113,7 @@ sed $sc ldscripts/${EMULATION_NAME}.xu                      >> e${EMULATION_NAME}.c
 echo '  ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
 sed $sc ldscripts/${EMULATION_NAME}.xr                 >> e${EMULATION_NAME}.c
 echo '  ; else if (link_info.separate_code) return'    >> e${EMULATION_NAME}.c
-sed $sc ldscripts/${EMULATION_NAME}.xn | \
-  sed -e "s/ALIGN($TARGET_PAGE_SIZE)/0/"               >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xe                 >> e${EMULATION_NAME}.c
 echo '  ; else if (!config.text_read_only) return'     >> e${EMULATION_NAME}.c
 sed $sc ldscripts/${EMULATION_NAME}.xbn                        >> e${EMULATION_NAME}.c
 echo '  ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
@@ -119,6 +122,29 @@ echo '  ; else return'                                     >> e${EMULATION_NAME}.c
 sed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
 echo '; }'                                             >> e${EMULATION_NAME}.c
 
+else
+# Scripts read from the filesystem.
+
+fragment <<EOF
+{
+  *isfile = 1;
+
+  if (bfd_link_relocatable (&link_info) && config.build_constructors)
+    return "ldscripts/${EMULATION_NAME}.xu";
+  else if (bfd_link_relocatable (&link_info))
+    return "ldscripts/${EMULATION_NAME}.xr";
+  else if (link_info.separate_code)
+    return "ldscripts/${EMULATION_NAME}.xe";
+  else if (!config.text_read_only)
+    return "ldscripts/${EMULATION_NAME}.xbn";
+  else if (!config.magic_demand_paged)
+    return "ldscripts/${EMULATION_NAME}.xn";
+  else
+    return "ldscripts/${EMULATION_NAME}.x";
+}
+EOF
+fi
+
 fragment <<EOF
 
 /* --- \end{pdp11.em} */
index f9060be8c6cf760e550fcd9e7eaeb0024d512a33..748a6b494128e140c846e8a6d550f40c6c0c452a 100644 (file)
@@ -2355,7 +2355,11 @@ gld_${EMULATION_NAME}_find_potential_libraries
 static char *
 gld_${EMULATION_NAME}_get_script (int *isfile)
 EOF
+
+if test x"$COMPILE_IN" = xyes
+then
 # Scripts compiled in.
+
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
@@ -2381,6 +2385,36 @@ echo '  ; else return'                                   >> e${EMULATION_NAME}.c
 sed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
 echo '; }'                                             >> e${EMULATION_NAME}.c
 
+else
+# Scripts read from the filesystem.
+
+fragment <<EOF
+{
+  *isfile = 1;
+
+  if (bfd_link_relocatable (&link_info) && config.build_constructors)
+    return "ldscripts/${EMULATION_NAME}.xu";
+  else if (bfd_link_relocatable (&link_info))
+    return "ldscripts/${EMULATION_NAME}.xr";
+  else if (!config.text_read_only)
+    return "ldscripts/${EMULATION_NAME}.xbn";
+  else if (!config.magic_demand_paged)
+    return "ldscripts/${EMULATION_NAME}.xn";
+EOF
+if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
+fragment <<EOF
+  else if (link_info.pei386_auto_import == 1
+          && (MERGE_RDATA_V2 || link_info.pei386_runtime_pseudo_reloc != 2))
+    return "ldscripts/${EMULATION_NAME}.xa";
+EOF
+fi
+fragment <<EOF
+  else
+    return "ldscripts/${EMULATION_NAME}.x";
+}
+EOF
+fi
+
 fragment <<EOF
 
 
index ca335b5aa6eb8d242c026b16bf3c69782d771128..ff49c15c002af126beb20fa4a18577e0f7f0084f 100644 (file)
@@ -2175,7 +2175,11 @@ gld_${EMULATION_NAME}_find_potential_libraries
 static char *
 gld_${EMULATION_NAME}_get_script (int *isfile)
 EOF
+
+if test x"$COMPILE_IN" = xyes
+then
 # Scripts compiled in.
+
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
@@ -2201,6 +2205,36 @@ echo '  ; else return'                                   >> e${EMULATION_NAME}.c
 sed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
 echo '; }'                                             >> e${EMULATION_NAME}.c
 
+else
+# Scripts read from the filesystem.
+
+fragment <<EOF
+{
+  *isfile = 1;
+
+  if (bfd_link_relocatable (&link_info) && config.build_constructors)
+    return "ldscripts/${EMULATION_NAME}.xu";
+  else if (bfd_link_relocatable (&link_info))
+    return "ldscripts/${EMULATION_NAME}.xr";
+  else if (!config.text_read_only)
+    return "ldscripts/${EMULATION_NAME}.xbn";
+  else if (!config.magic_demand_paged)
+    return "ldscripts/${EMULATION_NAME}.xn";
+EOF
+if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
+fragment <<EOF
+  else if (link_info.pei386_auto_import == 1
+          && link_info.pei386_runtime_pseudo_reloc != 2)
+    return "ldscripts/${EMULATION_NAME}.xa";
+EOF
+fi
+fragment <<EOF
+  else
+    return "ldscripts/${EMULATION_NAME}.x";
+}
+EOF
+fi
+
 fragment <<EOF
 
 
index b6cfed883416f4d670abb4a7cf2055a937efe1ef..8605ae7b7934970f229a6fae19dd50b11cd7b5df 100644 (file)
@@ -35,7 +35,7 @@ SECTIONS
     ${RELOCATING+__etext = .;}
     ${PAD_TEXT+${RELOCATING+. = ${DATA_ALIGNMENT};}}
   }
-  ${RELOCATING+. = ${DATA_ALIGNMENT};}
+  ${RELOCATING+. = ${DATA_SEG_ADDR};}
   .data :
   {
     *(.data)
index bf9f7a30831186cff018fff9ce67c691b1b5a26c..2e4a09704ab0961d8979146ba496f0935ac8e283 100644 (file)
@@ -62,6 +62,7 @@ if { [istarget "powerpc-*-*"] } {
 
 set gcc_B_opt_save $gcc_B_opt
 
+catch "exec ln -s ../ldscripts tmpdir/ldscripts" status
 foreach ldexe {ld1 ld2 ld3} {
     if {![file isdirectory tmpdir/gcc$ldexe]} then {
        catch "exec mkdir tmpdir/gcc$ldexe" status