Iain Sandoe <develo...@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