
From: David Howells <dhowells@redhat.com>

The attached patch makes it possible to support gp-rel addressing for small
variables.  Since the FR-V cpu's have fixed-length instructions and plenty of
general-purpose registers, one register is nominated as a base for the small
data area.  This makes it possible to use single-insn accesses to access
global and static variables instead of having to use multiple instructions.

This, however, causes problems with small variables used to pinpoint the
beginning and end of sections.  The compiler assumes it can use gp-rel
addressing for these, but the linker then complains because the displacement
is out of range.

By declaring certain variables as arrays or by forcing them into named
sections, the compiler is persuaded to access them as if they can be outside
the displacement range.  Declaring the variables as "const void" type also
works.

Signed-Off-By: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/drivers/char/tty_io.c   |    4 ++--
 25-akpm/fs/proc/proc_misc.c     |    1 -
 25-akpm/include/linux/init.h    |    4 ++--
 25-akpm/include/linux/jiffies.h |   10 ++++++++--
 25-akpm/include/linux/kernel.h  |    2 ++
 25-akpm/init/initramfs.c        |    6 +++---
 25-akpm/init/main.c             |   16 +++++++---------
 25-akpm/init/version.c          |    2 +-
 25-akpm/kernel/kallsyms.c       |    6 ++----
 25-akpm/kernel/power/swsusp.c   |    2 +-
 25-akpm/security/security.c     |    4 ++--
 11 files changed, 30 insertions(+), 27 deletions(-)

diff -puN drivers/char/tty_io.c~gp-rel-data-support drivers/char/tty_io.c
--- 25/drivers/char/tty_io.c~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/drivers/char/tty_io.c	Mon Nov  8 14:48:59 2004
@@ -2903,8 +2903,8 @@ void __init console_init(void)
 	   So I haven't moved it. dwmw2 */
         rs_360_init();
 #endif
-	call = &__con_initcall_start;
-	while (call < &__con_initcall_end) {
+	call = __con_initcall_start;
+	while (call < __con_initcall_end) {
 		(*call)();
 		call++;
 	}
diff -puN fs/proc/proc_misc.c~gp-rel-data-support fs/proc/proc_misc.c
--- 25/fs/proc/proc_misc.c~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/fs/proc/proc_misc.c	Mon Nov  8 14:48:59 2004
@@ -256,7 +256,6 @@ static struct file_operations fragmentat
 static int version_read_proc(char *page, char **start, off_t off,
 				 int count, int *eof, void *data)
 {
-	extern char *linux_banner;
 	int len;
 
 	strcpy(page, linux_banner);
diff -puN include/linux/init.h~gp-rel-data-support include/linux/init.h
--- 25/include/linux/init.h~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/include/linux/init.h	Mon Nov  8 14:48:59 2004
@@ -64,8 +64,8 @@
 typedef int (*initcall_t)(void);
 typedef void (*exitcall_t)(void);
 
-extern initcall_t __con_initcall_start, __con_initcall_end;
-extern initcall_t __security_initcall_start, __security_initcall_end;
+extern initcall_t __con_initcall_start[], __con_initcall_end[];
+extern initcall_t __security_initcall_start[], __security_initcall_end[];
 
 /* Defined in init/main.c */
 extern char saved_command_line[];
diff -puN include/linux/jiffies.h~gp-rel-data-support include/linux/jiffies.h
--- 25/include/linux/jiffies.h~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/include/linux/jiffies.h	Mon Nov  8 14:48:59 2004
@@ -70,13 +70,19 @@
 /* a value TUSEC for TICK_USEC (can be set bij adjtimex)		*/
 #define TICK_USEC_TO_NSEC(TUSEC) (SH_DIV (TUSEC * USER_HZ * 1000, ACTHZ, 8))
 
+/* some arch's have a small-data section that can be accessed register-relative
+ * but that can only take up to, say, 4-byte variables. jiffies being part of
+ * an 8-byte variable may not be correctly accessed unless we force the issue
+ */
+#define __jiffy_data  __attribute__((section(".data")))
+
 /*
  * The 64-bit value is not volatile - you MUST NOT read it
  * without sampling the sequence number in xtime_lock.
  * get_jiffies_64() will do this for you as appropriate.
  */
-extern u64 jiffies_64;
-extern unsigned long volatile jiffies;
+extern u64 __jiffy_data jiffies_64;
+extern unsigned long volatile __jiffy_data jiffies;
 
 #if (BITS_PER_LONG < 64)
 u64 get_jiffies_64(void);
diff -puN include/linux/kernel.h~gp-rel-data-support include/linux/kernel.h
--- 25/include/linux/kernel.h~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/include/linux/kernel.h	Mon Nov  8 14:48:59 2004
@@ -16,6 +16,8 @@
 #include <asm/byteorder.h>
 #include <asm/bug.h>
 
+extern const char linux_banner[];
+
 #define INT_MAX		((int)(~0U>>1))
 #define INT_MIN		(-INT_MAX - 1)
 #define UINT_MAX	(~0U)
diff -puN init/initramfs.c~gp-rel-data-support init/initramfs.c
--- 25/init/initramfs.c~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/init/initramfs.c	Mon Nov  8 14:48:59 2004
@@ -459,15 +459,15 @@ char * __init unpack_to_rootfs(char *buf
 	return message;
 }
 
-extern char __initramfs_start, __initramfs_end;
+extern char __initramfs_start[], __initramfs_end[];
 #ifdef CONFIG_BLK_DEV_INITRD
 #include <linux/initrd.h>
 #endif
 
 void __init populate_rootfs(void)
 {
-	char *err = unpack_to_rootfs(&__initramfs_start,
-			 &__initramfs_end - &__initramfs_start, 0);
+	char *err = unpack_to_rootfs(__initramfs_start,
+			 __initramfs_end - __initramfs_start, 0);
 	if (err)
 		panic(err);
 #ifdef CONFIG_BLK_DEV_INITRD
diff -puN init/main.c~gp-rel-data-support init/main.c
--- 25/init/main.c~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/init/main.c	Mon Nov  8 14:48:59 2004
@@ -75,8 +75,6 @@
 #error Sorry, your GCC is too old. It builds incorrect kernels.
 #endif
 
-extern char *linux_banner;
-
 static int init(void *);
 
 extern void init_IRQ(void);
@@ -157,12 +155,13 @@ static char * argv_init[MAX_INIT_ARGS+2]
 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
 static const char *panic_later, *panic_param;
 
+extern struct obs_kernel_param __setup_start[], __setup_end[];
+
 static int __init obsolete_checksetup(char *line)
 {
 	struct obs_kernel_param *p;
-	extern struct obs_kernel_param __setup_start, __setup_end;
 
-	p = &__setup_start;
+	p = __setup_start;
 	do {
 		int n = strlen(p->str);
 		if (!strncmp(line, p->str, n)) {
@@ -179,7 +178,7 @@ static int __init obsolete_checksetup(ch
 				return 1;
 		}
 		p++;
-	} while (p < &__setup_end);
+	} while (p < __setup_end);
 	return 0;
 }
 
@@ -453,9 +452,8 @@ static void noinline rest_init(void)
 static int __init do_early_param(char *param, char *val)
 {
 	struct obs_kernel_param *p;
-	extern struct obs_kernel_param __setup_start, __setup_end;
 
-	for (p = &__setup_start; p < &__setup_end; p++) {
+	for (p = __setup_start; p < __setup_end; p++) {
 		if (p->early && strcmp(param, p->str) == 0) {
 			if (p->setup_func(val) != 0)
 				printk(KERN_WARNING
@@ -592,14 +590,14 @@ __setup("initcall_debug", initcall_debug
 
 struct task_struct *child_reaper = &init_task;
 
-extern initcall_t __initcall_start, __initcall_end;
+extern initcall_t __initcall_start[], __initcall_end[];
 
 static void __init do_initcalls(void)
 {
 	initcall_t *call;
 	int count = preempt_count();
 
-	for (call = &__initcall_start; call < &__initcall_end; call++) {
+	for (call = __initcall_start; call < __initcall_end; call++) {
 		char *msg;
 
 		if (initcall_debug) {
diff -puN init/version.c~gp-rel-data-support init/version.c
--- 25/init/version.c~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/init/version.c	Mon Nov  8 14:48:59 2004
@@ -28,6 +28,6 @@ struct new_utsname system_utsname = {
 
 EXPORT_SYMBOL(system_utsname);
 
-const char *linux_banner = 
+const char linux_banner[] = 
 	"Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@"
 	LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n";
diff -puN kernel/kallsyms.c~gp-rel-data-support kernel/kallsyms.c
--- 25/kernel/kallsyms.c~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/kernel/kallsyms.c	Mon Nov  8 14:48:59 2004
@@ -18,10 +18,11 @@
 #include <linux/fs.h>
 #include <linux/err.h>
 #include <linux/proc_fs.h>
+#include <asm/sections.h>
 
 /* These will be re-linked against their real values during the second link stage */
 extern unsigned long kallsyms_addresses[] __attribute__((weak));
-extern unsigned long kallsyms_num_syms __attribute__((weak));
+extern unsigned long kallsyms_num_syms __attribute__((weak,section("data")));
 extern u8 kallsyms_names[] __attribute__((weak));
 
 extern u8 kallsyms_token_table[] __attribute__((weak));
@@ -29,9 +30,6 @@ extern u16 kallsyms_token_index[] __attr
 
 extern unsigned long kallsyms_markers[] __attribute__((weak));
 
-/* Defined by the linker script. */
-extern char _stext[], _etext[], _sinittext[], _einittext[];
-
 static inline int is_kernel_inittext(unsigned long addr)
 {
 	if (addr >= (unsigned long)_sinittext
diff -puN kernel/power/swsusp.c~gp-rel-data-support kernel/power/swsusp.c
--- 25/kernel/power/swsusp.c~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/kernel/power/swsusp.c	Mon Nov  8 14:48:59 2004
@@ -72,7 +72,7 @@
 #include "power.h"
 
 /* References to section boundaries */
-extern char __nosave_begin, __nosave_end;
+extern const void __nosave_begin, __nosave_end;
 
 extern int is_head_of_free_region(struct page *);
 
diff -puN security/security.c~gp-rel-data-support security/security.c
--- 25/security/security.c~gp-rel-data-support	Mon Nov  8 14:48:59 2004
+++ 25-akpm/security/security.c	Mon Nov  8 14:48:59 2004
@@ -38,8 +38,8 @@ static inline int verify(struct security
 static void __init do_security_initcalls(void)
 {
 	initcall_t *call;
-	call = &__security_initcall_start;
-	while (call < &__security_initcall_end) {
+	call = __security_initcall_start;
+	while (call < __security_initcall_end) {
 		(*call) ();
 		call++;
 	}
_
