public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* Patch to allow ARM dynamic linker to fix up PC24 relocs...
@ 1999-12-21  8:19 Scott Bambrough
  1999-12-21  8:29 ` Ulrich Drepper
  0 siblings, 1 reply; 9+ messages in thread
From: Scott Bambrough @ 1999-12-21  8:19 UTC (permalink / raw)
  To: libc-hacker mailing list

The attached patch adds a cache flush just after the readonly protection
is restored to .text.  I've done this in generic code, because the cache
flush is an extremely expensive operation on the ARM.  We don't want to
do this after every fixup, and only if we do fixups.  The patch as
written should only affect the ARM (or anyone else who defines
CLEAR_CACHE).  For all other targets it will disappear after
pre-processing.  This patch has the fix for the problem Phil Blundell
pointed out.  I've tested it and it seems to work.

1999-12-21  Scott Bambrough  <scottb@netwinder.org>

        * sysdeps/arm/dl-machine.h (CLEAR_CACHE): New macro to force a
        cache flush.
        * elf/dl-reloc.c (_dl_relocate_object): Add call to flush cache
        after .text segment fixups.

Scott

-- 
Scott Bambrough - Software Engineer
REBEL.COM    http://www.rebel.com
NetWinder    http://www.netwinder.org
diff -upr glibc-2.1.2.orig/elf/dl-reloc.c glibc-2.1.2/elf/dl-reloc.c
--- glibc-2.1.2.orig/elf/dl-reloc.c	Sat Feb 20 09:45:53 1999
+++ glibc-2.1.2/elf/dl-reloc.c	Fri Dec 10 10:36:33 1999
@@ -126,6 +126,10 @@ _dl_relocate_object (struct link_map *l,
 	    if (__mprotect (mapstart, mapend - mapstart, prot) < 0)
 	      _dl_signal_error (errno, l->l_name,
 				"can't restore segment prot after reloc");
+
+#ifdef CLEAR_CACHE
+	    CLEAR_CACHE (mapstart, mapend);
+#endif 
 	  }
     }
 }
diff -upr glibc-2.1.2.orig/sysdeps/arm/dl-machine.h glibc-2.1.2/sysdeps/arm/dl-machine.h
--- glibc-2.1.2.orig/sysdeps/arm/dl-machine.h	Tue Aug 10 01:13:22 1999
+++ glibc-2.1.2/sysdeps/arm/dl-machine.h	Fri Dec 10 10:36:57 1999
@@ -35,6 +35,14 @@
   VALID_ELF_ABIVERSION(hdr[EI_ABIVERSION]) \
 )
 
+#define CLEAR_CACHE(BEG,END)						\
+{									\
+  register unsigned long _beg __asm ("a1") = (unsigned long)(BEG);	\
+  register unsigned long _end __asm ("a2") = (unsigned long)(END);	\
+  register unsigned long _flg __asm ("a3") = 0;			\
+  __asm __volatile ("swi 0x9f0002");					\
+}
+
 /* Return nonzero iff E_MACHINE is compatible with the running host.  */
 static inline int __attribute__ ((unused))
 elf_machine_matches_host (Elf32_Half e_machine)

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Patch to allow ARM dynamic linker to fix up PC24 relocs...
@ 1999-12-07 11:50 Scott Bambrough
  1999-12-07 12:12 ` Philip Blundell
  1999-12-07 23:38 ` Ulrich Drepper
  0 siblings, 2 replies; 9+ messages in thread
From: Scott Bambrough @ 1999-12-07 11:50 UTC (permalink / raw)
  To: libc-hacker mailing list

Hi guys,

The attached patch allows the ARM dynamic linker to fix up PC24 relocs
in the code segment.  A bit of background is attached.

The PC24 reloc is generated for ARM branch and branch and link
instructions (b,bl).  The least significant 24 bits are used to for a 26
bit offset (the offset is modulo 4).  The address calculation performed
by the CPU is as follows:

PC = PC + (SignExtend(<24_bit_signed_offset>) << 2;

If the calculated 26 bit offset is out of range, the dynamic linker
displays an error message like the following:

foo_dynamic: error in loading shared libraries: ./foo.so: R_ARM_PC24
relocation out of range

1999-12-07  Scott Bambrough <scottb@netwinder.org>

	* sysdeps/arm/dl-machine.h (elf_machine_rel): Fixup R_ARM_PC24
 	  relocs if possible.

-- 
Scott Bambrough - Software Engineer
REBEL.COM    http://www.rebel.com
NetWinder    http://www.netwinder.org
--- dl-machine.h.orig	Fri Nov 26 08:56:05 1999
+++ dl-machine.h	Tue Dec  7 14:04:13 1999
@@ -446,6 +446,23 @@ elf_machine_rel (struct link_map *map, c
 	    *reloc_addr += value;
 	    break;
 	  }
+	case R_ARM_PC24:
+	  {
+	     signed int addend;
+
+	     addend = *reloc_addr & 0x00ffffff;
+	     if (addend & 0x00800000) addend |= 0xff000000;
+
+	     value = value - (unsigned int)reloc_addr + (addend << 2);
+	     if (value & 0xfc000003)
+	       _dl_signal_error (0, map->l_name,
+			  "R_ARM_PC24 relocation out of range");
+	       
+	     value = value >> 2;
+	     value = (*reloc_addr & 0xff000000) | (value & 0x00ffffff);
+	     *reloc_addr = value;
+	  }
+	break;
 	default:
 	  assert (! "unexpected dynamic reloc type");
 	  break;

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~1999-12-21  8:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-21  8:19 Patch to allow ARM dynamic linker to fix up PC24 relocs Scott Bambrough
1999-12-21  8:29 ` Ulrich Drepper
1999-12-21  8:37   ` Scott Bambrough
  -- strict thread matches above, loose matches on Subject: below --
1999-12-07 11:50 Scott Bambrough
1999-12-07 12:12 ` Philip Blundell
1999-12-07 18:37   ` Richard Henderson
     [not found]     ` <E11veej-0007M5-00@>
1999-12-17  8:53       ` Scott Bambrough
     [not found]         ` <E11z0kF-0000TS-00@fountain.labs.futuretv.com>
1999-12-17  9:40           ` Scott Bambrough
1999-12-07 23:38 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).