This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] SH FDPIC backend support
- From: Rich Felker <dalias at libc dot org>
- To: Oleg Endo <oleg dot endo at t-online dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 3 Oct 2015 21:12:09 -0400
- Subject: Re: [PATCH] SH FDPIC backend support
- Authentication-results: sourceware.org; auth=none
- References: <20151001213559 dot GA2442 at brightrain dot aerifal dot cx> <1443738987 dot 2031 dot 136 dot camel at t-online dot de> <20151001233910 dot GN8645 at brightrain dot aerifal dot cx> <20151002013017 dot GO8645 at brightrain dot aerifal dot cx> <1443793863 dot 2031 dot 177 dot camel at t-online dot de> <20151002151832 dot GT8645 at brightrain dot aerifal dot cx>
On Fri, Oct 02, 2015 at 11:18:32AM -0400, Rich Felker wrote:
> > > +#ifdef __FDPIC__
> > > +#define udiv_qrnnd(q, r, n1, n0, d) \
> > > + do { \
> > > + extern UWtype __udiv_qrnnd_16 (UWtype, UWtype) \
> >
> > It's really difficult to spot the subtle difference of the FDPIC version
> > and the non-FDPIC version. At least there should be a comment.
>
> OK, I can add a comment; this is appropriate anyway since the way it's
> making the FDPIC call is unconventional.
Before I add comments, can we discuss whether the approach I took is
appropriate? The udiv_qrnnd asm block takes as an operand a function
pointer for __udiv_qrnnd_16 which it calls from asm. The
__udiv_qrnnd_16 function is itself written in asm has a special
contract for register clobbers, and it doesn't need a GOT register.
The non-FDPIC asm calls it via jsr @%5 (%5 is the function pointer)
but on FDPIC the function pointer points to a function descriptor, not
code, so an extra level of indirection is needed. This is actually
inefficient to do in asm because we have to repeat it twice. Normally
an FDPIC call would also require loading the GOT pointer from the
function descriptor, but since this call is local, that can be
skipped.
Another option would be to pass (essentially) *(void**)__udiv_qrnnd_16
instead of __udiv_qrnnd_16 to the asm block; then the existing inline
asm can be used as-is. This could be done via passing
SH_CODE_ADDRESS(__udiv_qrnnd_16) instead of __udiv_qrnnd_16, where
SH_CODE_ADDRESS would be a macro defined to pass through its argument
for non-FDPIC and to extract the code address from the function
descriptor for FDPIC. However I'm not convinced it's clean/safe to do
the above punning. At the very least a may_alias attribute probably
belongs in there somewhere. But an approach like this would reduce
code duplication and slightly improve the size/performance of the
resulting code.
Opinions?
Rich