public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Make ld.so.cache identical between IA-32 and AMD64
@ 2003-08-25 10:49 Jakub Jelinek
  2003-08-25 18:38 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2003-08-25 10:49 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

If the number of old cache libraries in ld.so.cache (ie. those with
entry->hwcap == 0) is odd and ld.so.cache contains both old and new
cache, the 32-bit dynamic linker will not be able to find new cache
created by 64-bit ldconfig or 64-bit ld.so will not be able to find 
new cache created by 32-bit ldconfig on AMD64.
The problem is that cache_file_new structure is 32-bit aligned on
IA-32 while 64-bit aligned on AMD64 (it contains uint64_t hwcap).
The following patch fixes it by creating a dummy old cache entry,
which means no ld.so or libc.a loader changes are needed and compatibility
is ensured.
Also, it seems save_cache could clobber memory past end of file_entries
malloced buffer if last entry has entry->hwcap != 0.

2003-08-25  Jakub Jelinek  <jakub@redhat.com>

	* elf/cache.c (save_cache): Don't write beyond end of file_entries
	buffer.
	Duplicate last old cache entry if the count would be odd.

--- libc/elf/cache.c.jj	2003-03-15 20:03:52.000000000 -0500
+++ libc/elf/cache.c	2003-08-25 06:31:06.000000000 -0400
@@ -305,6 +305,13 @@ save_cache (const char *cache_name)
 
   if (opt_format != 2)
     {
+      /* struct cache_file_new is 64-bit aligned on some arches while
+	 only 32-bit aligned on other arches.  Duplicate last old
+	 cache entry so that new cache in ld.so.cache can be used by
+	 both.  */
+      if (opt_format != 0)
+	cache_entry_old_count = (cache_entry_old_count + 1) & ~1;
+
       /* And the list of all entries in the old format.  */
       file_entries_size = sizeof (struct cache_file)
 	+ cache_entry_old_count * sizeof (struct file_entry);
@@ -351,7 +358,7 @@ save_cache (const char *cache_name)
        entry = entry->next, ++idx_new)
     {
       /* First the library.  */
-      if (opt_format != 2)
+      if (opt_format != 2 && entry->hwcap == 0)
 	{
 	  file_entries->libs[idx_old].flags = entry->flags;
 	  /* XXX: Actually we can optimize here and remove duplicates.  */
@@ -374,7 +381,7 @@ save_cache (const char *cache_name)
       ++str;
       str_offset += len + 1;
       /* Then the path.  */
-      if (opt_format != 2)
+      if (opt_format != 2 && entry->hwcap == 0)
 	file_entries->libs[idx_old].value = str_offset + pad;
       if (opt_format != 0)
 	file_entries_new->libs[idx_new].value = str_offset;
@@ -388,6 +395,11 @@ save_cache (const char *cache_name)
 	++idx_old;
     }
 
+  /* Duplicate last old cache entry if needed.  */
+  if (opt_format != 2
+      && idx_old < cache_entry_old_count)
+    file_entries->libs[idx_old] = file_entries->libs[idx_old - 1];
+
   /* Write out the cache.  */
 
   /* Write cache first to a temporary file and rename it later.  */


	Jakub

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

* Re: [PATCH] Make ld.so.cache identical between IA-32 and AMD64
  2003-08-25 10:49 [PATCH] Make ld.so.cache identical between IA-32 and AMD64 Jakub Jelinek
@ 2003-08-25 18:38 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2003-08-25 18:38 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jakub Jelinek wrote:

> 2003-08-25  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* elf/cache.c (save_cache): Don't write beyond end of file_entries
> 	buffer.
> 	Duplicate last old cache entry if the count would be odd.

I applied the patch, thanks.

- -- 
- --------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/SleQ2ijCOnn/RHQRAnAPAJ0TIxQcVk2JscMuWvxAo8z5jtPfvgCgpdBk
gWjHdXvhXUkARdpF/gMBASA=
=ZYzQ
-----END PGP SIGNATURE-----

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

end of thread, other threads:[~2003-08-25 18:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-25 10:49 [PATCH] Make ld.so.cache identical between IA-32 and AMD64 Jakub Jelinek
2003-08-25 18: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).