This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch libiberty/mach-o] fix byte-swapping of indices in wrapper sections.
- From: Ian Lance Taylor <ian at airs dot com>
- To: Iain Sandoe <developer at sandoe-acoustics dot co dot uk>
- Cc: gcc-patches Patches <gcc-patches at gcc dot gnu dot org>, Mike Stump <mrs at gcc dot gnu dot org>
- Date: Sun, 26 Feb 2012 09:39:15 -0800
- Subject: Re: [Patch libiberty/mach-o] fix byte-swapping of indices in wrapper sections.
- References: <42C5221F-2437-4D2B-ADD7-202D86355E11@sandoe-acoustics.co.uk>
Iain Sandoe <developer@sandoe-acoustics.co.uk> writes:
> Found while testing x86 X ppc ...
> .. I missed byte-swapping the indices when outputting the index of the
> GNU wrapper for LTO sections.
>
> OK/When?
> Iain
>
> libiberty:
>
> * simple-object-mach-o.c (simple_object_mach_o_write_segment):
> Byte-swap indices when required.
>
> diff --git a/libiberty/simple-object-mach-o.c b/libiberty/simple-
> object-mach-o.c
> index af5e4f9..fbf6a3f 100644
> --- a/libiberty/simple-object-mach-o.c
> +++ b/libiberty/simple-object-mach-o.c
> @@ -1224,6 +1224,11 @@ simple_object_mach_o_write_segment
> (simple_object_write *sobj, int descriptor,
> index[4 * i] -= index[0];
> index[0] = 0;
>
> + /* Swap the indices, if required. */
> +
> + for (i = 0; i < (nsects_in * 4); ++i)
> + set_32 (&index[i], index[i]);
> +
> sechdr_offset += sechdrsize;
>
> /* Write out the section names.
I think that is not the only way the code is broken. When you pass the
array to simple_object_internal_write, you are assuming that the type
"unsigned int" is exactly 4 bytes long. I would strongly recommend
changing the code to do something like
index_bytes = XNEWVEC (unsigned char, nsects_in * 16);
for (i = 0; i < nsects_in * 4; ++i)
set_32 (index_bytes + i * 4, index[i]);
if (!simple_object_internal_write (descriptor, offset, index_bytes,
nsects_in * 16, errmsg, err))
return 0;
XFREEVEC (index_bytes);
If that works, I'll approve it. I think this is OK in stage 4, as it is
a bug fix.
Ian