https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124027

--- Comment #6 from Pali Rohár <pali at kernel dot org> ---
(In reply to Eric Botcazou from comment #2)
> See config/i386/cygming.h:
> 
> /* Don't allow flag_pic to propagate since gas may produce invalid code
>    otherwise.  */
> 
> #undef  SUBTARGET_OVERRIDE_OPTIONS
> #define SUBTARGET_OVERRIDE_OPTIONS                                    \
> do {                                                                  \
>   flag_pic = TARGET_64BIT ? 1 : 0;                                      \
> } while (0)

Thanks for this starting point. I tried to study gcc code, how it works and I
tried to implement this missing functionality. flag_pic=1 really generates
invalid code for 32-bit x86 PE-COFF, so the comment is correct and basically
this flag_pic = 0 assignment in SUBTARGET_OVERRIDE_OPTIONS completely overrides
all -fpic, -fPIC, -fpie and -fPIE compile options, effectively turning off PIC
support.

> Changing it would be backward incompatible.  Position Independence is
> achieved differently in PE-COFF by means of the .reloc section.

Well, if it is done correctly, then I think it should be ABI compatible. The
only thing which is needed for the -fpic is to generate valid 32-bit x86 code
which has exactly same meaning as the current -fno-pic code. And this should be
possible via logic which I described in the description of this thread. DISP32
relocation is already supported by GNU linker and GCC already generates asm
code which uses it, it is present basically in all "call" instructions. So such
change if done precisely should be backward compatible, just with different asm
code, like if optimizations are enabled (optimizations generates different
code, but with same meaning).

Reply via email to