Reviving SH FDPIC target

Rich Felker dalias@libc.org
Sun Sep 13 17:11:00 GMT 2015


On Fri, Sep 04, 2015 at 06:04:15PM -0500, Segher Boessenkool wrote:
> On Fri, Sep 04, 2015 at 04:16:40PM -0400, Rich Felker wrote:
> > One thing I've noticed that's odd is that gcc -mfdpic -fPIC produces
> > different (less efficient) code from just gcc -mfdpic, which seems
> > wrong, but agrees with sh.c which has a number of checks for flag_pic
> > not matched with a TARGET_FDPIC check.
> 
> Generic code tests flag_pic in important places as well.
> 
> > I'm thinking all of these
> > should either be flag_pic||TARGET_PIC or flag_pic&&!TARGET_FDPIC,
> > depending on whether the code applies to all PIC or is specific to the
> > non-FDPIC PIC model where r12 is call-saved. Does this sound correct?
> > I think we need spurious -fPIC to work (although it could be handled
> > with spec magic) and not pessimize code, since most library builds
> > will use -fPIC.
> 
> If you never want -fPIC (or -fpic) if fdpic is enabled, you can disable
> it (in sh_option_override)?

It turns out that with !flag_pic, gcc is generating broken code and/or
ICE, and this happens even after changing all the remaining flag_pic
tests in sh.c to flag_pic||TARGET_FDPIC. There are a few more in sh.md
I didn't try changing but they did not look relevant; the ICE came
via expand_binop in prepare_move_operands. Before I look at it
further, is there any reason to expect !flag_pic in the generic code
to break things when the target-specific code has PIC-like
constraints?

For now I just made sh_option_override force flag_pic when
TARGET_FDPIC is set. Note that flag_pic by itself is equivalent to
-fPIE; -fPIC also sets flag_shlib which affects other things like TLS
model and binds_locally interpretation. This seems like a viable
solution (and I got rid of the suboptimal codegen by fixing the
condition in sh_function_ok_for_sibcall so that flag_pic doesn't
preclude sibcalls when TARGET_FDPIC is set) but I'd still like to
figure out why gcc is breaking without flag_pic...

Rich



More information about the Gcc-patches mailing list