This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] config/host-darwin.c (darwin_gt_pch_use_address) should return -1 on error.
- From: Carlos O'Donell <carlos at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: mrs at apple dot com
- Date: Tue, 19 Dec 2006 22:31:26 -0500
- Subject: [PATCH] config/host-darwin.c (darwin_gt_pch_use_address) should return -1 on error.
Mike,
I was reading over the PCH code for other reasons and I saw a small
bug.
The caller of host_hooks.gt_pch_use_address() expects a return of zero
when the host was able to allocate memory at the current address but did
not load the file. Darwin's hook appears to return zero when the mmap
fails. This is not correct, it should return -1 to indicate failure.
In config/host-darwin.c (darwin_gt_pch_use_address) when the call to
mmap fails the result is presumably MAP_FAILED. The return value is set
by 'ret = mmap_result != MAP_FAILED'. The value returned is 0, and
the architecture independant code in ggc-common.c (gt_pch_restore) will
then attempt to fread into mmi.preferred_base and SIGSEGV.
A completely untested patch follows.
Cheers,
Carlos.
--
Carlos O'Donell
CodeSourcery
carlos@codesourcery.com
(650) 331-3385 x716
2006-12-19 Carlos O'Donell <carlos@codesourcery.com>
* config/host-darwin.c (darwin_gt_pch_use_address):
Return 1 on success, and -1 on failure.
Index: gcc/config/host-darwin.c
===================================================================
--- gcc/config/host-darwin.c (revision 120059)
+++ gcc/config/host-darwin.c (working copy)
@@ -75,5 +75,5 @@ darwin_gt_pch_use_address (void *addr, s
gcc_assert (!ret || mmap_result == addr);
}
- return ret;
+ return ret ? 1 : -1;
}