[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[openrisc] Bug fixes for uClinux



Hallo,

I've detected some bugs on uClinux:

    (1) The elf loader always performs relocations for each relocation
    section found on the binary file, even when the section those
    relocations apply to was not loaded in the previous step. The patch
    I provide performs a check to prevent this.
    
    (2) The value of TSS in asm-or32 is 528 (look like it was taken from
    ppc port) but, in or1k, the offset of TSS field within task_struct
    is 536 (I have checked this using the standard toolchain as weel as
    my new compiler). The patch also fixes this.

    (3) The linker scripts in arch/or32/board do not explicitly align
    some sections, with consequent danger of alignment errors. In fact
    such errors arise when using the new compiler. I have added explicit
    alignment expressions, which do no harm when not needed, anyway.
    
The patch with all these fixes is attached.

Best regards!

        Carlos

diff -Naur uclinux.old/uClinux-2.0.x/arch/or32/board/ram.ld uclinux/uClinux-2.0.x/arch/or32/board/ram.ld
--- uclinux.old/uClinux-2.0.x/arch/or32/board/ram.ld	2002-08-19 19:42:31.000000000 +0200
+++ uclinux/uClinux-2.0.x/arch/or32/board/ram.ld	2003-06-20 10:45:46.000000000 +0200
@@ -29,7 +29,7 @@
         __etext = . ;
         ___data_rom_start = ALIGN ( 4 ) ;
         } > ram
-        .data :
+        .data ALIGN(4) :
         {
         __sdata = . ;
         ___data_start = . ;
@@ -38,7 +38,7 @@
         __end_data = . ;
         edata = ALIGN( 0x10 ) ;
         } > ram
-        .bss :
+        .bss ALIGN (0x10):
         {
         __sbss = ALIGN( 0x10 ) ;
         ___bss_start = ALIGN( 0x10 ) ;
diff -Naur uclinux.old/uClinux-2.0.x/arch/or32/board/rom.ld uclinux/uClinux-2.0.x/arch/or32/board/rom.ld
--- uclinux.old/uClinux-2.0.x/arch/or32/board/rom.ld	2003-05-06 04:46:31.000000000 +0200
+++ uclinux/uClinux-2.0.x/arch/or32/board/rom.ld	2003-06-20 10:45:40.000000000 +0200
@@ -23,19 +23,18 @@
         *(.text)
         } > flash
 
-        .rodata :
+        .rodata ALIGN (8):
         {
         *(.rodata)
 	*(.rodata.*)
         __etext = . ;
         } > flash
 
-        .initrd :
+        .initrd ALIGN (8):
         {
         __initrd_start = . ;
         *(.initrd)
         __initrd_end = . ;
-        ___data_rom_start = . ;
         } > flash
 
         .eflash :
@@ -44,7 +43,7 @@
         } > eflash
 
         .data :
-        AT ( ADDR (.initrd) + SIZEOF (.initrd))
+	AT (( ADDR (.initrd) + SIZEOF (.initrd) + 8 - 1) & ~(8 - 1))
         {
         __ramstart = . ;
         __sdata = . ;
@@ -55,11 +54,12 @@
         __data_end = . ;
         edata = ALIGN( 0x10 ) ;
         } > ram
+	___data_rom_start = LOADADDR (.data);
 
-        .bss :
+        .bss ALIGN (0x10):
         {
-        __sbss = ALIGN( 0x10 ) ;
-        ___bss_start = ALIGN( 0x10 ) ;
+        __sbss = . ;
+        ___bss_start = . ;
         *(.bss)
         *(COMMON)
         __ebss = . ;
@@ -69,7 +69,7 @@
         } > ram
 
         .ramvec :
-        AT ( ADDR (.initrd) + SIZEOF (.initrd) + SIZEOF (.data))
+	AT ( LOADADDR (.data) + SIZEOF (.data))
         {
         __ramvec_start = . ;
         *(.ramvec)
diff -Naur uclinux.old/uClinux-2.0.x/fs/binfmt_elf.c uclinux/uClinux-2.0.x/fs/binfmt_elf.c
--- uclinux.old/uClinux-2.0.x/fs/binfmt_elf.c	2002-05-14 01:19:32.000000000 +0200
+++ uclinux/uClinux-2.0.x/fs/binfmt_elf.c	2003-06-20 10:46:33.000000000 +0200
@@ -593,15 +593,19 @@
 			   real setiona hader info field. */
 
 			rel_nb = sec[rel_indx].len / sizeof(struct elf32_rel);
-			retval = do_relocate(elf_spnt->sh_info, rel_nb, rel_ptr, sym_ptr,  sec);
-
-			if (retval < 0) {
-                                for(j = 0; j < elf_ex.e_shnum; j++)
-                                        if(sec[j].len)
-                                                do_munmap(sec[j].pm_add, sec[j].len);
-				do_munmap(code_start, code_len + code_len + bss_len + stack_len);
-                                kfree(elf_shdata);
-                                return retval;
+			/* Check if section to relocate was allocated first */
+		 	if ((elf_shdata + elf_spnt->sh_info)->sh_flags & SHF_ALLOC) {
+				retval = do_relocate(elf_spnt->sh_info, rel_nb, rel_ptr, sym_ptr,  sec);
+
+				if (retval < 0) {
+        	                        for(j = 0; j < elf_ex.e_shnum; j++)
+                	                        if(sec[j].len)
+                        	                        do_munmap(sec[j].pm_add, sec[j].len);
+					do_munmap(code_start, code_len + code_len + bss_len + stack_len);
+	                                kfree(elf_shdata);
+        	                        return retval;
+				}
+			
                         }
 
 			/* Now unmap rel section */
diff -Naur uclinux.old/uClinux-2.0.x/include/asm-or32/ptrace.h uclinux/uClinux-2.0.x/include/asm-or32/ptrace.h
--- uclinux.old/uClinux-2.0.x/include/asm-or32/ptrace.h	2002-02-19 16:40:18.000000000 +0100
+++ uclinux/uClinux-2.0.x/include/asm-or32/ptrace.h	2003-06-20 10:47:16.000000000 +0200
@@ -8,7 +8,7 @@
 #define SIGNAL 		12
 #define BLOCKED 	16
 #define TASK_FLAGS 	20
-#define TSS 		528
+#define TSS 		536
 #define TSS_PC 		0
 #define TSS_SR 		4
 #define TSS_KSP 	8

Esta parte del mensaje esta firmada digitalmente