diff options
author | kaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk> | 2005-12-02 18:00:49 +0100 |
---|---|---|
committer | kaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk> | 2005-12-02 18:00:49 +0100 |
commit | 773ded42218d434302b31aa4501649534c62e6d0 (patch) | |
tree | d1ef2697f559ee16b2ba5135ed98eae906997866 | |
parent | 9b08b0371d509d9465bacb4dd14fc99b01183d02 (diff) | |
download | xen-773ded42218d434302b31aa4501649534c62e6d0.tar.gz xen-773ded42218d434302b31aa4501649534c62e6d0.tar.bz2 xen-773ded42218d434302b31aa4501649534c62e6d0.zip |
Move cpu0_stack out of Xen text section and into BSS. This
avoids getting loads of bogus cpu0_stack lines in call
backtraces from non-debug builds.
Doing this requires greater alignment of the BSS section,
which reveals a bug in ld where the alignment padding is
not added to the program segment's memsz field. We get around
this by finding the address of the last symbol in the image,
and increasing our load image's memsz to include that symbol.
Also some cleanups to the linker scripts.
Signed-off-by: Keir Fraser <keir@xensource.com>
-rw-r--r-- | xen/arch/x86/Makefile | 3 | ||||
-rw-r--r-- | xen/arch/x86/boot/mkelf32.c | 17 | ||||
-rw-r--r-- | xen/arch/x86/boot/x86_32.S | 35 | ||||
-rw-r--r-- | xen/arch/x86/boot/x86_64.S | 19 | ||||
-rw-r--r-- | xen/arch/x86/x86_32/xen.lds | 17 | ||||
-rw-r--r-- | xen/arch/x86/x86_64/xen.lds | 17 |
6 files changed, 50 insertions, 58 deletions
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index ecd0b64e68..952327cc16 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -37,7 +37,8 @@ endif default: $(TARGET) $(TARGET): $(TARGET)-syms boot/mkelf32 - ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 + ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ + `nm $(TARGET)-syms | sort | tail -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` $(CURDIR)/arch.o: $(OBJS) $(LD) $(LDFLAGS) -r -o $@ $(OBJS) diff --git a/xen/arch/x86/boot/mkelf32.c b/xen/arch/x86/boot/mkelf32.c index 8fb665e068..e93dfdcf96 100644 --- a/xen/arch/x86/boot/mkelf32.c +++ b/xen/arch/x86/boot/mkelf32.c @@ -222,6 +222,7 @@ static void do_read(int fd, void *data, int len) int main(int argc, char **argv) { + u64 final_exec_addr; u32 loadbase, dat_siz, mem_siz; char *inimage, *outimage; int infd, outfd; @@ -234,15 +235,17 @@ int main(int argc, char **argv) Elf64_Ehdr in64_ehdr; Elf64_Phdr in64_phdr; - if ( argc != 4 ) + if ( argc != 5 ) { - fprintf(stderr, "Usage: mkelf32 <in-image> <out-image> <load-base>\n"); + fprintf(stderr, "Usage: mkelf32 <in-image> <out-image> " + "<load-base> <final-exec-addr>\n"); return 1; } inimage = argv[1]; outimage = argv[2]; loadbase = strtoul(argv[3], NULL, 16); + final_exec_addr = strtoul(argv[4], NULL, 16); infd = open(inimage, O_RDONLY); if ( infd == -1 ) @@ -286,7 +289,10 @@ int main(int argc, char **argv) (void)lseek(infd, in32_phdr.p_offset, SEEK_SET); dat_siz = (u32)in32_phdr.p_filesz; - mem_siz = (u32)in32_phdr.p_memsz; + + /* Do not use p_memsz: it does not include BSS alignment padding. */ + /*mem_siz = (u32)in32_phdr.p_memsz;*/ + mem_siz = (u32)(final_exec_addr - in32_phdr.p_vaddr); break; case ELFCLASS64: @@ -314,7 +320,10 @@ int main(int argc, char **argv) (void)lseek(infd, in64_phdr.p_offset, SEEK_SET); dat_siz = (u32)in64_phdr.p_filesz; - mem_siz = (u32)in64_phdr.p_memsz; + + /* Do not use p_memsz: it does not include BSS alignment padding. */ + /*mem_siz = (u32)in64_phdr.p_memsz;*/ + mem_siz = (u32)(final_exec_addr - in64_phdr.p_vaddr); break; default: diff --git a/xen/arch/x86/boot/x86_32.S b/xen/arch/x86/boot/x86_32.S index ca0c43555a..3294b7351a 100644 --- a/xen/arch/x86/boot/x86_32.S +++ b/xen/arch/x86/boot/x86_32.S @@ -74,10 +74,6 @@ __start: cmp $0x2BADB002,%eax jne not_multiboot - /* Save the Multiboot info structure for later use. */ - add $__PAGE_OFFSET,%ebx - push %ebx - /* Initialize BSS (no nasty surprises!) */ mov $__bss_start-__PAGE_OFFSET,%edi mov $_end-__PAGE_OFFSET,%ecx @@ -85,6 +81,10 @@ __start: xor %eax,%eax rep stosb + /* Save the Multiboot info structure for later use. */ + add $__PAGE_OFFSET,%ebx + push %ebx + #ifdef CONFIG_X86_PAE /* Initialize low and high mappings of all memory with 2MB pages */ mov $idle_pg_table_l2-__PAGE_OFFSET,%edi @@ -238,27 +238,28 @@ ENTRY(gdt_table) .fill 2*NR_CPUS,8,0 /* space for TSS and LDT per CPU */ .org 0x2000 -/* Maximum STACK_ORDER for x86/32 is 1. We must therefore ensure that the */ -/* CPU0 stack is aligned on an even page boundary! */ -ENTRY(cpu0_stack) - .org 0x2000 + STACK_SIZE #ifdef CONFIG_X86_PAE - ENTRY(idle_pg_table) ENTRY(idle_pg_table_l3) .quad 0x100000 + 0x2000 + STACK_SIZE + 1*PAGE_SIZE + 0x01 .quad 0x100000 + 0x2000 + STACK_SIZE + 2*PAGE_SIZE + 0x01 .quad 0x100000 + 0x2000 + STACK_SIZE + 3*PAGE_SIZE + 0x01 .quad 0x100000 + 0x2000 + STACK_SIZE + 4*PAGE_SIZE + 0x01 - .org 0x2000 + STACK_SIZE + 1*PAGE_SIZE +.section ".bss.page_aligned","w" ENTRY(idle_pg_table_l2) - .org 0x2000 + STACK_SIZE + 5*PAGE_SIZE - -#else /* CONFIG_X86_PAE */ - + .fill 4*PAGE_SIZE,1,0 +#else +.section ".bss.page_aligned","w" ENTRY(idle_pg_table) -ENTRY(idle_pg_table_l2) # Initial page directory is 4kB - .org 0x2000 + STACK_SIZE + PAGE_SIZE +ENTRY(idle_pg_table_l2) + .fill 1*PAGE_SIZE,1,0 +#endif -#endif /* CONFIG_X86_PAE */ +#if (STACK_ORDER == 0) +.section ".bss.page_aligned","w" +#else +.section ".bss.twopage_aligned","w" +#endif +ENTRY(cpu0_stack) + .fill STACK_SIZE,1,0 diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S index fbe5311124..126850a0f8 100644 --- a/xen/arch/x86/boot/x86_64.S +++ b/xen/arch/x86/boot/x86_64.S @@ -249,13 +249,8 @@ ENTRY(idle_pg_table_4) ENTRY(idle_pg_table_l3) .quad idle_pg_table_l2 - __PAGE_OFFSET + 7 - .org 0x4000 -/* Maximum STACK_ORDER for x86/64 is 2. We must therefore ensure that the */ -/* CPU0 stack is aligned on a 4-page boundary. */ -ENTRY(cpu0_stack) - /* Initial PDE -- level-2 page table. Maps first 64MB physical memory. */ - .org 0x4000 + STACK_SIZE + .org 0x4000 ENTRY(idle_pg_table_l2) .macro identmap from=0, count=32 .if \count-1 @@ -265,7 +260,15 @@ ENTRY(idle_pg_table_l2) .quad 0x00000000000001e3 + \from .endif .endm - identmap /* Too orangey for crows :-) */ + identmap - .org 0x4000 + STACK_SIZE + PAGE_SIZE + .org 0x4000 + PAGE_SIZE .code64 + +#if (STACK_ORDER == 0) +.section ".bss.page_aligned","w" +#else +.section ".bss.twopage_aligned","w" +#endif +ENTRY(cpu0_stack) + .fill STACK_SIZE,1,0 diff --git a/xen/arch/x86/x86_32/xen.lds b/xen/arch/x86/x86_32/xen.lds index fec62dbf24..f3c168f662 100644 --- a/xen/arch/x86/x86_32/xen.lds +++ b/xen/arch/x86/x86_32/xen.lds @@ -23,7 +23,6 @@ SECTIONS _etext = .; /* End of text section */ .rodata : { *(.rodata) *(.rodata.*) } :text - .kstrtab : { *(.kstrtab) } :text . = ALIGN(32); /* Exception table */ __start___ex_table = .; @@ -35,24 +34,11 @@ SECTIONS __pre_ex_table : { *(__pre_ex_table) } :text __stop___pre_ex_table = .; - __start___ksymtab = .; /* Kernel symbol table */ - __ksymtab : { *(__ksymtab) } :text - __stop___ksymtab = .; - - __start___kallsyms = .; /* All kernel symbols */ - __kallsyms : { *(__kallsyms) } :text - __stop___kallsyms = .; - .data : { /* Data */ *(.data) CONSTRUCTORS } :text - _edata = .; /* End of data section */ - - . = ALIGN(8192); /* init_task */ - .data.init_task : { *(.data.init_task) } :text - . = ALIGN(4096); /* Init code and data */ __init_begin = .; .text.init : { *(.text.init) } :text @@ -64,10 +50,13 @@ SECTIONS __initcall_start = .; .initcall.init : { *(.initcall.init) } :text __initcall_end = .; + . = ALIGN(8192); __init_end = .; __bss_start = .; /* BSS */ .bss : { + *(.bss.twopage_aligned) + *(.bss.page_aligned) *(.bss) } :text _end = . ; diff --git a/xen/arch/x86/x86_64/xen.lds b/xen/arch/x86/x86_64/xen.lds index 30a2b0ca67..837d335f0d 100644 --- a/xen/arch/x86/x86_64/xen.lds +++ b/xen/arch/x86/x86_64/xen.lds @@ -21,7 +21,6 @@ SECTIONS _etext = .; /* End of text section */ .rodata : { *(.rodata) *(.rodata.*) } :text - .kstrtab : { *(.kstrtab) } :text . = ALIGN(32); /* Exception table */ __start___ex_table = .; @@ -33,24 +32,11 @@ SECTIONS __pre_ex_table : { *(__pre_ex_table) } :text __stop___pre_ex_table = .; - __start___ksymtab = .; /* Kernel symbol table */ - __ksymtab : { *(__ksymtab) } :text - __stop___ksymtab = .; - - __start___kallsyms = .; /* All kernel symbols */ - __kallsyms : { *(__kallsyms) } :text - __stop___kallsyms = .; - .data : { /* Data */ *(.data) CONSTRUCTORS } :text - _edata = .; /* End of data section */ - - . = ALIGN(8192); /* init_task */ - .data.init_task : { *(.data.init_task) } :text - . = ALIGN(4096); /* Init code and data */ __init_begin = .; .text.init : { *(.text.init) } :text @@ -62,10 +48,13 @@ SECTIONS __initcall_start = .; .initcall.init : { *(.initcall.init) } :text __initcall_end = .; + . = ALIGN(8192); __init_end = .; __bss_start = .; /* BSS */ .bss : { + *(.bss.twopage_aligned) + *(.bss.page_aligned) *(.bss) } :text _end = . ; |