[PATCH 1/4] v850: improve linker scripts for relocatable linking

Jan Beulich jbeulich@suse.com
Wed Feb 26 11:58:31 GMT 2025


Quite a few constructs where unconditional when they should take
$RELOCATING into account. The original observation was that output of
"ld -r" had .text start at 0x00100000.
---
I can only hope I caught all the places that need adjusting.

--- a/ld/scripttempl/v850.sc
+++ b/ld/scripttempl/v850.sc
@@ -26,7 +26,7 @@ SECTIONS
   /* This saves a little space in the ELF file, since the zda starts
      at a higher location that the ELF headers take up.  */
 
-  .zdata ${ZDATA_START_ADDR} :
+  .zdata ${RELOCATING+${ZDATA_START_ADDR}} :
   {
 	*(.zdata)
 	${RELOCATING+*(.zbss)
@@ -40,7 +40,7 @@ SECTIONS
      section.  Specifically it prevents the zdata
      section from being marked READONLY.  */
 
-  .rozdata ${ROZDATA_START_ADDR} :
+  .rozdata ${RELOCATING+${ROZDATA_START_ADDR}} :
   {
 	*(.rozdata)
 	${RELOCATING+*(romzdata)
@@ -48,7 +48,7 @@ SECTIONS
   }
 
   /* Read-only sections, merged into text segment.  */
-  . = ${TEXT_START_ADDR};
+  ${RELOCATING+. = ${TEXT_START_ADDR};}
   .interp	: { *(.interp) }
   .hash		: { *(.hash) }
   .dynsym	: { *(.dynsym) }
@@ -95,7 +95,7 @@ SECTIONS
       It contains a small lookup table at the start followed by the
       code pointed to by entries in the lookup table.  */
 
-  .call_table_data ${CALL_TABLE_START_ADDR} :
+  .call_table_data ${RELOCATING+${CALL_TABLE_START_ADDR}} :
   {
     ${RELOCATING+PROVIDE(__ctbp = .);}
     *(.call_table_data)
@@ -144,7 +144,7 @@ SECTIONS
   .got		: {${RELOCATING+ *(.got.plt)} *(.got) }
   .dynamic	: { *(.dynamic) }
 
-  .tdata ${TDATA_START_ADDR} :
+  .tdata ${RELOCATING+${TDATA_START_ADDR}} :
   {
 	${RELOCATING+PROVIDE (__ep = .);
 	*(.tbyte)
@@ -158,14 +158,14 @@ SECTIONS
      can access them all, and initialized data all before uninitialized, so
      we can shorten the on-disk segment size.  */
 
-  .sdata ${SDATA_START_ADDR} :
+  .sdata ${RELOCATING+${SDATA_START_ADDR}} :
   {
 	${RELOCATING+PROVIDE (__gp = . + 0x8000);}
 	*(.sdata)
    }
 
   /* See comment about .rozdata. */
-  .rosdata ${ROSDATA_START_ADDR} :
+  .rosdata ${RELOCATING+${ROSDATA_START_ADDR}} :
   {
 	*(.rosdata)
   }
--- a/ld/scripttempl/v850_rh850.sc
+++ b/ld/scripttempl/v850_rh850.sc
@@ -26,7 +26,7 @@ SECTIONS
   /* This saves a little space in the ELF file, since the zda starts
      at a higher location that the ELF headers take up.  */
 
-  .zdata ${ZDATA_START_ADDR} :
+  .zdata ${RELOCATING+${ZDATA_START_ADDR}} :
   {
 	*(.zdata)
 	${RELOCATING+*(.zdata23)
@@ -42,7 +42,7 @@ SECTIONS
      section.  Specifically it prevents the zdata
      section from being marked READONLY.  */
 
-  .rozdata ${ROZDATA_START_ADDR} :
+  .rozdata ${RELOCATING+${ROZDATA_START_ADDR}} :
   {
 	*(.rozdata)
 	${RELOCATING+*(romzdata)
@@ -52,7 +52,7 @@ SECTIONS
   }
 
   /* Read-only sections, merged into text segment.  */
-  . = ${TEXT_START_ADDR};
+  ${RELOCATING+. = ${TEXT_START_ADDR};}
   .interp	: { *(.interp) }
   .hash		: { *(.hash) }
   .dynsym	: { *(.dynsym) }
@@ -99,7 +99,7 @@ SECTIONS
       It contains a small lookup table at the start followed by the
       code pointed to by entries in the lookup table.  */
 
-  .call_table_data ${CALL_TABLE_START_ADDR} :
+  .call_table_data ${RELOCATING+${CALL_TABLE_START_ADDR}} :
   {
     ${RELOCATING+PROVIDE(__ctbp = .);}
     *(.call_table_data)
@@ -154,7 +154,7 @@ SECTIONS
   .got		: {${RELOCATING+ *(.got.plt)} *(.got) }
   .dynamic	: { *(.dynamic) }
 
-  .tdata ${TDATA_START_ADDR} :
+  .tdata ${RELOCATING+${TDATA_START_ADDR}} :
   {
 	${RELOCATING+PROVIDE (__ep = .);
 	*(.edata)
@@ -174,7 +174,7 @@ SECTIONS
      can access them all, and initialized data all before uninitialized, so
      we can shorten the on-disk segment size.  */
 
-  .sdata ${SDATA_START_ADDR} :
+  .sdata ${RELOCATING+${SDATA_START_ADDR}} :
   {
 	${RELOCATING+PROVIDE (__gp = . + 0x8000);}
 	*(.sdata)
@@ -182,7 +182,7 @@ SECTIONS
    }
 
   /* See comment about .rozdata. */
-  .rosdata ${ROSDATA_START_ADDR} :
+  .rosdata ${RELOCATING+${ROSDATA_START_ADDR}} :
   {
 	*(.rosdata)
 	${RELOCATING+*(.sconst)



More information about the Binutils mailing list