Skip to contentSkip to conversation

Fix kernel linker scripts

PATCH In review Jakub Jelinek 2 participants 3 messages Jul 2, 2001 – Jul 3, 2001

Subsystems (10)
Arm (32-bit) PowerPC MIPS s390 +6 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix kernel linker scripts

Hi!

Apparently all kernel scripts only have .rodata and not also .rodata.* input sections in it.
This has been no problem so far, but since binutils and gcc support SHF_MERGE sections (so that string constant (and other constant too) duplicates can be removed at link time) the compiler creates sections like .rodata.str1.1 and they really should be merged into the rodata output section (or whatever else) during linking (the default binutils linker scripts are doing this for ages).
On some architectures it creates no problems, just one more section in section table (like i386), on others it causes the kernel not to boot at all (e.g. on ia64).
Please apply.

arch/alpha/boot/bootloader.lds renamed from arch/alpha/boot/bootloader.lds.jj +1 -1
@@ -6,7 +6,7 @@ SECTIONS
   .text : { *(.text) }
   _etext = .;
   PROVIDE (etext = .);
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }
   .data : { *(.data) CONSTRUCTORS }
   .got : { *(.got) }
   .sdata : { *(.sdata) }
arch/alpha/vmlinux.lds.in renamed from arch/alpha/vmlinux.lds.in.jj +1 -1
@@ -53,7 +53,7 @@ SECTIONS
   /* Global data */
   _data = .;
   .data.cacheline_aligned : { *(.data.cacheline_aligned) }
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }
   .data : { *(.data) CONSTRUCTORS }
   .got : { *(.got) }
   .sdata : { *(.sdata) }
arch/arm/boot/compressed/vmlinux.lds.in renamed from arch/arm/boot/compressed/vmlinux.lds.in.jj +1 -0
@@ -24,6 +24,7 @@ SECTIONS
     *(.fixup)
     *(.gnu.warning)
     *(.rodata)
+    *(.rodata.*)
     *(.glue_7)
     *(.glue_7t)
     input_data = .;
arch/arm/vmlinux-armo.lds.in renamed from arch/arm/vmlinux-armo.lds.in.jj +1 -0
@@ -47,6 +47,7 @@ SECTIONS
 			*(.gnu.warning)
 			*(.text.lock)	/* out-of-line lock text */
 			*(.rodata)
+			*(.rodata.*)
 			*(.glue_7)
 			*(.glue_7t)
 			*(.kstrtab)
arch/arm/vmlinux-armv.lds.in renamed from arch/arm/vmlinux-armv.lds.in.jj +1 -0
@@ -42,6 +42,7 @@ SECTIONS
 			*(.gnu.warning)
 			*(.text.lock)	/* out-of-line lock text */
 			*(.rodata)
+			*(.rodata.*)
 			*(.glue_7)
 			*(.glue_7t)
 		*(.got)			/* Global offset table		*/
arch/cris/boot/compressed/decompress.ld renamed from arch/cris/boot/compressed/decompress.ld.jj +1 -0
@@ -13,6 +13,7 @@ SECTIONS
 		_stext = . ;
 		*(.text)
 		*(.rodata)
+		*(.rodata.*)
 		_etext = . ;
 	} > dram
 	.data :
arch/cris/cris.ld renamed from arch/cris/cris.ld.jj +1 -1
@@ -24,7 +24,7 @@ SECTIONS
 		*(.fixup)
 		*(.text.__*)
 		*(.rodata)
-		*(.rodata.__*)
+		*(.rodata.*)
 	}
 
 	. = ALIGN(4);                /* Exception table */
arch/i386/vmlinux.lds renamed from arch/i386/vmlinux.lds.jj +1 -1
@@ -17,7 +17,7 @@ SECTIONS
 
   _etext = .;			/* End of text section */
 
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }
   .kstrtab : { *(.kstrtab) }
 
   . = ALIGN(16);		/* Exception table */
arch/ia64/boot/bootloader.lds renamed from arch/ia64/boot/bootloader.lds.jj +1 -1
@@ -12,7 +12,7 @@ SECTIONS
 
   /* Global data */
   _data = .;
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }
   .data    : { *(.data) *(.gnu.linkonce.d*) CONSTRUCTORS }
   __gp = ALIGN (8) + 0x200000;
   .got           : { *(.got.plt) *(.got) }
arch/ia64/sn/fprom/fprom.lds renamed from arch/ia64/sn/fprom/fprom.lds.jj +1 -1
@@ -24,7 +24,7 @@ SECTIONS
   _data = .;
 
   .rodata : AT(ADDR(.rodata) - 0x0000000000000000 )
-	{ *(.rodata) }
+	{ *(.rodata) *(.rodata.*) }
   .opd : AT(ADDR(.opd) - 0x0000000000000000 )
 	{ *(.opd) }
   .data : AT(ADDR(.data) - 0x0000000000000000 )
arch/ia64/vmlinux.lds.S renamed from arch/ia64/vmlinux.lds.S.jj +1 -1
@@ -83,7 +83,7 @@ SECTIONS
   ia64_unw_end = .;
 
   .rodata : AT(ADDR(.rodata) - PAGE_OFFSET)
-	{ *(.rodata) }
+	{ *(.rodata) *(.rodata.*) }
   .kstrtab : AT(ADDR(.kstrtab) - PAGE_OFFSET)
 	{ *(.kstrtab) }
   .opd : AT(ADDR(.opd) - PAGE_OFFSET)
arch/m68k/vmlinux.lds renamed from arch/m68k/vmlinux.lds.jj +1 -1
@@ -12,7 +12,7 @@ SECTIONS
 	*(.text.lock)		/* out-of-line lock text */
 	*(.gnu.warning)
 	} = 0x4e75
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }
   .kstrtab : { *(.kstrtab) }
 
   . = ALIGN(16);		/* Exception table */
arch/m68k/vmlinux-sun3.lds renamed from arch/m68k/vmlinux-sun3.lds.jj +1 -0
@@ -20,6 +20,7 @@ SECTIONS
 
   .data : {			/* Data */
 	*(.rodata)
+	*(.rodata.*)
 	*(.data)
 	CONSTRUCTORS
   	. = ALIGN(16);		/* Exception table */
arch/mips/baget/ld.script.balo renamed from arch/mips/baget/ld.script.balo.jj +1 -0
@@ -31,6 +31,7 @@ SECTIONS
     _ftext = . ;
     *(.text)
     *(.rodata)
+    *(.rodata.*)
     *(.rodata1)
     /* .gnu.warning sections are handled specially by elf32.em.  */
     *(.gnu.warning)
arch/mips/dec/boot/ld.ecoff renamed from arch/mips/dec/boot/ld.ecoff.jj +1 -1
@@ -13,7 +13,7 @@ SECTIONS
   }
   .rdata :
   {
-    *(.rodata .rdata)
+    *(.rodata .rodata.* .rdata)
   }
   .data :
   {
arch/mips/ld.script.big renamed from arch/mips/ld.script.big.jj +1 -0
@@ -11,6 +11,7 @@ SECTIONS
     _ftext = . ;
     *(.text)
     *(.rodata)
+    *(.rodata.*)
     *(.rodata1)
     /* .gnu.warning sections are handled specially by elf32.em.  */
     *(.gnu.warning)
arch/mips/ld.script.little renamed from arch/mips/ld.script.little.jj +1 -0
@@ -11,6 +11,7 @@ SECTIONS
     _ftext = . ;
     *(.text)
     *(.rodata)
+    *(.rodata.*)
     *(.rodata1)
     /* .gnu.warning sections are handled specially by elf32.em.  */
     *(.gnu.warning)
arch/mips64/ld.script.elf64 renamed from arch/mips64/ld.script.elf64.jj +1 -0
@@ -18,6 +18,7 @@ SECTIONS
   .text : {
     *(.text)
     *(.rodata)
+    *(.rodata.*)
     *(.rodata1)
     /* .gnu.warning sections are handled specially by elf32.em.  */
     *(.gnu.warning)
arch/mips64/ld.script.elf32.S renamed from arch/mips64/ld.script.elf32.S.jj +1 -0
@@ -8,6 +8,7 @@ SECTIONS
   {
     *(.text)
     *(.rodata)
+    *(.rodata.*)
     *(.rodata1)
     /* .gnu.warning sections are handled specially by elf32.em.  */
     *(.gnu.warning)
arch/parisc/vmlinux.lds renamed from arch/parisc/vmlinux.lds.jj +1 -1
@@ -22,7 +22,7 @@ SECTIONS
 	} = 0
 
   . = ALIGN(16);
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }
   .kstrtab : { *(.kstrtab) }
 
   _etext = .;			/* End of text section */
arch/ppc/boot/pmac/ld.script renamed from arch/ppc/boot/pmac/ld.script.jj +1 -0
@@ -32,6 +32,7 @@ SECTIONS
   {
     *(.text)
     *(.rodata)
+    *(.rodata.*)
     *(.rodata1)
     *(.got1)
   }
arch/ppc/boot/tree/ld.script renamed from arch/ppc/boot/tree/ld.script.jj +1 -0
@@ -32,6 +32,7 @@ SECTIONS
   {
     *(.text)
     *(.rodata)
+    *(.rodata.*)
     *(.rodata1)
     *(.got1)
   }
arch/ppc/vmlinux.lds renamed from arch/ppc/vmlinux.lds.jj +1 -0
@@ -39,6 +39,7 @@ SECTIONS
   .rodata    :
   {
     *(.rodata)
+    *(.rodata.*)
     *(.rodata1)
   }
   .kstrtab   : { *(.kstrtab) }
arch/s390/vmlinux.lds renamed from arch/s390/vmlinux.lds.jj +1 -1
@@ -14,7 +14,7 @@ SECTIONS
 	*(.gnu.warning)
 	} = 0x0700
   .text.lock : { *(.text.lock) }	/* out-of-line lock text */
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }
   .kstrtab : { *(.kstrtab) }
 
   . = ALIGN(16);		/* Exception table */
arch/s390x/vmlinux.lds renamed from arch/s390x/vmlinux.lds.jj +1 -1
@@ -14,7 +14,7 @@ SECTIONS
 	*(.gnu.warning)
 	} = 0x0700
   .text.lock : { *(.text.lock) }	/* out-of-line lock text */
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }
   .kstrtab : { *(.kstrtab) }
 
   . = ALIGN(16);		/* Exception table */
arch/sh/vmlinux.lds.S renamed from arch/sh/vmlinux.lds.S.jj +1 -1
@@ -24,7 +24,7 @@ SECTIONS
 	*(.gnu.warning)
 	} = 0x0009
   .text.lock : { *(.text.lock) }	/* out-of-line lock text */
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }
   .kstrtab : { *(.kstrtab) }
 
   . = ALIGN(16);		/* Exception table */
arch/sparc/vmlinux.lds renamed from arch/sparc/vmlinux.lds.jj +1 -1
@@ -12,7 +12,7 @@ SECTIONS
   } =0
   _etext = .;
   PROVIDE (etext = .);
-  .rodata    : { *(.rodata)  }
+  .rodata    : { *(.rodata) *(.rodata.*) }
   .rodata1   : { *(.rodata1) }
   .data    :
   {
arch/sparc64/vmlinux.lds renamed from arch/sparc64/vmlinux.lds.jj +1 -1
@@ -16,7 +16,7 @@ SECTIONS
   } =0
   _etext = .;
   PROVIDE (etext = .);
-  .rodata    : { *(.rodata)  }
+  .rodata    : { *(.rodata) *(.rodata.*) }
   .rodata1   : { *(.rodata1) }
   .data    :
   {

Jakub

#1 lore raw

Review

Quoted 4 lines · Jakub Jelinek

Apparently all kernel scripts only have .rodata and not also .rodata.* input sections in it.

(quoted diff) +1 -1
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }

Any reason not to use *(.rodata*) to cover all rodata sections? I see no need for two input definitions, one works for me.

#2 lore raw
In reply to Jakub Jelinek
Quoted 9 lines · Keith Owens

Review

Quoted 4 lines · Jakub Jelinek

Apparently all kernel scripts only have .rodata and not also .rodata.* input sections in it.

(quoted diff) +1 -1
-  .rodata : { *(.rodata) }
+  .rodata : { *(.rodata) *(.rodata.*) }

Any reason not to use *(.rodata*) to cover all rodata sections? I see no need for two input definitions, one works for me.

The reason why I wrote it this way is so that it matches default ld linker scripts:
...
.rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
...
Of course, *(.rodata*) would work as well and provided nobody creates sections like .rodatafoo, the behaviour would be the same as well.

Jakub