public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@in.ibm.com>
To: linux kernel mailing list <linux-kernel@vger.kernel.org>
Cc: Reloc Kernel List <fastboot@lists.osdl.org>,
	ebiederm@xmission.com, akpm@osdl.org, ak@suse.de,
	horms@verge.net.au, lace@jankratochvil.net, hpa@zytor.com,
	magnus.damm@gmail.com, lwang@redhat.com, dzickus@redhat.com,
	maneesh@in.ibm.com
Subject: [PATCH 1/12] i386: Distinguish absolute symbols
Date: Tue, 3 Oct 2006 13:04:13 -0400	[thread overview]
Message-ID: <20061003170413.GA3164@in.ibm.com> (raw)
In-Reply-To: <20061003170032.GA30036@in.ibm.com>



Ld knows about 2 kinds of symbols,  absolute and section
relative.  Section relative symbols symbols change value
when a section is moved and absolute symbols do not.

Currently in the linker script we have several labels
marking the beginning and ending of sections that
are outside of sections, making them absolute symbols.
Having a mixture of absolute and section relative
symbols refereing to the same data is currently harmless
but it is confusing.

This must be done carefully as newer revs of ld do not place
symbols that appear in sections without data and instead
ld makes those symbols global :(

My ultimate goal is to build a relocatable kernel.  The
safest and least intrusive technique is to generate
relocation entries so the kernel can be relocated at load
time.  The only penalty would be an increase in the size
of the kernel binary.  The problem is that if absolute and
relocatable symbols are not properly specified absolute symbols
will be relocated or section relative symbols won't be, which
is fatal.

The practical motivation is that when generating kernels that
will run from a reserved area for analyzing what caused
a kernel panic, it is simpler if you don't need to hard code
the physical memory location they will run at, especially
for the distributions.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Vivek Goyal <vgoyal@in.ibm.com>
---

 arch/i386/kernel/vmlinux.lds.S    |  109 ++++++++++++++++++++------------------
 include/asm-generic/vmlinux.lds.h |    4 -
 2 files changed, 60 insertions(+), 53 deletions(-)

diff -puN arch/i386/kernel/vmlinux.lds.S~i386-vmlinux.lds.S-Distinguish-absolute-symbols arch/i386/kernel/vmlinux.lds.S
--- linux-2.6.18-git17/arch/i386/kernel/vmlinux.lds.S~i386-vmlinux.lds.S-Distinguish-absolute-symbols	2006-10-02 13:17:58.000000000 -0400
+++ linux-2.6.18-git17-root/arch/i386/kernel/vmlinux.lds.S	2006-10-02 14:38:44.000000000 -0400
@@ -24,31 +24,32 @@ SECTIONS
   . = __KERNEL_START;
   phys_startup_32 = startup_32 - LOAD_OFFSET;
   /* read-only */
-  _text = .;			/* Text and read-only data */
   .text : AT(ADDR(.text) - LOAD_OFFSET) {
+  	_text = .;			/* Text and read-only data */
 	*(.text)
 	SCHED_TEXT
 	LOCK_TEXT
 	KPROBES_TEXT
 	*(.fixup)
 	*(.gnu.warning)
-	} :text = 0x9090
-
-  _etext = .;			/* End of text section */
+  	_etext = .;			/* End of text section */
+  } :text = 0x9090
 
   . = ALIGN(16);		/* Exception table */
-  __start___ex_table = .;
-  __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { *(__ex_table) }
-  __stop___ex_table = .;
+  __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
+  	__start___ex_table = .;
+	 *(__ex_table)
+  	__stop___ex_table = .;
+  }
 
   RODATA
 
   . = ALIGN(4);
-  __tracedata_start = .;
   .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) {
+  	__tracedata_start = .;
 	*(.tracedata)
+  	__tracedata_end = .;
   }
-  __tracedata_end = .;
 
   /* writeable */
   .data : AT(ADDR(.data) - LOAD_OFFSET) {	/* Data */
@@ -57,10 +58,12 @@ SECTIONS
 	} :data
 
   . = ALIGN(4096);
-  __nosave_begin = .;
-  .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
-  . = ALIGN(4096);
-  __nosave_end = .;
+  .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
+  	__nosave_begin = .;
+	*(.data.nosave)
+  	. = ALIGN(4096);
+  	__nosave_end = .;
+  }
 
   . = ALIGN(4096);
   .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
@@ -74,8 +77,10 @@ SECTIONS
 
   /* rarely changed data like cpu maps */
   . = ALIGN(32);
-  .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) { *(.data.read_mostly) }
-  _edata = .;			/* End of data section */
+  .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
+	*(.data.read_mostly)
+	_edata = .;		/* End of data section */
+  }
 
 #ifdef CONFIG_STACK_UNWIND
   . = ALIGN(4);
@@ -93,39 +98,41 @@ SECTIONS
 
   /* might get freed after init */
   . = ALIGN(4096);
-  __smp_alt_begin = .;
-  __smp_alt_instructions = .;
   .smp_altinstructions : AT(ADDR(.smp_altinstructions) - LOAD_OFFSET) {
+	__smp_alt_begin = .;
+	__smp_alt_instructions = .;
 	*(.smp_altinstructions)
+	__smp_alt_instructions_end = .;
   }
-  __smp_alt_instructions_end = .;
   . = ALIGN(4);
-  __smp_locks = .;
   .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
+	__smp_locks = .;
 	*(.smp_locks)
+	__smp_locks_end = .;
   }
-  __smp_locks_end = .;
   .smp_altinstr_replacement : AT(ADDR(.smp_altinstr_replacement) - LOAD_OFFSET) {
 	*(.smp_altinstr_replacement)
+	. = ALIGN(4096);
+	__smp_alt_end = .;
   }
-  . = ALIGN(4096);
-  __smp_alt_end = .;
 
   /* will be freed after init */
   . = ALIGN(4096);		/* Init code and data */
-  __init_begin = .;
   .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
+  	__init_begin = .;
 	_sinittext = .;
 	*(.init.text)
 	_einittext = .;
   }
   .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { *(.init.data) }
   . = ALIGN(16);
-  __setup_start = .;
-  .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { *(.init.setup) }
-  __setup_end = .;
-  __initcall_start = .;
+  .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
+	__setup_start = .;
+	*(.init.setup)
+	__setup_end = .;
+  }
   .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
+	__initcall_start = .;
 	*(.initcall1.init) 
 	*(.initcall2.init) 
 	*(.initcall3.init) 
@@ -133,20 +140,20 @@ SECTIONS
 	*(.initcall5.init) 
 	*(.initcall6.init) 
 	*(.initcall7.init)
+	__initcall_end = .;
   }
-  __initcall_end = .;
-  __con_initcall_start = .;
   .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
+	__con_initcall_start = .;
 	*(.con_initcall.init)
+	__con_initcall_end = .;
   }
-  __con_initcall_end = .;
   SECURITY_INIT
   . = ALIGN(4);
-  __alt_instructions = .;
   .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
+	__alt_instructions = .;
 	*(.altinstructions)
+	__alt_instructions_end = .;
   }
-  __alt_instructions_end = .; 
   .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
 	*(.altinstr_replacement)
   }
@@ -155,32 +162,32 @@ SECTIONS
   .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) { *(.exit.text) }
   .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) { *(.exit.data) }
   . = ALIGN(4096);
-  __initramfs_start = .;
-  .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { *(.init.ramfs) }
-  __initramfs_end = .;
+  .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
+	__initramfs_start = .;
+	*(.init.ramfs)
+	__initramfs_end = .;
+  }
   . = ALIGN(L1_CACHE_BYTES);
-  __per_cpu_start = .;
-  .data.percpu  : AT(ADDR(.data.percpu) - LOAD_OFFSET) { *(.data.percpu) }
-  __per_cpu_end = .;
+  .data.percpu  : AT(ADDR(.data.percpu) - LOAD_OFFSET) {
+	__per_cpu_start = .;
+	*(.data.percpu)
+	__per_cpu_end = .;
+  }
   . = ALIGN(4096);
-  __init_end = .;
   /* freed after init ends here */
 	
-  __bss_start = .;		/* BSS */
-  .bss.page_aligned : AT(ADDR(.bss.page_aligned) - LOAD_OFFSET) {
-	*(.bss.page_aligned)
-  }
   .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
+	__init_end = .;
+	__bss_start = .;		/* BSS */
+	*(.bss.page_aligned)
 	*(.bss)
+	. = ALIGN(4);
+	__bss_stop = .;
+  	_end = . ;
+	/* This is where the kernel creates the early boot page tables */
+	. = ALIGN(4096);
+	pg0 = . ;
   }
-  . = ALIGN(4);
-  __bss_stop = .; 
-
-  _end = . ;
-
-  /* This is where the kernel creates the early boot page tables */
-  . = ALIGN(4096);
-  pg0 = .;
 
   /* Sections to be discarded */
   /DISCARD/ : {
diff -puN include/asm-generic/vmlinux.lds.h~i386-vmlinux.lds.S-Distinguish-absolute-symbols include/asm-generic/vmlinux.lds.h
--- linux-2.6.18-git17/include/asm-generic/vmlinux.lds.h~i386-vmlinux.lds.S-Distinguish-absolute-symbols	2006-10-02 13:17:58.000000000 -0400
+++ linux-2.6.18-git17-root/include/asm-generic/vmlinux.lds.h	2006-10-02 13:17:58.000000000 -0400
@@ -11,8 +11,8 @@
 
 #define RODATA								\
 	. = ALIGN(4096);						\
-	__start_rodata = .;						\
 	.rodata           : AT(ADDR(.rodata) - LOAD_OFFSET) {		\
+		VMLINUX_SYMBOL(__start_rodata) = .;			\
 		*(.rodata) *(.rodata.*)					\
 		*(__vermagic)		/* Kernel version magic */	\
 	}								\
@@ -124,8 +124,8 @@
 		VMLINUX_SYMBOL(__start___param) = .;			\
 		*(__param)						\
 		VMLINUX_SYMBOL(__stop___param) = .;			\
+		VMLINUX_SYMBOL(__end_rodata) = .;			\
 	}								\
-	__end_rodata = .;						\
 	. = ALIGN(4096);
 
 #define SECURITY_INIT							\
_

  reply	other threads:[~2006-10-03 17:31 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-03 17:00 [RFC][PATCH 0/12] ELF Relocatable x86 bzImage (V2) Vivek Goyal
2006-10-03 17:04 ` Vivek Goyal [this message]
2006-10-07  6:35   ` [PATCH 1/12] i386: Distinguish absolute symbols Andrew Morton
2006-10-08 16:47     ` Vivek Goyal
2006-10-09  7:35       ` Gerd Hoffmann
2006-10-09 13:49         ` Vivek Goyal
2006-10-03 17:06 ` [PATCH 2/12] i386: align data section to 4K boundary Vivek Goyal
2006-10-04 11:17   ` Andi Kleen
2006-10-04 15:18     ` H. Peter Anvin
2006-10-03 17:09 ` [PATCH 3/12] i386: Force section size to be non-zero to prevent a symbol becoming absolute Vivek Goyal
2006-10-04 11:02   ` Andi Kleen
2006-10-04 14:07     ` Eric W. Biederman
2006-10-04 14:45       ` Vivek Goyal
2006-10-04 16:09   ` Andrew Morton
2006-10-04 16:14     ` Vivek Goyal
2006-10-03 17:10 ` [PATCH 4/12] i386: define __pa_symbol() Vivek Goyal
2006-10-04  8:26   ` Franck Bui-Huu
2006-10-04 19:44     ` Vivek Goyal
2006-10-06 13:10       ` Franck Bui-Huu
2006-10-06 18:33         ` Vivek Goyal
2006-10-03 17:12 ` [PATCH 5/12] i386 setup.c: Reserve kernel memory starting from _text Vivek Goyal
2006-10-03 17:15 ` [PATCH 6/12] i386: CONFIG_PHYSICAL_START cleanup Vivek Goyal
2006-10-03 18:45   ` Dave Hansen
2006-10-03 18:52     ` Vivek Goyal
2006-10-03 18:59     ` Eric W. Biederman
2006-10-03 19:35       ` Vivek Goyal
2006-10-03 17:17 ` [PATCH 7/12] Make linux/elf.h safe to be included in assembly files Vivek Goyal
2006-10-03 17:19 ` [PATCH 8/12] elf: Add ELFOSABI_STANDALONE to elf.h Vivek Goyal
2006-10-03 17:21 ` [PATCH 9/12] kallsyms: Generate relocatable symbols Vivek Goyal
2006-10-03 17:22 ` [PATCH 10/12] i386: Relocatable kernel support Vivek Goyal
2006-10-03 17:24 ` [PATCH 11/12] i386: Implement CONFIG_PHYSICAL_ALIGN Vivek Goyal
2006-10-03 17:25 ` [PATCH 12/12] i386 boot: Add an ELF header to bzImage Vivek Goyal
2006-10-04  3:13   ` Andrew Morton
2006-10-04  4:28     ` Vivek Goyal
2006-10-04  4:40       ` H. Peter Anvin
2006-10-04  8:04         ` Eric W. Biederman
2006-10-04 15:18           ` H. Peter Anvin
2006-10-05  4:12             ` Eric W. Biederman
2006-10-05  4:17               ` H. Peter Anvin
2006-10-04 20:22         ` Vivek Goyal
2006-10-04 20:27           ` H. Peter Anvin
2006-10-04 20:48             ` Vivek Goyal
2006-10-04 20:52               ` H. Peter Anvin
2006-10-04 21:06                 ` Vivek Goyal
2006-10-04 21:09                   ` H. Peter Anvin
2006-10-04  5:37       ` Andrew Morton
2006-10-05  4:06     ` Eric W. Biederman
2006-10-05  4:12       ` H. Peter Anvin
2006-10-05  4:44       ` Andrew Morton
2006-10-05  6:13         ` Eric W. Biederman
2006-10-05  6:31           ` Andrew Morton
2006-10-05  6:48             ` Eric W. Biederman
2006-10-05 21:54               ` Vivek Goyal
2006-10-05 15:25             ` H. Peter Anvin
2006-10-05 15:35               ` Eric W. Biederman
2006-10-05 15:29             ` Eric W. Biederman
2006-10-05 15:44               ` H. Peter Anvin
2006-10-06  6:59               ` Andrew Morton
2006-10-06 12:56                 ` Eric W. Biederman
2006-10-06 18:38                   ` Vivek Goyal
2006-10-06 18:54                     ` H. Peter Anvin
2006-10-06 19:09                       ` Eric W. Biederman
2006-10-06 21:54                         ` H. Peter Anvin
2006-10-09 14:33                           ` Vivek Goyal
2006-10-10  3:14                             ` Andrew Morton
2006-10-10  4:51                               ` Eric W. Biederman
2006-10-10 14:30                               ` Vivek Goyal
2006-10-10 18:46                                 ` Andrew Morton
2006-10-10 21:40                               ` Vivek Goyal
2006-10-11  2:35                                 ` Andrew Morton
2006-10-06 19:01                     ` Eric W. Biederman
2006-10-04  7:08   ` Eric W. Biederman
2006-10-04 14:23     ` Vivek Goyal
2006-10-05  3:09       ` Eric W. Biederman
2006-10-04 17:03     ` Vivek Goyal
2006-10-05  6:25       ` Eric W. Biederman
2006-10-05 21:34         ` Vivek Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061003170413.GA3164@in.ibm.com \
    --to=vgoyal@in.ibm.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=dzickus@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=fastboot@lists.osdl.org \
    --cc=horms@verge.net.au \
    --cc=hpa@zytor.com \
    --cc=lace@jankratochvil.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lwang@redhat.com \
    --cc=magnus.damm@gmail.com \
    --cc=maneesh@in.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox