Skip to contentSkip to conversation

Valid relocation symbol for FLAT format on ARM

PATCH In review Jun Sun 2 participants 3 messages Dec 26, 2009 – Jan 1, 2010

Subsystems (3)
lore
Share & tools
lore

Jun Sun

author
#0 lore raw

PATCH 1/1 Valid relocation symbol for FLAT format on ARM

Apparently newer GCC would generate ANCHOR symbols beyond the end of data/bss segment on ARM CPUs. As a result, the exiting validity checking for relocation symbols in FLAT format will fail.

This also fixes a cosmetic error in printk. Text segment and data/bss segment are allocated from two different areas. It is not meaningful to give the diff between them in error reporting messages.

arch/arm/include/asm/flat.h renamed from arch/arm/include/asm/flat.h.orig +6 -1
diff -Nru linux-2.6.32.2/arch/arm/include/asm/flat.h.orig linux-2.6.32.2/arch/arm/include/asm/flat.h
@@ -7,7 +7,12 @@
 
 #define	flat_argvp_envp_on_stack()		1
 #define	flat_old_ram_flag(flags)		(flags)
-#define	flat_reloc_valid(reloc, size)		((reloc) <= (size))
+#define	flat_reloc_valid(reloc, size)		((reloc) <= (size) + 0x1000)
+/* [JSUN] new gcc 4.x generates ANCHOR symbols in order to reduce the size
+ * of GOT table for PIC code. It is possible the ANCHOR is placed beyond
+ * the end of data/bss segment up to 4K bytes(12 bits), because ARM allows
+ * negative 12-bit offset. Thus we allow 0x1000 extra in reloc address range.
+ */
 #define	flat_get_addr_from_rp(rp, relval, flags, persistent) get_unaligned(rp)
 #define	flat_put_addr_at_rp(rp, val, relval)	put_unaligned(val,rp)
 #define	flat_get_relocate_addr(rel)		(rel)
fs/binfmt_flat.c renamed from fs/binfmt_flat.c.orig +1 -1
diff -Nru linux-2.6.32.2/fs/binfmt_flat.c.orig linux-2.6.32.2/fs/binfmt_flat.c
@@ -355,7 +355,7 @@
 
 	if (!flat_reloc_valid(r, start_brk - start_data + text_len)) {
 		printk("BINFMT_FLAT: reloc outside program 0x%x (0 - 0x%x/0x%x)",
-		       (int) r,(int)(start_brk-start_code),(int)text_len);
+		       (int) r,(int)(start_brk-start_data+text_len),(int)text_len);
 		goto failed;
 	}
 
#1 lore raw
Quoted 11 lines · Jun Sun

Apparently newer GCC would generate ANCHOR symbols beyond the end of data/bss segment on ARM CPUs. As a result, the exiting validity checking for relocation symbols in FLAT format will fail.

This also fixes a cosmetic error in printk. Text segment and data/bss segment are allocated from two different areas. It is not meaningful to give the diff between them in error reporting messages.

diff -Nru linux-2.6.32.2/arch/arm/include/asm/flat.h.orig linux-2.6.32.2/arch/arm/include/asm/flat.h

you really should use git to generate the patch. if you're going to do it by hand, you need to format it correctly. you're missing the --- marker between your change log and the start of the patch.

fs/binfmt_flat.c line 360

Quoted 10 lines
fs/binfmt_flat.c +1 -1
@@ -355,7 +355,7 @@
 
        if (!flat_reloc_valid(r, start_brk - start_data + text_len)) {
                printk("BINFMT_FLAT: reloc outside program 0x%x (0 - 0x%x/0x%x)",
-                      (int) r,(int)(start_brk-start_code),(int)text_len);
+                      (int) r,(int)(start_brk-start_data+text_len),(int)text_len);
                goto failed;
        }

this should be a separate patch since it is unrelated to your other change -mike

author
#2 lore raw
Quoted 21 lines · Mike Frysinger
Quoted 11 lines · Jun Sun

Apparently newer GCC would generate ANCHOR symbols beyond the end of data/bss segment on ARM CPUs. As a result, the exiting validity checking for relocation symbols in FLAT format will fail.

This also fixes a cosmetic error in printk. Text segment and data/bss segment are allocated from two different areas. It is not meaningful to give the diff between them in error reporting messages.

diff -Nru linux-2.6.32.2/arch/arm/include/asm/flat.h.orig linux-2.6.32.2/arch/arm/include/asm/flat.h

you really should use git to generate the patch. if you're going to do it by hand, you need to format it correctly. you're missing the --- marker between your change log and the start of the patch.

Quoted 4 lines
fs/binfmt_flat.c +0 -0
@@ -355,7 +355,7 @@
 
Quoted 9 lines

fs/binfmt_flat.c line 360

Quoted 6 lines
fs/binfmt_flat.c +1 -1
 ?? ?? ?? ??if (!flat_reloc_valid(r, start_brk - start_data + text_len)) {
 ?? ?? ?? ?? ?? ?? ?? ??printk("BINFMT_FLAT: reloc outside program 0x%x (0 - 0x%x/0x%x)",
- ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??(int) r,(int)(start_brk-start_code),(int)text_len);
+ ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??(int) r,(int)(start_brk-start_data+text_len),(int)text_len);
 ?? ?? ?? ?? ?? ?? ?? ??goto failed;
 ?? ?? ?? ??}

this should be a separate patch since it is unrelated to your other change -mike

Thanks for the feedback. Have not submitted any patches for a while. New patches are coming in a sec.

Cheers.

Jun