ia64/xen-unstable

changeset 8199:b21be984945a

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>
author kaf24@firebug.cl.cam.ac.uk
date Fri Dec 02 18:00:49 2005 +0100 (2005-12-02)
parents a9c35cd7e559
children 42d4059108d4
files xen/arch/x86/Makefile xen/arch/x86/boot/mkelf32.c xen/arch/x86/boot/x86_32.S xen/arch/x86/boot/x86_64.S xen/arch/x86/x86_32/xen.lds xen/arch/x86/x86_64/xen.lds
line diff
     1.1 --- a/xen/arch/x86/Makefile	Fri Dec 02 15:52:47 2005 +0000
     1.2 +++ b/xen/arch/x86/Makefile	Fri Dec 02 18:00:49 2005 +0100
     1.3 @@ -37,7 +37,8 @@ endif
     1.4  default: $(TARGET)
     1.5  
     1.6  $(TARGET): $(TARGET)-syms boot/mkelf32
     1.7 -	./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000
     1.8 +	./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \
     1.9 +	`nm $(TARGET)-syms | sort | tail -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'`
    1.10  
    1.11  $(CURDIR)/arch.o: $(OBJS)
    1.12  	$(LD) $(LDFLAGS) -r -o $@ $(OBJS)
     2.1 --- a/xen/arch/x86/boot/mkelf32.c	Fri Dec 02 15:52:47 2005 +0000
     2.2 +++ b/xen/arch/x86/boot/mkelf32.c	Fri Dec 02 18:00:49 2005 +0100
     2.3 @@ -222,6 +222,7 @@ static void do_read(int fd, void *data, 
     2.4  
     2.5  int main(int argc, char **argv)
     2.6  {
     2.7 +    u64        final_exec_addr;
     2.8      u32        loadbase, dat_siz, mem_siz;
     2.9      char      *inimage, *outimage;
    2.10      int        infd, outfd;
    2.11 @@ -234,15 +235,17 @@ int main(int argc, char **argv)
    2.12      Elf64_Ehdr in64_ehdr;
    2.13      Elf64_Phdr in64_phdr;
    2.14  
    2.15 -    if ( argc != 4 )
    2.16 +    if ( argc != 5 )
    2.17      {
    2.18 -        fprintf(stderr, "Usage: mkelf32 <in-image> <out-image> <load-base>\n");
    2.19 +        fprintf(stderr, "Usage: mkelf32 <in-image> <out-image> "
    2.20 +                "<load-base> <final-exec-addr>\n");
    2.21          return 1;
    2.22      }
    2.23  
    2.24      inimage  = argv[1];
    2.25      outimage = argv[2];
    2.26      loadbase = strtoul(argv[3], NULL, 16);
    2.27 +    final_exec_addr = strtoul(argv[4], NULL, 16);
    2.28  
    2.29      infd = open(inimage, O_RDONLY);
    2.30      if ( infd == -1 )
    2.31 @@ -286,7 +289,10 @@ int main(int argc, char **argv)
    2.32  
    2.33          (void)lseek(infd, in32_phdr.p_offset, SEEK_SET);
    2.34          dat_siz = (u32)in32_phdr.p_filesz;
    2.35 -        mem_siz = (u32)in32_phdr.p_memsz;
    2.36 +
    2.37 +        /* Do not use p_memsz: it does not include BSS alignment padding. */
    2.38 +        /*mem_siz = (u32)in32_phdr.p_memsz;*/
    2.39 +        mem_siz = (u32)(final_exec_addr - in32_phdr.p_vaddr);
    2.40          break;
    2.41  
    2.42      case ELFCLASS64:
    2.43 @@ -314,7 +320,10 @@ int main(int argc, char **argv)
    2.44  
    2.45          (void)lseek(infd, in64_phdr.p_offset, SEEK_SET);
    2.46          dat_siz = (u32)in64_phdr.p_filesz;
    2.47 -        mem_siz = (u32)in64_phdr.p_memsz;
    2.48 +
    2.49 +        /* Do not use p_memsz: it does not include BSS alignment padding. */
    2.50 +        /*mem_siz = (u32)in64_phdr.p_memsz;*/
    2.51 +        mem_siz = (u32)(final_exec_addr - in64_phdr.p_vaddr);
    2.52          break;
    2.53  
    2.54      default:
     3.1 --- a/xen/arch/x86/boot/x86_32.S	Fri Dec 02 15:52:47 2005 +0000
     3.2 +++ b/xen/arch/x86/boot/x86_32.S	Fri Dec 02 18:00:49 2005 +0100
     3.3 @@ -74,10 +74,6 @@ 1:      lss     stack_start-__PAGE_OFFSE
     3.4          cmp     $0x2BADB002,%eax
     3.5          jne     not_multiboot
     3.6  
     3.7 -        /* Save the Multiboot info structure for later use. */
     3.8 -	add     $__PAGE_OFFSET,%ebx
     3.9 -        push    %ebx
    3.10 -
    3.11          /* Initialize BSS (no nasty surprises!) */
    3.12          mov     $__bss_start-__PAGE_OFFSET,%edi
    3.13          mov     $_end-__PAGE_OFFSET,%ecx
    3.14 @@ -85,6 +81,10 @@ 1:      lss     stack_start-__PAGE_OFFSE
    3.15          xor     %eax,%eax
    3.16          rep     stosb
    3.17  
    3.18 +        /* Save the Multiboot info structure for later use. */
    3.19 +        add     $__PAGE_OFFSET,%ebx
    3.20 +        push    %ebx
    3.21 +
    3.22  #ifdef CONFIG_X86_PAE
    3.23          /* Initialize low and high mappings of all memory with 2MB pages */
    3.24          mov     $idle_pg_table_l2-__PAGE_OFFSET,%edi
    3.25 @@ -238,27 +238,28 @@ ENTRY(gdt_table)
    3.26          .fill 2*NR_CPUS,8,0          /* space for TSS and LDT per CPU    */
    3.27  
    3.28          .org 0x2000
    3.29 -/* Maximum STACK_ORDER for x86/32 is 1. We must therefore ensure that the */
    3.30 -/* CPU0 stack is aligned on an even page boundary!                        */
    3.31 -ENTRY(cpu0_stack)
    3.32 -        .org 0x2000 + STACK_SIZE
    3.33  
    3.34  #ifdef CONFIG_X86_PAE
    3.35 -
    3.36  ENTRY(idle_pg_table)
    3.37  ENTRY(idle_pg_table_l3)
    3.38          .quad 0x100000 + 0x2000 + STACK_SIZE + 1*PAGE_SIZE + 0x01
    3.39          .quad 0x100000 + 0x2000 + STACK_SIZE + 2*PAGE_SIZE + 0x01
    3.40          .quad 0x100000 + 0x2000 + STACK_SIZE + 3*PAGE_SIZE + 0x01
    3.41          .quad 0x100000 + 0x2000 + STACK_SIZE + 4*PAGE_SIZE + 0x01
    3.42 -        .org 0x2000 + STACK_SIZE + 1*PAGE_SIZE
    3.43 +.section ".bss.page_aligned","w"
    3.44  ENTRY(idle_pg_table_l2)
    3.45 -        .org 0x2000 + STACK_SIZE + 5*PAGE_SIZE
    3.46 -
    3.47 -#else /* CONFIG_X86_PAE */
    3.48 +        .fill 4*PAGE_SIZE,1,0
    3.49 +#else
    3.50 +.section ".bss.page_aligned","w"
    3.51 +ENTRY(idle_pg_table)
    3.52 +ENTRY(idle_pg_table_l2)
    3.53 +        .fill 1*PAGE_SIZE,1,0
    3.54 +#endif
    3.55  
    3.56 -ENTRY(idle_pg_table)
    3.57 -ENTRY(idle_pg_table_l2) # Initial page directory is 4kB
    3.58 -        .org 0x2000 + STACK_SIZE + PAGE_SIZE
    3.59 -
    3.60 -#endif /* CONFIG_X86_PAE */
    3.61 +#if (STACK_ORDER == 0)
    3.62 +.section ".bss.page_aligned","w"
    3.63 +#else
    3.64 +.section ".bss.twopage_aligned","w"
    3.65 +#endif
    3.66 +ENTRY(cpu0_stack)
    3.67 +        .fill STACK_SIZE,1,0
     4.1 --- a/xen/arch/x86/boot/x86_64.S	Fri Dec 02 15:52:47 2005 +0000
     4.2 +++ b/xen/arch/x86/boot/x86_64.S	Fri Dec 02 18:00:49 2005 +0100
     4.3 @@ -249,13 +249,8 @@ ENTRY(idle_pg_table_4)
     4.4  ENTRY(idle_pg_table_l3)
     4.5          .quad idle_pg_table_l2 - __PAGE_OFFSET + 7
     4.6  
     4.7 +/* Initial PDE -- level-2 page table. Maps first 64MB physical memory. */
     4.8          .org 0x4000
     4.9 -/* Maximum STACK_ORDER for x86/64 is 2. We must therefore ensure that the */
    4.10 -/* CPU0 stack is aligned on a 4-page boundary.                            */
    4.11 -ENTRY(cpu0_stack)
    4.12 -
    4.13 -/* Initial PDE -- level-2 page table. Maps first 64MB physical memory. */
    4.14 -        .org 0x4000 + STACK_SIZE
    4.15  ENTRY(idle_pg_table_l2)
    4.16          .macro identmap from=0, count=32
    4.17          .if \count-1
    4.18 @@ -265,7 +260,15 @@ ENTRY(idle_pg_table_l2)
    4.19          .quad 0x00000000000001e3 + \from
    4.20          .endif
    4.21          .endm
    4.22 -        identmap /* Too orangey for crows :-) */
    4.23 +        identmap
    4.24 +
    4.25 +        .org 0x4000 + PAGE_SIZE
    4.26 +        .code64
    4.27  
    4.28 -        .org 0x4000 + STACK_SIZE + PAGE_SIZE
    4.29 -        .code64
    4.30 +#if (STACK_ORDER == 0)
    4.31 +.section ".bss.page_aligned","w"
    4.32 +#else
    4.33 +.section ".bss.twopage_aligned","w"
    4.34 +#endif
    4.35 +ENTRY(cpu0_stack)
    4.36 +        .fill STACK_SIZE,1,0
     5.1 --- a/xen/arch/x86/x86_32/xen.lds	Fri Dec 02 15:52:47 2005 +0000
     5.2 +++ b/xen/arch/x86/x86_32/xen.lds	Fri Dec 02 18:00:49 2005 +0100
     5.3 @@ -23,7 +23,6 @@ SECTIONS
     5.4    _etext = .;			/* End of text section */
     5.5  
     5.6    .rodata : { *(.rodata) *(.rodata.*) } :text
     5.7 -  .kstrtab : { *(.kstrtab) } :text
     5.8  
     5.9    . = ALIGN(32);		/* Exception table */
    5.10    __start___ex_table = .;
    5.11 @@ -35,24 +34,11 @@ SECTIONS
    5.12    __pre_ex_table : { *(__pre_ex_table) } :text
    5.13    __stop___pre_ex_table = .;
    5.14  
    5.15 -  __start___ksymtab = .;	/* Kernel symbol table */
    5.16 -  __ksymtab : { *(__ksymtab) } :text
    5.17 -  __stop___ksymtab = .;
    5.18 -
    5.19 -  __start___kallsyms = .;	/* All kernel symbols */
    5.20 -  __kallsyms : { *(__kallsyms) } :text
    5.21 -  __stop___kallsyms = .;
    5.22 -
    5.23    .data : {			/* Data */
    5.24  	*(.data)
    5.25  	CONSTRUCTORS
    5.26  	} :text
    5.27  
    5.28 -  _edata = .;			/* End of data section */
    5.29 -
    5.30 -  . = ALIGN(8192);		/* init_task */
    5.31 -  .data.init_task : { *(.data.init_task) } :text
    5.32 -
    5.33    . = ALIGN(4096);		/* Init code and data */
    5.34    __init_begin = .;
    5.35    .text.init : { *(.text.init) } :text
    5.36 @@ -64,10 +50,13 @@ SECTIONS
    5.37    __initcall_start = .;
    5.38    .initcall.init : { *(.initcall.init) } :text
    5.39    __initcall_end = .;
    5.40 +  . = ALIGN(8192);
    5.41    __init_end = .;
    5.42  
    5.43    __bss_start = .;		/* BSS */
    5.44    .bss : {
    5.45 +	*(.bss.twopage_aligned)
    5.46 +	*(.bss.page_aligned)
    5.47  	*(.bss)
    5.48  	} :text
    5.49    _end = . ;
     6.1 --- a/xen/arch/x86/x86_64/xen.lds	Fri Dec 02 15:52:47 2005 +0000
     6.2 +++ b/xen/arch/x86/x86_64/xen.lds	Fri Dec 02 18:00:49 2005 +0100
     6.3 @@ -21,7 +21,6 @@ SECTIONS
     6.4    _etext = .;			/* End of text section */
     6.5  
     6.6    .rodata : { *(.rodata) *(.rodata.*) } :text
     6.7 -  .kstrtab : { *(.kstrtab) } :text
     6.8  
     6.9    . = ALIGN(32);		/* Exception table */
    6.10    __start___ex_table = .;
    6.11 @@ -33,24 +32,11 @@ SECTIONS
    6.12    __pre_ex_table : { *(__pre_ex_table) } :text
    6.13    __stop___pre_ex_table = .;
    6.14  
    6.15 -  __start___ksymtab = .;	/* Kernel symbol table */
    6.16 -  __ksymtab : { *(__ksymtab) } :text
    6.17 -  __stop___ksymtab = .;
    6.18 -
    6.19 -  __start___kallsyms = .;	/* All kernel symbols */
    6.20 -  __kallsyms : { *(__kallsyms) } :text
    6.21 -  __stop___kallsyms = .;
    6.22 -
    6.23    .data : {			/* Data */
    6.24  	*(.data)
    6.25  	CONSTRUCTORS
    6.26  	} :text
    6.27  
    6.28 -  _edata = .;			/* End of data section */
    6.29 -
    6.30 -  . = ALIGN(8192);		/* init_task */
    6.31 -  .data.init_task : { *(.data.init_task) } :text
    6.32 -
    6.33    . = ALIGN(4096);		/* Init code and data */
    6.34    __init_begin = .;
    6.35    .text.init : { *(.text.init) } :text
    6.36 @@ -62,10 +48,13 @@ SECTIONS
    6.37    __initcall_start = .;
    6.38    .initcall.init : { *(.initcall.init) } :text
    6.39    __initcall_end = .;
    6.40 +  . = ALIGN(8192);
    6.41    __init_end = .;
    6.42  
    6.43    __bss_start = .;		/* BSS */
    6.44    .bss : {
    6.45 +	*(.bss.twopage_aligned)
    6.46 +	*(.bss.page_aligned)
    6.47  	*(.bss)
    6.48  	} :text
    6.49    _end = . ;