On Tue, Jan 12, 2016 at 5:32 PM, Ian Lepore <i...@freebsd.org> wrote:
> Yep, but then I had to do this because ef->off is 64 bits even on 32
> bit arches, so I got a pointer/int size mismatch warning...
>
> Index: common/load_elf.c
> ===================================================================
> --- common/load_elf.c   (revision 293796)
> +++ common/load_elf.c   (working copy)
> @@ -886,7 +886,7 @@ __elfN(parse_modmetadata)(struct preloaded_file *f
>         error = __elfN(reloc_ptr)(fp, ef, v, &md, sizeof(md));
>         if (error == EOPNOTSUPP) {
>             md.md_cval += ef->off;
> -           md.md_data = (void *)((uintptr_t)md.md_data + ef->off);
> +           md.md_data = (void *)(uintptr_t)((uintptr_t)md.md_data +
> ef->off);
>         } else if (error != 0)
>             return (error);
>  #endif
>
>
> That is just some special kind of ugly.

Yes.  You could maybe do:

md.md_data = (c_caddr_t)md.md_data + (ptrdiff_t)ef->off;

Instead.  Yes, the ptrdiff_t will truncate uint64_t on 32-bit pointer
platforms, but the result is truncated regardless when it is stored in
the md_data pointer.  And the result under modulus is equivalent.

(You could even change the type of md_data to c_caddr_t from 'const
void *' to make it easier to do math on.  Then this could just be:
md.md_data += (ptrdiff_t)ef->off;)

Best,
Conrad
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to