Fix even more merging PIC and PIE options

Message ID 20180810143333.GA90959@kam.mff.cuni.cz
State New
Headers show
Series
  • Fix even more merging PIC and PIE options
Related show

Commit Message

Jan Hubicka Aug. 10, 2018, 2:33 p.m.
Hi,
this patch should fix merging of PIC and PIE options so we always resort
to the least common denominator of the object files compiled (i.e. 
linking together -fpic and -fPIE will result in -fpie binary).
Note that we also use information about format of output passed by linker
plugin so we will disable pic/pie when resulting binary is not relocatable.
However for shared libraries and pie we want to pick right mode that makes
sense.

I wrote simple script that tries all possible options of combining two files.
Mode picked is specified in the output file.

To support targets that default to pic/pie well, I had to also hack
lto_write_options to always stream what mode was used in the given file.

lto-bootstrapped/regtested x86_64-linux, OK?

Honza

	PR lto/86517
	* lto-opts.c (lto_write_options): Always stream PIC/PIE mode.
	* lto-wrapper.c (merge_and_complain): Fix merging of PIC/PIE
+                   =>  -fno-pie 
                  +    -fpic          =>  -fno-pie 
                  +    -fPIC          =>  -fno-pie 
                  +    -fpie          =>  -fno-pie 
                  +    -fPIE          =>  -fno-pie 
                  + -fno-pic          =>  -fno-pie 
                  + -fno-pie          =>  -fno-pie 
            -fpic +                   =>  -fno-pie 
            -fpic +    -fpic          =>  -fpic 
            -fpic +    -fPIC          =>  -fpic 
            -fpic +    -fpie          =>  -fpie 
            -fpic +    -fPIE          =>  -fpie 
            -fpic + -fno-pic          =>  -fno-pic 
            -fpic + -fno-pie          =>  -fno-pie 
            -fPIC +                   =>  -fno-pie 
            -fPIC +    -fpic          =>  -fpic 
            -fPIC +    -fPIC          =>  -fPIC 
            -fPIC +    -fpie          =>  -fpie 
            -fPIC +    -fPIE          =>  -fPIE 
            -fPIC + -fno-pic          =>  -fno-pic 
            -fPIC + -fno-pie          =>  -fno-pie 
            -fpie +                   =>  -fno-pie 
            -fpie +    -fpic          =>  -fpie 
            -fpie +    -fPIC          =>  -fpie 
            -fpie +    -fpie          =>  -fpie 
            -fpie +    -fPIE          =>  -fpie 
            -fpie + -fno-pic          =>  -fno-pie 
            -fpie + -fno-pie          =>  -fno-pie 
            -fPIE +                   =>  -fno-pie 
            -fPIE +    -fpic          =>  -fpie 
            -fPIE +    -fPIC          =>  -fPIE 
            -fPIE +    -fpie          =>  -fpie 
            -fPIE +    -fPIE          =>  -fPIE 
            -fPIE + -fno-pic          =>  -fno-pie 
            -fPIE + -fno-pie          =>  -fno-pie 
         -fno-pic +                   =>  -fno-pic 
         -fno-pic +    -fpic          =>  -fno-pic 
         -fno-pic +    -fPIC          =>  -fno-pic 
         -fno-pic +    -fpie          =>  -fno-pic 
         -fno-pic +    -fPIE          =>  -fno-pic 
         -fno-pic + -fno-pic          =>  -fno-pic 
         -fno-pic + -fno-pie          =>  -fno-pic 
         -fno-pie +                   =>  -fno-pie 
         -fno-pie +    -fpic          =>  -fno-pie 
         -fno-pie +    -fPIC          =>  -fno-pie 
         -fno-pie +    -fpie          =>  -fno-pie 
         -fno-pie +    -fPIE          =>  -fno-pie 
         -fno-pie + -fno-pic          =>  -fno-pie 
         -fno-pie + -fno-pie          =>  -fno-pie 
                  +             -fpic =>  -fno-pie 
                  +    -fpic    -fpic =>  -fno-pie 
                  +    -fPIC    -fpic =>  -fno-pie 
                  +    -fpie    -fpic =>  -fno-pie 
                  +    -fPIE    -fpic =>  -fno-pie 
                  + -fno-pic    -fpic =>  -fno-pie 
                  + -fno-pie    -fpic =>  -fno-pie 
            -fpic +             -fpic =>  -fpic 
            -fpic +    -fpic    -fpic =>  -fpic 
            -fpic +    -fPIC    -fpic =>  -fpic 
            -fpic +    -fpie    -fpic =>  -fpic 
            -fpic +    -fPIE    -fpic =>  -fpic 
            -fpic + -fno-pic    -fpic =>  -fpic 
            -fpic + -fno-pie    -fpic =>  -fpic 
            -fPIC +             -fpic =>  -fpic 
            -fPIC +    -fpic    -fpic =>  -fpic 
            -fPIC +    -fPIC    -fpic =>  -fpic 
            -fPIC +    -fpie    -fpic =>  -fpic 
            -fPIC +    -fPIE    -fpic =>  -fpic 
            -fPIC + -fno-pic    -fpic =>  -fpic 
            -fPIC + -fno-pie    -fpic =>  -fpic 
            -fpie +             -fpic =>  -fpie 
            -fpie +    -fpic    -fpic =>  -fpie 
            -fpie +    -fPIC    -fpic =>  -fpie 
            -fpie +    -fpie    -fpic =>  -fpie 
            -fpie +    -fPIE    -fpic =>  -fpie 
            -fpie + -fno-pic    -fpic =>  -fpie 
            -fpie + -fno-pie    -fpic =>  -fpie 
            -fPIE +             -fpic =>  -fpie 
            -fPIE +    -fpic    -fpic =>  -fpie 
            -fPIE +    -fPIC    -fpic =>  -fpie 
            -fPIE +    -fpie    -fpic =>  -fpie 
            -fPIE +    -fPIE    -fpic =>  -fpie 
            -fPIE + -fno-pic    -fpic =>  -fpie 
            -fPIE + -fno-pie    -fpic =>  -fpie 
         -fno-pic +             -fpic =>  -fno-pic 
         -fno-pic +    -fpic    -fpic =>  -fno-pic 
         -fno-pic +    -fPIC    -fpic =>  -fno-pic 
         -fno-pic +    -fpie    -fpic =>  -fno-pic 
         -fno-pic +    -fPIE    -fpic =>  -fno-pic 
         -fno-pic + -fno-pic    -fpic =>  -fno-pic 
         -fno-pic + -fno-pie    -fpic =>  -fno-pic 
         -fno-pie +             -fpic =>  -fno-pie 
         -fno-pie +    -fpic    -fpic =>  -fno-pie 
         -fno-pie +    -fPIC    -fpic =>  -fno-pie 
         -fno-pie +    -fpie    -fpic =>  -fno-pie 
         -fno-pie +    -fPIE    -fpic =>  -fno-pie 
         -fno-pie + -fno-pic    -fpic =>  -fno-pie 
         -fno-pie + -fno-pie    -fpic =>  -fno-pie 
                  +             -fPIC =>  -fno-pie 
                  +    -fpic    -fPIC =>  -fno-pie 
                  +    -fPIC    -fPIC =>  -fno-pie 
                  +    -fpie    -fPIC =>  -fno-pie 
                  +    -fPIE    -fPIC =>  -fno-pie 
                  + -fno-pic    -fPIC =>  -fno-pie 
                  + -fno-pie    -fPIC =>  -fno-pie 
            -fpic +             -fPIC =>  -fpic 
            -fpic +    -fpic    -fPIC =>  -fpic 
            -fpic +    -fPIC    -fPIC =>  -fpic 
            -fpic +    -fpie    -fPIC =>  -fpic 
            -fpic +    -fPIE    -fPIC =>  -fpic 
            -fpic + -fno-pic    -fPIC =>  -fpic 
            -fpic + -fno-pie    -fPIC =>  -fpic 
            -fPIC +             -fPIC =>  -fPIC 
            -fPIC +    -fpic    -fPIC =>  -fPIC 
            -fPIC +    -fPIC    -fPIC =>  -fPIC 
            -fPIC +    -fpie    -fPIC =>  -fPIC 
            -fPIC +    -fPIE    -fPIC =>  -fPIC 
            -fPIC + -fno-pic    -fPIC =>  -fPIC 
            -fPIC + -fno-pie    -fPIC =>  -fPIC 
            -fpie +             -fPIC =>  -fpie 
            -fpie +    -fpic    -fPIC =>  -fpie 
            -fpie +    -fPIC    -fPIC =>  -fpie 
            -fpie +    -fpie    -fPIC =>  -fpie 
            -fpie +    -fPIE    -fPIC =>  -fpie 
            -fpie + -fno-pic    -fPIC =>  -fpie 
            -fpie + -fno-pie    -fPIC =>  -fpie 
            -fPIE +             -fPIC =>  -fPIE 
            -fPIE +    -fpic    -fPIC =>  -fPIE 
            -fPIE +    -fPIC    -fPIC =>  -fPIE 
            -fPIE +    -fpie    -fPIC =>  -fPIE 
            -fPIE +    -fPIE    -fPIC =>  -fPIE 
            -fPIE + -fno-pic    -fPIC =>  -fPIE 
            -fPIE + -fno-pie    -fPIC =>  -fPIE 
         -fno-pic +             -fPIC =>  -fno-pic 
         -fno-pic +    -fpic    -fPIC =>  -fno-pic 
         -fno-pic +    -fPIC    -fPIC =>  -fno-pic 
         -fno-pic +    -fpie    -fPIC =>  -fno-pic 
         -fno-pic +    -fPIE    -fPIC =>  -fno-pic 
         -fno-pic + -fno-pic    -fPIC =>  -fno-pic 
         -fno-pic + -fno-pie    -fPIC =>  -fno-pic 
         -fno-pie +             -fPIC =>  -fno-pie 
         -fno-pie +    -fpic    -fPIC =>  -fno-pie 
         -fno-pie +    -fPIC    -fPIC =>  -fno-pie 
         -fno-pie +    -fpie    -fPIC =>  -fno-pie 
         -fno-pie +    -fPIE    -fPIC =>  -fno-pie 
         -fno-pie + -fno-pic    -fPIC =>  -fno-pie 
         -fno-pie + -fno-pie    -fPIC =>  -fno-pie 
                  +             -fpie =>  -fno-pie 
                  +    -fpic    -fpie =>  -fno-pie 
                  +    -fPIC    -fpie =>  -fno-pie 
                  +    -fpie    -fpie =>  -fno-pie 
                  +    -fPIE    -fpie =>  -fno-pie 
                  + -fno-pic    -fpie =>  -fno-pie 
                  + -fno-pie    -fpie =>  -fno-pie 
            -fpic +             -fpie =>  -fpie 
            -fpic +    -fpic    -fpie =>  -fpie 
            -fpic +    -fPIC    -fpie =>  -fpie 
            -fpic +    -fpie    -fpie =>  -fpie 
            -fpic +    -fPIE    -fpie =>  -fpie 
            -fpic + -fno-pic    -fpie =>  -fpie 
            -fpic + -fno-pie    -fpie =>  -fpie 
            -fPIC +             -fpie =>  -fpie 
            -fPIC +    -fpic    -fpie =>  -fpie 
            -fPIC +    -fPIC    -fpie =>  -fpie 
            -fPIC +    -fpie    -fpie =>  -fpie 
            -fPIC +    -fPIE    -fpie =>  -fpie 
            -fPIC + -fno-pic    -fpie =>  -fpie 
            -fPIC + -fno-pie    -fpie =>  -fpie 
            -fpie +             -fpie =>  -fpie 
            -fpie +    -fpic    -fpie =>  -fpie 
            -fpie +    -fPIC    -fpie =>  -fpie 
            -fpie +    -fpie    -fpie =>  -fpie 
            -fpie +    -fPIE    -fpie =>  -fpie 
            -fpie + -fno-pic    -fpie =>  -fpie 
            -fpie + -fno-pie    -fpie =>  -fpie 
            -fPIE +             -fpie =>  -fpie 
            -fPIE +    -fpic    -fpie =>  -fpie 
            -fPIE +    -fPIC    -fpie =>  -fpie 
            -fPIE +    -fpie    -fpie =>  -fpie 
            -fPIE +    -fPIE    -fpie =>  -fpie 
            -fPIE + -fno-pic    -fpie =>  -fpie 
            -fPIE + -fno-pie    -fpie =>  -fpie 
         -fno-pic +             -fpie =>  -fno-pic 
         -fno-pic +    -fpic    -fpie =>  -fno-pic 
         -fno-pic +    -fPIC    -fpie =>  -fno-pic 
         -fno-pic +    -fpie    -fpie =>  -fno-pic 
         -fno-pic +    -fPIE    -fpie =>  -fno-pic 
         -fno-pic + -fno-pic    -fpie =>  -fno-pic 
         -fno-pic + -fno-pie    -fpie =>  -fno-pic 
         -fno-pie +             -fpie =>  -fno-pie 
         -fno-pie +    -fpic    -fpie =>  -fno-pie 
         -fno-pie +    -fPIC    -fpie =>  -fno-pie 
         -fno-pie +    -fpie    -fpie =>  -fno-pie 
         -fno-pie +    -fPIE    -fpie =>  -fno-pie 
         -fno-pie + -fno-pic    -fpie =>  -fno-pie 
         -fno-pie + -fno-pie    -fpie =>  -fno-pie 
                  +             -fPIE =>  -fno-pie 
                  +    -fpic    -fPIE =>  -fno-pie 
                  +    -fPIC    -fPIE =>  -fno-pie 
                  +    -fpie    -fPIE =>  -fno-pie 
                  +    -fPIE    -fPIE =>  -fno-pie 
                  + -fno-pic    -fPIE =>  -fno-pie 
                  + -fno-pie    -fPIE =>  -fno-pie 
            -fpic +             -fPIE =>  -fpie 
            -fpic +    -fpic    -fPIE =>  -fpie 
            -fpic +    -fPIC    -fPIE =>  -fpie 
            -fpic +    -fpie    -fPIE =>  -fpie 
            -fpic +    -fPIE    -fPIE =>  -fpie 
            -fpic + -fno-pic    -fPIE =>  -fpie 
            -fpic + -fno-pie    -fPIE =>  -fpie 
            -fPIC +             -fPIE =>  -fPIE 
            -fPIC +    -fpic    -fPIE =>  -fPIE 
            -fPIC +    -fPIC    -fPIE =>  -fPIE 
            -fPIC +    -fpie    -fPIE =>  -fPIE 
            -fPIC +    -fPIE    -fPIE =>  -fPIE 
            -fPIC + -fno-pic    -fPIE =>  -fPIE 
            -fPIC + -fno-pie    -fPIE =>  -fPIE 
            -fpie +             -fPIE =>  -fpie 
            -fpie +    -fpic    -fPIE =>  -fpie 
            -fpie +    -fPIC    -fPIE =>  -fpie 
            -fpie +    -fpie    -fPIE =>  -fpie 
            -fpie +    -fPIE    -fPIE =>  -fpie 
            -fpie + -fno-pic    -fPIE =>  -fpie 
            -fpie + -fno-pie    -fPIE =>  -fpie 
            -fPIE +             -fPIE =>  -fPIE 
            -fPIE +    -fpic    -fPIE =>  -fPIE 
            -fPIE +    -fPIC    -fPIE =>  -fPIE 
            -fPIE +    -fpie    -fPIE =>  -fPIE 
            -fPIE +    -fPIE    -fPIE =>  -fPIE 
            -fPIE + -fno-pic    -fPIE =>  -fPIE 
            -fPIE + -fno-pie    -fPIE =>  -fPIE 
         -fno-pic +             -fPIE =>  -fno-pic 
         -fno-pic +    -fpic    -fPIE =>  -fno-pic 
         -fno-pic +    -fPIC    -fPIE =>  -fno-pic 
         -fno-pic +    -fpie    -fPIE =>  -fno-pic 
         -fno-pic +    -fPIE    -fPIE =>  -fno-pic 
         -fno-pic + -fno-pic    -fPIE =>  -fno-pic 
         -fno-pic + -fno-pie    -fPIE =>  -fno-pic 
         -fno-pie +             -fPIE =>  -fno-pie 
         -fno-pie +    -fpic    -fPIE =>  -fno-pie 
         -fno-pie +    -fPIC    -fPIE =>  -fno-pie 
         -fno-pie +    -fpie    -fPIE =>  -fno-pie 
         -fno-pie +    -fPIE    -fPIE =>  -fno-pie 
         -fno-pie + -fno-pic    -fPIE =>  -fno-pie 
         -fno-pie + -fno-pie    -fPIE =>  -fno-pie 
                  +          -fno-pic =>  -fno-pie 
                  +    -fpic -fno-pic =>  -fno-pie 
                  +    -fPIC -fno-pic =>  -fno-pie 
                  +    -fpie -fno-pic =>  -fno-pie 
                  +    -fPIE -fno-pic =>  -fno-pie 
                  + -fno-pic -fno-pic =>  -fno-pie 
                  + -fno-pie -fno-pic =>  -fno-pie 
            -fpic +          -fno-pic =>  -fno-pic 
            -fpic +    -fpic -fno-pic =>  -fno-pic 
            -fpic +    -fPIC -fno-pic =>  -fno-pic 
            -fpic +    -fpie -fno-pic =>  -fno-pic 
            -fpic +    -fPIE -fno-pic =>  -fno-pic 
            -fpic + -fno-pic -fno-pic =>  -fno-pic 
            -fpic + -fno-pie -fno-pic =>  -fno-pic 
            -fPIC +          -fno-pic =>  -fno-pic 
            -fPIC +    -fpic -fno-pic =>  -fno-pic 
            -fPIC +    -fPIC -fno-pic =>  -fno-pic 
            -fPIC +    -fpie -fno-pic =>  -fno-pic 
            -fPIC +    -fPIE -fno-pic =>  -fno-pic 
            -fPIC + -fno-pic -fno-pic =>  -fno-pic 
            -fPIC + -fno-pie -fno-pic =>  -fno-pic 
            -fpie +          -fno-pic =>  -fno-pie 
            -fpie +    -fpic -fno-pic =>  -fno-pie 
            -fpie +    -fPIC -fno-pic =>  -fno-pie 
            -fpie +    -fpie -fno-pic =>  -fno-pie 
            -fpie +    -fPIE -fno-pic =>  -fno-pie 
            -fpie + -fno-pic -fno-pic =>  -fno-pie 
            -fpie + -fno-pie -fno-pic =>  -fno-pie 
            -fPIE +          -fno-pic =>  -fno-pie 
            -fPIE +    -fpic -fno-pic =>  -fno-pie 
            -fPIE +    -fPIC -fno-pic =>  -fno-pie 
            -fPIE +    -fpie -fno-pic =>  -fno-pie 
            -fPIE +    -fPIE -fno-pic =>  -fno-pie 
            -fPIE + -fno-pic -fno-pic =>  -fno-pie 
            -fPIE + -fno-pie -fno-pic =>  -fno-pie 
         -fno-pic +          -fno-pic =>  -fno-pic 
         -fno-pic +    -fpic -fno-pic =>  -fno-pic 
         -fno-pic +    -fPIC -fno-pic =>  -fno-pic 
         -fno-pic +    -fpie -fno-pic =>  -fno-pic 
         -fno-pic +    -fPIE -fno-pic =>  -fno-pic 
         -fno-pic + -fno-pic -fno-pic =>  -fno-pic 
         -fno-pic + -fno-pie -fno-pic =>  -fno-pic 
         -fno-pie +          -fno-pic =>  -fno-pie 
         -fno-pie +    -fpic -fno-pic =>  -fno-pie 
         -fno-pie +    -fPIC -fno-pic =>  -fno-pie 
         -fno-pie +    -fpie -fno-pic =>  -fno-pie 
         -fno-pie +    -fPIE -fno-pic =>  -fno-pie 
         -fno-pie + -fno-pic -fno-pic =>  -fno-pie 
         -fno-pie + -fno-pie -fno-pic =>  -fno-pie 
                  +          -fno-pie =>  -fno-pie 
                  +    -fpic -fno-pie =>  -fno-pie 
                  +    -fPIC -fno-pie =>  -fno-pie 
                  +    -fpie -fno-pie =>  -fno-pie 
                  +    -fPIE -fno-pie =>  -fno-pie 
                  + -fno-pic -fno-pie =>  -fno-pie 
                  + -fno-pie -fno-pie =>  -fno-pie 
            -fpic +          -fno-pie =>  -fno-pie 
            -fpic +    -fpic -fno-pie =>  -fno-pie 
            -fpic +    -fPIC -fno-pie =>  -fno-pie 
            -fpic +    -fpie -fno-pie =>  -fno-pie 
            -fpic +    -fPIE -fno-pie =>  -fno-pie 
            -fpic + -fno-pic -fno-pie =>  -fno-pie 
            -fpic + -fno-pie -fno-pie =>  -fno-pie 
            -fPIC +          -fno-pie =>  -fno-pie 
            -fPIC +    -fpic -fno-pie =>  -fno-pie 
            -fPIC +    -fPIC -fno-pie =>  -fno-pie 
            -fPIC +    -fpie -fno-pie =>  -fno-pie 
            -fPIC +    -fPIE -fno-pie =>  -fno-pie 
            -fPIC + -fno-pic -fno-pie =>  -fno-pie 
            -fPIC + -fno-pie -fno-pie =>  -fno-pie 
            -fpie +          -fno-pie =>  -fno-pie 
            -fpie +    -fpic -fno-pie =>  -fno-pie 
            -fpie +    -fPIC -fno-pie =>  -fno-pie 
            -fpie +    -fpie -fno-pie =>  -fno-pie 
            -fpie +    -fPIE -fno-pie =>  -fno-pie 
            -fpie + -fno-pic -fno-pie =>  -fno-pie 
            -fpie + -fno-pie -fno-pie =>  -fno-pie 
            -fPIE +          -fno-pie =>  -fno-pie 
            -fPIE +    -fpic -fno-pie =>  -fno-pie 
            -fPIE +    -fPIC -fno-pie =>  -fno-pie 
            -fPIE +    -fpie -fno-pie =>  -fno-pie 
            -fPIE +    -fPIE -fno-pie =>  -fno-pie 
            -fPIE + -fno-pic -fno-pie =>  -fno-pie 
            -fPIE + -fno-pie -fno-pie =>  -fno-pie 
         -fno-pic +          -fno-pie =>  -fno-pic 
         -fno-pic +    -fpic -fno-pie =>  -fno-pic 
         -fno-pic +    -fPIC -fno-pie =>  -fno-pic 
         -fno-pic +    -fpie -fno-pie =>  -fno-pic 
         -fno-pic +    -fPIE -fno-pie =>  -fno-pic 
         -fno-pic + -fno-pic -fno-pie =>  -fno-pic 
         -fno-pic + -fno-pie -fno-pie =>  -fno-pic 
         -fno-pie +          -fno-pie =>  -fno-pie 
         -fno-pie +    -fpic -fno-pie =>  -fno-pie 
         -fno-pie +    -fPIC -fno-pie =>  -fno-pie 
         -fno-pie +    -fpie -fno-pie =>  -fno-pie 
         -fno-pie +    -fPIE -fno-pie =>  -fno-pie 
         -fno-pie + -fno-pic -fno-pie =>  -fno-pie 
         -fno-pie + -fno-pie -fno-pie =>  -fno-pie 
   -fpic          +                   =>  -fno-pie 
   -fpic          +    -fpic          =>  -fpic 
   -fpic          +    -fPIC          =>  -fpic 
   -fpic          +    -fpie          =>  -fpie 
   -fpic          +    -fPIE          =>  -fpie 
   -fpic          + -fno-pic          =>  -fno-pic 
   -fpic          + -fno-pie          =>  -fno-pie 
   -fpic    -fpic +                   =>  -fno-pie 
   -fpic    -fpic +    -fpic          =>  -fpic 
   -fpic    -fpic +    -fPIC          =>  -fpic 
   -fpic    -fpic +    -fpie          =>  -fpie 
   -fpic    -fpic +    -fPIE          =>  -fpie 
   -fpic    -fpic + -fno-pic          =>  -fno-pic 
   -fpic    -fpic + -fno-pie          =>  -fno-pie 
   -fpic    -fPIC +                   =>  -fno-pie 
   -fpic    -fPIC +    -fpic          =>  -fpic 
   -fpic    -fPIC +    -fPIC          =>  -fPIC 
   -fpic    -fPIC +    -fpie          =>  -fpie 
   -fpic    -fPIC +    -fPIE          =>  -fPIE 
   -fpic    -fPIC + -fno-pic          =>  -fno-pic 
   -fpic    -fPIC + -fno-pie          =>  -fno-pie 
   -fpic    -fpie +                   =>  -fno-pie 
   -fpic    -fpie +    -fpic          =>  -fpie 
   -fpic    -fpie +    -fPIC          =>  -fpie 
   -fpic    -fpie +    -fpie          =>  -fpie 
   -fpic    -fpie +    -fPIE          =>  -fpie 
   -fpic    -fpie + -fno-pic          =>  -fno-pie 
   -fpic    -fpie + -fno-pie          =>  -fno-pie 
   -fpic    -fPIE +                   =>  -fno-pie 
   -fpic    -fPIE +    -fpic          =>  -fpie 
   -fpic    -fPIE +    -fPIC          =>  -fPIE 
   -fpic    -fPIE +    -fpie          =>  -fpie 
   -fpic    -fPIE +    -fPIE          =>  -fPIE 
   -fpic    -fPIE + -fno-pic          =>  -fno-pie 
   -fpic    -fPIE + -fno-pie          =>  -fno-pie 
   -fpic -fno-pic +                   =>  -fno-pic 
   -fpic -fno-pic +    -fpic          =>  -fno-pic 
   -fpic -fno-pic +    -fPIC          =>  -fno-pic 
   -fpic -fno-pic +    -fpie          =>  -fno-pic 
   -fpic -fno-pic +    -fPIE          =>  -fno-pic 
   -fpic -fno-pic + -fno-pic          =>  -fno-pic 
   -fpic -fno-pic + -fno-pie          =>  -fno-pic 
   -fpic -fno-pie +                   =>  -fno-pie 
   -fpic -fno-pie +    -fpic          =>  -fno-pie 
   -fpic -fno-pie +    -fPIC          =>  -fno-pie 
   -fpic -fno-pie +    -fpie          =>  -fno-pie 
   -fpic -fno-pie +    -fPIE          =>  -fno-pie 
   -fpic -fno-pie + -fno-pic          =>  -fno-pie 
   -fpic -fno-pie + -fno-pie          =>  -fno-pie 
   -fpic          +             -fpic =>  -fpic 
   -fpic          +    -fpic    -fpic =>  -fpic 
   -fpic          +    -fPIC    -fpic =>  -fpic 
   -fpic          +    -fpie    -fpic =>  -fpic 
   -fpic          +    -fPIE    -fpic =>  -fpic 
   -fpic          + -fno-pic    -fpic =>  -fpic 
   -fpic          + -fno-pie    -fpic =>  -fpic 
   -fpic    -fpic +             -fpic =>  -fpic 
   -fpic    -fpic +    -fpic    -fpic =>  -fpic 
   -fpic    -fpic +    -fPIC    -fpic =>  -fpic 
   -fpic    -fpic +    -fpie    -fpic =>  -fpic 
   -fpic    -fpic +    -fPIE    -fpic =>  -fpic 
   -fpic    -fpic + -fno-pic    -fpic =>  -fpic 
   -fpic    -fpic + -fno-pie    -fpic =>  -fpic 
   -fpic    -fPIC +             -fpic =>  -fpic 
   -fpic    -fPIC +    -fpic    -fpic =>  -fpic 
   -fpic    -fPIC +    -fPIC    -fpic =>  -fpic 
   -fpic    -fPIC +    -fpie    -fpic =>  -fpic 
   -fpic    -fPIC +    -fPIE    -fpic =>  -fpic 
   -fpic    -fPIC + -fno-pic    -fpic =>  -fpic 
   -fpic    -fPIC + -fno-pie    -fpic =>  -fpic 
   -fpic    -fpie +             -fpic =>  -fpie 
   -fpic    -fpie +    -fpic    -fpic =>  -fpie 
   -fpic    -fpie +    -fPIC    -fpic =>  -fpie 
   -fpic    -fpie +    -fpie    -fpic =>  -fpie 
   -fpic    -fpie +    -fPIE    -fpic =>  -fpie 
   -fpic    -fpie + -fno-pic    -fpic =>  -fpie 
   -fpic    -fpie + -fno-pie    -fpic =>  -fpie 
   -fpic    -fPIE +             -fpic =>  -fpie 
   -fpic    -fPIE +    -fpic    -fpic =>  -fpie 
   -fpic    -fPIE +    -fPIC    -fpic =>  -fpie 
   -fpic    -fPIE +    -fpie    -fpic =>  -fpie 
   -fpic    -fPIE +    -fPIE    -fpic =>  -fpie 
   -fpic    -fPIE + -fno-pic    -fpic =>  -fpie 
   -fpic    -fPIE + -fno-pie    -fpic =>  -fpie 
   -fpic -fno-pic +             -fpic =>  -fno-pic 
   -fpic -fno-pic +    -fpic    -fpic =>  -fno-pic 
   -fpic -fno-pic +    -fPIC    -fpic =>  -fno-pic 
   -fpic -fno-pic +    -fpie    -fpic =>  -fno-pic 
   -fpic -fno-pic +    -fPIE    -fpic =>  -fno-pic 
   -fpic -fno-pic + -fno-pic    -fpic =>  -fno-pic 
   -fpic -fno-pic + -fno-pie    -fpic =>  -fno-pic 
   -fpic -fno-pie +             -fpic =>  -fno-pie 
   -fpic -fno-pie +    -fpic    -fpic =>  -fno-pie 
   -fpic -fno-pie +    -fPIC    -fpic =>  -fno-pie 
   -fpic -fno-pie +    -fpie    -fpic =>  -fno-pie 
   -fpic -fno-pie +    -fPIE    -fpic =>  -fno-pie 
   -fpic -fno-pie + -fno-pic    -fpic =>  -fno-pie 
   -fpic -fno-pie + -fno-pie    -fpic =>  -fno-pie 
   -fpic          +             -fPIC =>  -fpic 
   -fpic          +    -fpic    -fPIC =>  -fpic 
   -fpic          +    -fPIC    -fPIC =>  -fpic 
   -fpic          +    -fpie    -fPIC =>  -fpic 
   -fpic          +    -fPIE    -fPIC =>  -fpic 
   -fpic          + -fno-pic    -fPIC =>  -fpic 
   -fpic          + -fno-pie    -fPIC =>  -fpic 
   -fpic    -fpic +             -fPIC =>  -fpic 
   -fpic    -fpic +    -fpic    -fPIC =>  -fpic 
   -fpic    -fpic +    -fPIC    -fPIC =>  -fpic 
   -fpic    -fpic +    -fpie    -fPIC =>  -fpic 
   -fpic    -fpic +    -fPIE    -fPIC =>  -fpic 
   -fpic    -fpic + -fno-pic    -fPIC =>  -fpic 
   -fpic    -fpic + -fno-pie    -fPIC =>  -fpic 
   -fpic    -fPIC +             -fPIC =>  -fPIC 
   -fpic    -fPIC +    -fpic    -fPIC =>  -fPIC 
   -fpic    -fPIC +    -fPIC    -fPIC =>  -fPIC 
   -fpic    -fPIC +    -fpie    -fPIC =>  -fPIC 
   -fpic    -fPIC +    -fPIE    -fPIC =>  -fPIC 
   -fpic    -fPIC + -fno-pic    -fPIC =>  -fPIC 
   -fpic    -fPIC + -fno-pie    -fPIC =>  -fPIC 
   -fpic    -fpie +             -fPIC =>  -fpie 
   -fpic    -fpie +    -fpic    -fPIC =>  -fpie 
   -fpic    -fpie +    -fPIC    -fPIC =>  -fpie 
   -fpic    -fpie +    -fpie    -fPIC =>  -fpie 
   -fpic    -fpie +    -fPIE    -fPIC =>  -fpie 
   -fpic    -fpie + -fno-pic    -fPIC =>  -fpie 
   -fpic    -fpie + -fno-pie    -fPIC =>  -fpie 
   -fpic    -fPIE +             -fPIC =>  -fPIE 
   -fpic    -fPIE +    -fpic    -fPIC =>  -fPIE 
   -fpic    -fPIE +    -fPIC    -fPIC =>  -fPIE 
   -fpic    -fPIE +    -fpie    -fPIC =>  -fPIE 
   -fpic    -fPIE +    -fPIE    -fPIC =>  -fPIE 
   -fpic    -fPIE + -fno-pic    -fPIC =>  -fPIE 
   -fpic    -fPIE + -fno-pie    -fPIC =>  -fPIE 
   -fpic -fno-pic +             -fPIC =>  -fno-pic 
   -fpic -fno-pic +    -fpic    -fPIC =>  -fno-pic 
   -fpic -fno-pic +    -fPIC    -fPIC =>  -fno-pic 
   -fpic -fno-pic +    -fpie    -fPIC =>  -fno-pic 
   -fpic -fno-pic +    -fPIE    -fPIC =>  -fno-pic 
   -fpic -fno-pic + -fno-pic    -fPIC =>  -fno-pic 
   -fpic -fno-pic + -fno-pie    -fPIC =>  -fno-pic 
   -fpic -fno-pie +             -fPIC =>  -fno-pie 
   -fpic -fno-pie +    -fpic    -fPIC =>  -fno-pie 
   -fpic -fno-pie +    -fPIC    -fPIC =>  -fno-pie 
   -fpic -fno-pie +    -fpie    -fPIC =>  -fno-pie 
   -fpic -fno-pie +    -fPIE    -fPIC =>  -fno-pie 
   -fpic -fno-pie + -fno-pic    -fPIC =>  -fno-pie 
   -fpic -fno-pie + -fno-pie    -fPIC =>  -fno-pie 
   -fpic          +             -fpie =>  -fpie 
   -fpic          +    -fpic    -fpie =>  -fpie 
   -fpic          +    -fPIC    -fpie =>  -fpie 
   -fpic          +    -fpie    -fpie =>  -fpie 
   -fpic          +    -fPIE    -fpie =>  -fpie 
   -fpic          + -fno-pic    -fpie =>  -fpie 
   -fpic          + -fno-pie    -fpie =>  -fpie 
   -fpic    -fpic +             -fpie =>  -fpie 
   -fpic    -fpic +    -fpic    -fpie =>  -fpie 
   -fpic    -fpic +    -fPIC    -fpie =>  -fpie 
   -fpic    -fpic +    -fpie    -fpie =>  -fpie 
   -fpic    -fpic +    -fPIE    -fpie =>  -fpie 
   -fpic    -fpic + -fno-pic    -fpie =>  -fpie 
   -fpic    -fpic + -fno-pie    -fpie =>  -fpie 
   -fpic    -fPIC +             -fpie =>  -fpie 
   -fpic    -fPIC +    -fpic    -fpie =>  -fpie 
   -fpic    -fPIC +    -fPIC    -fpie =>  -fpie 
   -fpic    -fPIC +    -fpie    -fpie =>  -fpie 
   -fpic    -fPIC +    -fPIE    -fpie =>  -fpie 
   -fpic    -fPIC + -fno-pic    -fpie =>  -fpie 
   -fpic    -fPIC + -fno-pie    -fpie =>  -fpie 
   -fpic    -fpie +             -fpie =>  -fpie 
   -fpic    -fpie +    -fpic    -fpie =>  -fpie 
   -fpic    -fpie +    -fPIC    -fpie =>  -fpie 
   -fpic    -fpie +    -fpie    -fpie =>  -fpie 
   -fpic    -fpie +    -fPIE    -fpie =>  -fpie 
   -fpic    -fpie + -fno-pic    -fpie =>  -fpie 
   -fpic    -fpie + -fno-pie    -fpie =>  -fpie 
   -fpic    -fPIE +             -fpie =>  -fpie 
   -fpic    -fPIE +    -fpic    -fpie =>  -fpie 
   -fpic    -fPIE +    -fPIC    -fpie =>  -fpie 
   -fpic    -fPIE +    -fpie    -fpie =>  -fpie 
   -fpic    -fPIE +    -fPIE    -fpie =>  -fpie 
   -fpic    -fPIE + -fno-pic    -fpie =>  -fpie 
   -fpic    -fPIE + -fno-pie    -fpie =>  -fpie 
   -fpic -fno-pic +             -fpie =>  -fno-pic 
   -fpic -fno-pic +    -fpic    -fpie =>  -fno-pic 
   -fpic -fno-pic +    -fPIC    -fpie =>  -fno-pic 
   -fpic -fno-pic +    -fpie    -fpie =>  -fno-pic 
   -fpic -fno-pic +    -fPIE    -fpie =>  -fno-pic 
   -fpic -fno-pic + -fno-pic    -fpie =>  -fno-pic 
   -fpic -fno-pic + -fno-pie    -fpie =>  -fno-pic 
   -fpic -fno-pie +             -fpie =>  -fno-pie 
   -fpic -fno-pie +    -fpic    -fpie =>  -fno-pie 
   -fpic -fno-pie +    -fPIC    -fpie =>  -fno-pie 
   -fpic -fno-pie +    -fpie    -fpie =>  -fno-pie 
   -fpic -fno-pie +    -fPIE    -fpie =>  -fno-pie 
   -fpic -fno-pie + -fno-pic    -fpie =>  -fno-pie 
   -fpic -fno-pie + -fno-pie    -fpie =>  -fno-pie 
   -fpic          +             -fPIE =>  -fpie 
   -fpic          +    -fpic    -fPIE =>  -fpie 
   -fpic          +    -fPIC    -fPIE =>  -fpie 
   -fpic          +    -fpie    -fPIE =>  -fpie 
   -fpic          +    -fPIE    -fPIE =>  -fpie 
   -fpic          + -fno-pic    -fPIE =>  -fpie 
   -fpic          + -fno-pie    -fPIE =>  -fpie 
   -fpic    -fpic +             -fPIE =>  -fpie 
   -fpic    -fpic +    -fpic    -fPIE =>  -fpie 
   -fpic    -fpic +    -fPIC    -fPIE =>  -fpie 
   -fpic    -fpic +    -fpie    -fPIE =>  -fpie 
   -fpic    -fpic +    -fPIE    -fPIE =>  -fpie 
   -fpic    -fpic + -fno-pic    -fPIE =>  -fpie 
   -fpic    -fpic + -fno-pie    -fPIE =>  -fpie 
   -fpic    -fPIC +             -fPIE =>  -fPIE 
   -fpic    -fPIC +    -fpic    -fPIE =>  -fPIE 
   -fpic    -fPIC +    -fPIC    -fPIE =>  -fPIE 
   -fpic    -fPIC +    -fpie    -fPIE =>  -fPIE 
   -fpic    -fPIC +    -fPIE    -fPIE =>  -fPIE 
   -fpic    -fPIC + -fno-pic    -fPIE =>  -fPIE 
   -fpic    -fPIC + -fno-pie    -fPIE =>  -fPIE 
   -fpic    -fpie +             -fPIE =>  -fpie 
   -fpic    -fpie +    -fpic    -fPIE =>  -fpie 
   -fpic    -fpie +    -fPIC    -fPIE =>  -fpie 
   -fpic    -fpie +    -fpie    -fPIE =>  -fpie 
   -fpic    -fpie +    -fPIE    -fPIE =>  -fpie 
   -fpic    -fpie + -fno-pic    -fPIE =>  -fpie 
   -fpic    -fpie + -fno-pie    -fPIE =>  -fpie 
   -fpic    -fPIE +             -fPIE =>  -fPIE 
   -fpic    -fPIE +    -fpic    -fPIE =>  -fPIE 
   -fpic    -fPIE +    -fPIC    -fPIE =>  -fPIE 
   -fpic    -fPIE +    -fpie    -fPIE =>  -fPIE 
   -fpic    -fPIE +    -fPIE    -fPIE =>  -fPIE 
   -fpic    -fPIE + -fno-pic    -fPIE =>  -fPIE 
   -fpic    -fPIE + -fno-pie    -fPIE =>  -fPIE 
   -fpic -fno-pic +             -fPIE =>  -fno-pic 
   -fpic -fno-pic +    -fpic    -fPIE =>  -fno-pic 
   -fpic -fno-pic +    -fPIC    -fPIE =>  -fno-pic 
   -fpic -fno-pic +    -fpie    -fPIE =>  -fno-pic 
   -fpic -fno-pic +    -fPIE    -fPIE =>  -fno-pic 
   -fpic -fno-pic + -fno-pic    -fPIE =>  -fno-pic 
   -fpic -fno-pic + -fno-pie    -fPIE =>  -fno-pic 
   -fpic -fno-pie +             -fPIE =>  -fno-pie 
   -fpic -fno-pie +    -fpic    -fPIE =>  -fno-pie 
   -fpic -fno-pie +    -fPIC    -fPIE =>  -fno-pie 
   -fpic -fno-pie +    -fpie    -fPIE =>  -fno-pie 
   -fpic -fno-pie +    -fPIE    -fPIE =>  -fno-pie 
   -fpic -fno-pie + -fno-pic    -fPIE =>  -fno-pie 
   -fpic -fno-pie + -fno-pie    -fPIE =>  -fno-pie 
   -fpic          +          -fno-pic =>  -fno-pic 
   -fpic          +    -fpic -fno-pic =>  -fno-pic 
   -fpic          +    -fPIC -fno-pic =>  -fno-pic 
   -fpic          +    -fpie -fno-pic =>  -fno-pic 
   -fpic          +    -fPIE -fno-pic =>  -fno-pic 
   -fpic          + -fno-pic -fno-pic =>  -fno-pic 
   -fpic          + -fno-pie -fno-pic =>  -fno-pic 
   -fpic    -fpic +          -fno-pic =>  -fno-pic 
   -fpic    -fpic +    -fpic -fno-pic =>  -fno-pic 
   -fpic    -fpic +    -fPIC -fno-pic =>  -fno-pic 
   -fpic    -fpic +    -fpie -fno-pic =>  -fno-pic 
   -fpic    -fpic +    -fPIE -fno-pic =>  -fno-pic 
   -fpic    -fpic + -fno-pic -fno-pic =>  -fno-pic 
   -fpic    -fpic + -fno-pie -fno-pic =>  -fno-pic 
   -fpic    -fPIC +          -fno-pic =>  -fno-pic 
   -fpic    -fPIC +    -fpic -fno-pic =>  -fno-pic 
   -fpic    -fPIC +    -fPIC -fno-pic =>  -fno-pic 
   -fpic    -fPIC +    -fpie -fno-pic =>  -fno-pic 
   -fpic    -fPIC +    -fPIE -fno-pic =>  -fno-pic 
   -fpic    -fPIC + -fno-pic -fno-pic =>  -fno-pic 
   -fpic    -fPIC + -fno-pie -fno-pic =>  -fno-pic 
   -fpic    -fpie +          -fno-pic =>  -fno-pie 
   -fpic    -fpie +    -fpic -fno-pic =>  -fno-pie 
   -fpic    -fpie +    -fPIC -fno-pic =>  -fno-pie 
   -fpic    -fpie +    -fpie -fno-pic =>  -fno-pie 
   -fpic    -fpie +    -fPIE -fno-pic =>  -fno-pie 
   -fpic    -fpie + -fno-pic -fno-pic =>  -fno-pie 
   -fpic    -fpie + -fno-pie -fno-pic =>  -fno-pie 
   -fpic    -fPIE +          -fno-pic =>  -fno-pie 
   -fpic    -fPIE +    -fpic -fno-pic =>  -fno-pie 
   -fpic    -fPIE +    -fPIC -fno-pic =>  -fno-pie 
   -fpic    -fPIE +    -fpie -fno-pic =>  -fno-pie 
   -fpic    -fPIE +    -fPIE -fno-pic =>  -fno-pie 
   -fpic    -fPIE + -fno-pic -fno-pic =>  -fno-pie 
   -fpic    -fPIE + -fno-pie -fno-pic =>  -fno-pie 
   -fpic -fno-pic +          -fno-pic =>  -fno-pic 
   -fpic -fno-pic +    -fpic -fno-pic =>  -fno-pic 
   -fpic -fno-pic +    -fPIC -fno-pic =>  -fno-pic 
   -fpic -fno-pic +    -fpie -fno-pic =>  -fno-pic 
   -fpic -fno-pic +    -fPIE -fno-pic =>  -fno-pic 
   -fpic -fno-pic + -fno-pic -fno-pic =>  -fno-pic 
   -fpic -fno-pic + -fno-pie -fno-pic =>  -fno-pic 
   -fpic -fno-pie +          -fno-pic =>  -fno-pie 
   -fpic -fno-pie +    -fpic -fno-pic =>  -fno-pie 
   -fpic -fno-pie +    -fPIC -fno-pic =>  -fno-pie 
   -fpic -fno-pie +    -fpie -fno-pic =>  -fno-pie 
   -fpic -fno-pie +    -fPIE -fno-pic =>  -fno-pie 
   -fpic -fno-pie + -fno-pic -fno-pic =>  -fno-pie 
   -fpic -fno-pie + -fno-pie -fno-pic =>  -fno-pie 
   -fpic          +          -fno-pie =>  -fno-pie 
   -fpic          +    -fpic -fno-pie =>  -fno-pie 
   -fpic          +    -fPIC -fno-pie =>  -fno-pie 
   -fpic          +    -fpie -fno-pie =>  -fno-pie 
   -fpic          +    -fPIE -fno-pie =>  -fno-pie 
   -fpic          + -fno-pic -fno-pie =>  -fno-pie 
   -fpic          + -fno-pie -fno-pie =>  -fno-pie 
   -fpic    -fpic +          -fno-pie =>  -fno-pie 
   -fpic    -fpic +    -fpic -fno-pie =>  -fno-pie 
   -fpic    -fpic +    -fPIC -fno-pie =>  -fno-pie 
   -fpic    -fpic +    -fpie -fno-pie =>  -fno-pie 
   -fpic    -fpic +    -fPIE -fno-pie =>  -fno-pie 
   -fpic    -fpic + -fno-pic -fno-pie =>  -fno-pie 
   -fpic    -fpic + -fno-pie -fno-pie =>  -fno-pie 
   -fpic    -fPIC +          -fno-pie =>  -fno-pie 
   -fpic    -fPIC +    -fpic -fno-pie =>  -fno-pie 
   -fpic    -fPIC +    -fPIC -fno-pie =>  -fno-pie 
   -fpic    -fPIC +    -fpie -fno-pie =>  -fno-pie 
   -fpic    -fPIC +    -fPIE -fno-pie =>  -fno-pie 
   -fpic    -fPIC + -fno-pic -fno-pie =>  -fno-pie 
   -fpic    -fPIC + -fno-pie -fno-pie =>  -fno-pie 
   -fpic    -fpie +          -fno-pie =>

Comments

Martin Liška Aug. 14, 2018, 7:17 a.m. | #1
On 08/10/2018 04:33 PM, Jan Hubicka wrote:
> Hi,
> this patch should fix merging of PIC and PIE options so we always resort
> to the least common denominator of the object files compiled (i.e. 
> linking together -fpic and -fPIE will result in -fpie binary).
> Note that we also use information about format of output passed by linker
> plugin so we will disable pic/pie when resulting binary is not relocatable.
> However for shared libraries and pie we want to pick right mode that makes
> sense.
> 
> I wrote simple script that tries all possible options of combining two files.
> Mode picked is specified in the output file.
> 
> To support targets that default to pic/pie well, I had to also hack
> lto_write_options to always stream what mode was used in the given file.
> 
> lto-bootstrapped/regtested x86_64-linux, OK?
> 
> Honza

Thank you Honza for it. Would it be then subject for backporting into GCC-8 branch?

Martin

> 
> 	PR lto/86517
> 	* lto-opts.c (lto_write_options): Always stream PIC/PIE mode.
> 	* lto-wrapper.c (merge_and_complain): Fix merging of PIC/PIE
> Index: lto-opts.c
> ===================================================================
> --- lto-opts.c	(revision 263356)
> +++ lto-opts.c	(working copy)
> @@ -78,6 +78,22 @@ lto_write_options (void)
>        && !global_options.x_flag_openacc)
>      append_to_collect_gcc_options (&temporary_obstack, &first_p,
>  				   "-fno-openacc");
> +  /* Append PIC/PIE mode because its default depends on target and it is
> +     subject of merging in lto-wrapper.  */
> +  if ((!global_options_set.x_flag_pic || global_options.x_flag_pic == 0)
> +      && !global_options_set.x_flag_pie)
> +    {
> +       append_to_collect_gcc_options (&temporary_obstack, &first_p,
> +				      global_options.x_flag_pic == 2
> +				      ? "-fPIC"
> +				      : global_options.x_flag_pic == 1
> +				      ? "-fpic"
> +				      : global_options.x_flag_pie == 2
> +				      ? "-fPIE"
> +				      : global_options.x_flag_pie == 1
> +				      ? "-fpie"
> +				      : "-fno-pie");
> +    }
>  
>    /* Append options from target hook and store them to offload_lto section.  */
>    if (lto_stream_offload_p)
> Index: lto-wrapper.c
> ===================================================================
> --- lto-wrapper.c	(revision 263356)
> +++ lto-wrapper.c	(working copy)
> @@ -408,6 +408,11 @@ merge_and_complain (struct cl_decoded_op
>       It is a common mistake to mix few -fPIC compiled objects into otherwise
>       non-PIC code.  We do not want to build everything with PIC then.
>  
> +     Similarly we merge PIE options, however in addition we keep
> +      -fPIC + -fPIE = -fPIE
> +      -fpic + -fPIE = -fpie
> +      -fPIC/-fpic + -fpie = -fpie
> +
>       It would be good to warn on mismatches, but it is bit hard to do as
>       we do not know what nothing translates to.  */
>      
> @@ -415,11 +420,38 @@ merge_and_complain (struct cl_decoded_op
>      if ((*decoded_options)[j].opt_index == OPT_fPIC
>          || (*decoded_options)[j].opt_index == OPT_fpic)
>        {
> -	if (!pic_option
> -	    || (pic_option->value > 0) != ((*decoded_options)[j].value > 0))
> -	  remove_option (decoded_options, j, decoded_options_count);
> -	else if (pic_option->opt_index == OPT_fPIC
> -		 && (*decoded_options)[j].opt_index == OPT_fpic)
> +	/* -fno-pic in one unit implies -fno-pic everywhere.  */
> +	if ((*decoded_options)[j].value == 0)
> +	  j++;
> +	/* If we have no pic option or merge in -fno-pic, we still may turn
> +	   existing pic/PIC mode into pie/PIE if -fpie/-fPIE is present.  */
> +	else if ((pic_option && pic_option->value == 0)
> +		 || !pic_option)
> +	  {
> +	    if (pie_option)
> +	      {
> +		bool big = (*decoded_options)[j].opt_index == OPT_fPIC
> +			   && pie_option->opt_index == OPT_fPIE;
> +	        (*decoded_options)[j].opt_index = big ? OPT_fPIE : OPT_fpie;
> +		if (pie_option->value)
> +	          (*decoded_options)[j].canonical_option[0] = big ? "-fPIE" : "-fpie";
> +		else
> +	          (*decoded_options)[j].canonical_option[0] = big ? "-fno-pie" : "-fno-pie";
> +		(*decoded_options)[j].value = pie_option->value;
> +	        j++;
> +	      }
> +	    else if (pic_option)
> +	      {
> +	        (*decoded_options)[j] = *pic_option;
> +	        j++;
> +	      }
> +	    /* We do not know if target defaults to pic or not, so just remove
> +	       option if it is missing in one unit but enabled in other.  */
> +	    else
> +	      remove_option (decoded_options, j, decoded_options_count);
> +	  }
> +	else if (pic_option->opt_index == OPT_fpic
> +		 && (*decoded_options)[j].opt_index == OPT_fPIC)
>  	  {
>  	    (*decoded_options)[j] = *pic_option;
>  	    j++;
> @@ -430,11 +462,42 @@ merge_and_complain (struct cl_decoded_op
>     else if ((*decoded_options)[j].opt_index == OPT_fPIE
>              || (*decoded_options)[j].opt_index == OPT_fpie)
>        {
> -	if (!pie_option
> -	    || pie_option->value != (*decoded_options)[j].value)
> -	  remove_option (decoded_options, j, decoded_options_count);
> -	else if (pie_option->opt_index == OPT_fPIE
> -		 && (*decoded_options)[j].opt_index == OPT_fpie)
> +	/* -fno-pie in one unit implies -fno-pie everywhere.  */
> +	if ((*decoded_options)[j].value == 0)
> +	  j++;
> +	/* If we have no pie option or merge in -fno-pie, we still preserve
> +	   PIE/pie if pic/PIC is present.  */
> +	else if ((pie_option && pie_option->value == 0)
> +		 || !pie_option)
> +	  {
> +	    /* If -fPIC/-fpic is given, merge it with -fPIE/-fpie.  */
> +	    if (pic_option)
> +	      {
> +		if (pic_option->opt_index == OPT_fpic
> +		    && (*decoded_options)[j].opt_index == OPT_fPIE)
> +		  {
> +	            (*decoded_options)[j].opt_index = OPT_fpie;
> +	            (*decoded_options)[j].canonical_option[0]
> +			 = pic_option->value ? "-fpie" : "-fno-pie";
> +		  }
> +		else if (!pic_option->value)
> +		  (*decoded_options)[j].canonical_option[0] = "-fno-pie";
> +		(*decoded_options)[j].value = pic_option->value;
> +		j++;
> +	      }
> +	    else if (pie_option)
> +	      {
> +	        (*decoded_options)[j] = *pie_option;
> +		j++;
> +	      }
> +	    /* Because we always append pic/PIE options this code path should
> +	       not happen unless the LTO object was built by old lto1 which
> +	       did not contain that logic yet.  */
> +	    else
> +	      remove_option (decoded_options, j, decoded_options_count);
> +	  }
> +	else if (pie_option->opt_index == OPT_fpie
> +		 && (*decoded_options)[j].opt_index == OPT_fPIE)
>  	  {
>  	    (*decoded_options)[j] = *pie_option;
>  	    j++;
>
Richard Biener Aug. 20, 2018, 12:33 p.m. | #2
On Fri, 10 Aug 2018, Jan Hubicka wrote:

> Hi,
> this patch should fix merging of PIC and PIE options so we always resort
> to the least common denominator of the object files compiled (i.e. 
> linking together -fpic and -fPIE will result in -fpie binary).
> Note that we also use information about format of output passed by linker
> plugin so we will disable pic/pie when resulting binary is not relocatable.
> However for shared libraries and pie we want to pick right mode that makes
> sense.
> 
> I wrote simple script that tries all possible options of combining two files.
> Mode picked is specified in the output file.
> 
> To support targets that default to pic/pie well, I had to also hack
> lto_write_options to always stream what mode was used in the given file.
> 
> lto-bootstrapped/regtested x86_64-linux, OK?
> 
> Honza
> 
> 	PR lto/86517
> 	* lto-opts.c (lto_write_options): Always stream PIC/PIE mode.
> 	* lto-wrapper.c (merge_and_complain): Fix merging of PIC/PIE
> Index: lto-opts.c
> ===================================================================
> --- lto-opts.c	(revision 263356)
> +++ lto-opts.c	(working copy)
> @@ -78,6 +78,22 @@ lto_write_options (void)
>        && !global_options.x_flag_openacc)
>      append_to_collect_gcc_options (&temporary_obstack, &first_p,
>  				   "-fno-openacc");
> +  /* Append PIC/PIE mode because its default depends on target and it is
> +     subject of merging in lto-wrapper.  */
> +  if ((!global_options_set.x_flag_pic || global_options.x_flag_pic == 0)

why's that checked only for flag_pic?
Shouldn't it be consistent with flag_pie?

Isn't it so that setting either -f[no-]pic or -f[no-]pie fully specifies
the state?  So the == 0 check is superfluous?

The rest of the patch looks OK to me.

Thanks,
Richard.

> +      && !global_options_set.x_flag_pie)
> +    {
> +       append_to_collect_gcc_options (&temporary_obstack, &first_p,
> +				      global_options.x_flag_pic == 2
> +				      ? "-fPIC"
> +				      : global_options.x_flag_pic == 1
> +				      ? "-fpic"
> +				      : global_options.x_flag_pie == 2
> +				      ? "-fPIE"
> +				      : global_options.x_flag_pie == 1
> +				      ? "-fpie"
> +				      : "-fno-pie");
> +    }
>  
>    /* Append options from target hook and store them to offload_lto section.  */
>    if (lto_stream_offload_p)
> Index: lto-wrapper.c
> ===================================================================
> --- lto-wrapper.c	(revision 263356)
> +++ lto-wrapper.c	(working copy)
> @@ -408,6 +408,11 @@ merge_and_complain (struct cl_decoded_op
>       It is a common mistake to mix few -fPIC compiled objects into otherwise
>       non-PIC code.  We do not want to build everything with PIC then.
>  
> +     Similarly we merge PIE options, however in addition we keep
> +      -fPIC + -fPIE = -fPIE
> +      -fpic + -fPIE = -fpie
> +      -fPIC/-fpic + -fpie = -fpie
> +
>       It would be good to warn on mismatches, but it is bit hard to do as
>       we do not know what nothing translates to.  */
>      
> @@ -415,11 +420,38 @@ merge_and_complain (struct cl_decoded_op
>      if ((*decoded_options)[j].opt_index == OPT_fPIC
>          || (*decoded_options)[j].opt_index == OPT_fpic)
>        {
> -	if (!pic_option
> -	    || (pic_option->value > 0) != ((*decoded_options)[j].value > 0))
> -	  remove_option (decoded_options, j, decoded_options_count);
> -	else if (pic_option->opt_index == OPT_fPIC
> -		 && (*decoded_options)[j].opt_index == OPT_fpic)
> +	/* -fno-pic in one unit implies -fno-pic everywhere.  */
> +	if ((*decoded_options)[j].value == 0)
> +	  j++;
> +	/* If we have no pic option or merge in -fno-pic, we still may turn
> +	   existing pic/PIC mode into pie/PIE if -fpie/-fPIE is present.  */
> +	else if ((pic_option && pic_option->value == 0)
> +		 || !pic_option)
> +	  {
> +	    if (pie_option)
> +	      {
> +		bool big = (*decoded_options)[j].opt_index == OPT_fPIC
> +			   && pie_option->opt_index == OPT_fPIE;
> +	        (*decoded_options)[j].opt_index = big ? OPT_fPIE : OPT_fpie;
> +		if (pie_option->value)
> +	          (*decoded_options)[j].canonical_option[0] = big ? "-fPIE" : "-fpie";
> +		else
> +	          (*decoded_options)[j].canonical_option[0] = big ? "-fno-pie" : "-fno-pie";
> +		(*decoded_options)[j].value = pie_option->value;
> +	        j++;
> +	      }
> +	    else if (pic_option)
> +	      {
> +	        (*decoded_options)[j] = *pic_option;
> +	        j++;
> +	      }
> +	    /* We do not know if target defaults to pic or not, so just remove
> +	       option if it is missing in one unit but enabled in other.  */
> +	    else
> +	      remove_option (decoded_options, j, decoded_options_count);
> +	  }
> +	else if (pic_option->opt_index == OPT_fpic
> +		 && (*decoded_options)[j].opt_index == OPT_fPIC)
>  	  {
>  	    (*decoded_options)[j] = *pic_option;
>  	    j++;
> @@ -430,11 +462,42 @@ merge_and_complain (struct cl_decoded_op
>     else if ((*decoded_options)[j].opt_index == OPT_fPIE
>              || (*decoded_options)[j].opt_index == OPT_fpie)
>        {
> -	if (!pie_option
> -	    || pie_option->value != (*decoded_options)[j].value)
> -	  remove_option (decoded_options, j, decoded_options_count);
> -	else if (pie_option->opt_index == OPT_fPIE
> -		 && (*decoded_options)[j].opt_index == OPT_fpie)
> +	/* -fno-pie in one unit implies -fno-pie everywhere.  */
> +	if ((*decoded_options)[j].value == 0)
> +	  j++;
> +	/* If we have no pie option or merge in -fno-pie, we still preserve
> +	   PIE/pie if pic/PIC is present.  */
> +	else if ((pie_option && pie_option->value == 0)
> +		 || !pie_option)
> +	  {
> +	    /* If -fPIC/-fpic is given, merge it with -fPIE/-fpie.  */
> +	    if (pic_option)
> +	      {
> +		if (pic_option->opt_index == OPT_fpic
> +		    && (*decoded_options)[j].opt_index == OPT_fPIE)
> +		  {
> +	            (*decoded_options)[j].opt_index = OPT_fpie;
> +	            (*decoded_options)[j].canonical_option[0]
> +			 = pic_option->value ? "-fpie" : "-fno-pie";
> +		  }
> +		else if (!pic_option->value)
> +		  (*decoded_options)[j].canonical_option[0] = "-fno-pie";
> +		(*decoded_options)[j].value = pic_option->value;
> +		j++;
> +	      }
> +	    else if (pie_option)
> +	      {
> +	        (*decoded_options)[j] = *pie_option;
> +		j++;
> +	      }
> +	    /* Because we always append pic/PIE options this code path should
> +	       not happen unless the LTO object was built by old lto1 which
> +	       did not contain that logic yet.  */
> +	    else
> +	      remove_option (decoded_options, j, decoded_options_count);
> +	  }
> +	else if (pie_option->opt_index == OPT_fpie
> +		 && (*decoded_options)[j].opt_index == OPT_fPIE)
>  	  {
>  	    (*decoded_options)[j] = *pie_option;
>  	    j++;
>
Jan Hubicka Aug. 30, 2018, 3:48 p.m. | #3
> On Fri, 10 Aug 2018, Jan Hubicka wrote:
> 
> > Hi,
> > this patch should fix merging of PIC and PIE options so we always resort
> > to the least common denominator of the object files compiled (i.e. 
> > linking together -fpic and -fPIE will result in -fpie binary).
> > Note that we also use information about format of output passed by linker
> > plugin so we will disable pic/pie when resulting binary is not relocatable.
> > However for shared libraries and pie we want to pick right mode that makes
> > sense.
> > 
> > I wrote simple script that tries all possible options of combining two files.
> > Mode picked is specified in the output file.
> > 
> > To support targets that default to pic/pie well, I had to also hack
> > lto_write_options to always stream what mode was used in the given file.
> > 
> > lto-bootstrapped/regtested x86_64-linux, OK?
> > 
> > Honza
> > 
> > 	PR lto/86517
> > 	* lto-opts.c (lto_write_options): Always stream PIC/PIE mode.
> > 	* lto-wrapper.c (merge_and_complain): Fix merging of PIC/PIE
> > Index: lto-opts.c
> > ===================================================================
> > --- lto-opts.c	(revision 263356)
> > +++ lto-opts.c	(working copy)
> > @@ -78,6 +78,22 @@ lto_write_options (void)
> >        && !global_options.x_flag_openacc)
> >      append_to_collect_gcc_options (&temporary_obstack, &first_p,
> >  				   "-fno-openacc");
> > +  /* Append PIC/PIE mode because its default depends on target and it is
> > +     subject of merging in lto-wrapper.  */
> > +  if ((!global_options_set.x_flag_pic || global_options.x_flag_pic == 0)
> 
> why's that checked only for flag_pic?
> Shouldn't it be consistent with flag_pie?
> 
> Isn't it so that setting either -f[no-]pic or -f[no-]pie fully specifies
> the state?  So the == 0 check is superfluous?

Yep, it is superflows. I have changed it to test if at least one option is set,
re-tested and going to commit.

OK for release branch after some soaking?
Honza

> 
> The rest of the patch looks OK to me.
> 
> Thanks,
> Richard.
> 
> > +      && !global_options_set.x_flag_pie)
> > +    {
> > +       append_to_collect_gcc_options (&temporary_obstack, &first_p,
> > +				      global_options.x_flag_pic == 2
> > +				      ? "-fPIC"
> > +				      : global_options.x_flag_pic == 1
> > +				      ? "-fpic"
> > +				      : global_options.x_flag_pie == 2
> > +				      ? "-fPIE"
> > +				      : global_options.x_flag_pie == 1
> > +				      ? "-fpie"
> > +				      : "-fno-pie");
> > +    }
> >  
> >    /* Append options from target hook and store them to offload_lto section.  */
> >    if (lto_stream_offload_p)
> > Index: lto-wrapper.c
> > ===================================================================
> > --- lto-wrapper.c	(revision 263356)
> > +++ lto-wrapper.c	(working copy)
> > @@ -408,6 +408,11 @@ merge_and_complain (struct cl_decoded_op
> >       It is a common mistake to mix few -fPIC compiled objects into otherwise
> >       non-PIC code.  We do not want to build everything with PIC then.
> >  
> > +     Similarly we merge PIE options, however in addition we keep
> > +      -fPIC + -fPIE = -fPIE
> > +      -fpic + -fPIE = -fpie
> > +      -fPIC/-fpic + -fpie = -fpie
> > +
> >       It would be good to warn on mismatches, but it is bit hard to do as
> >       we do not know what nothing translates to.  */
> >      
> > @@ -415,11 +420,38 @@ merge_and_complain (struct cl_decoded_op
> >      if ((*decoded_options)[j].opt_index == OPT_fPIC
> >          || (*decoded_options)[j].opt_index == OPT_fpic)
> >        {
> > -	if (!pic_option
> > -	    || (pic_option->value > 0) != ((*decoded_options)[j].value > 0))
> > -	  remove_option (decoded_options, j, decoded_options_count);
> > -	else if (pic_option->opt_index == OPT_fPIC
> > -		 && (*decoded_options)[j].opt_index == OPT_fpic)
> > +	/* -fno-pic in one unit implies -fno-pic everywhere.  */
> > +	if ((*decoded_options)[j].value == 0)
> > +	  j++;
> > +	/* If we have no pic option or merge in -fno-pic, we still may turn
> > +	   existing pic/PIC mode into pie/PIE if -fpie/-fPIE is present.  */
> > +	else if ((pic_option && pic_option->value == 0)
> > +		 || !pic_option)
> > +	  {
> > +	    if (pie_option)
> > +	      {
> > +		bool big = (*decoded_options)[j].opt_index == OPT_fPIC
> > +			   && pie_option->opt_index == OPT_fPIE;
> > +	        (*decoded_options)[j].opt_index = big ? OPT_fPIE : OPT_fpie;
> > +		if (pie_option->value)
> > +	          (*decoded_options)[j].canonical_option[0] = big ? "-fPIE" : "-fpie";
> > +		else
> > +	          (*decoded_options)[j].canonical_option[0] = big ? "-fno-pie" : "-fno-pie";
> > +		(*decoded_options)[j].value = pie_option->value;
> > +	        j++;
> > +	      }
> > +	    else if (pic_option)
> > +	      {
> > +	        (*decoded_options)[j] = *pic_option;
> > +	        j++;
> > +	      }
> > +	    /* We do not know if target defaults to pic or not, so just remove
> > +	       option if it is missing in one unit but enabled in other.  */
> > +	    else
> > +	      remove_option (decoded_options, j, decoded_options_count);
> > +	  }
> > +	else if (pic_option->opt_index == OPT_fpic
> > +		 && (*decoded_options)[j].opt_index == OPT_fPIC)
> >  	  {
> >  	    (*decoded_options)[j] = *pic_option;
> >  	    j++;
> > @@ -430,11 +462,42 @@ merge_and_complain (struct cl_decoded_op
> >     else if ((*decoded_options)[j].opt_index == OPT_fPIE
> >              || (*decoded_options)[j].opt_index == OPT_fpie)
> >        {
> > -	if (!pie_option
> > -	    || pie_option->value != (*decoded_options)[j].value)
> > -	  remove_option (decoded_options, j, decoded_options_count);
> > -	else if (pie_option->opt_index == OPT_fPIE
> > -		 && (*decoded_options)[j].opt_index == OPT_fpie)
> > +	/* -fno-pie in one unit implies -fno-pie everywhere.  */
> > +	if ((*decoded_options)[j].value == 0)
> > +	  j++;
> > +	/* If we have no pie option or merge in -fno-pie, we still preserve
> > +	   PIE/pie if pic/PIC is present.  */
> > +	else if ((pie_option && pie_option->value == 0)
> > +		 || !pie_option)
> > +	  {
> > +	    /* If -fPIC/-fpic is given, merge it with -fPIE/-fpie.  */
> > +	    if (pic_option)
> > +	      {
> > +		if (pic_option->opt_index == OPT_fpic
> > +		    && (*decoded_options)[j].opt_index == OPT_fPIE)
> > +		  {
> > +	            (*decoded_options)[j].opt_index = OPT_fpie;
> > +	            (*decoded_options)[j].canonical_option[0]
> > +			 = pic_option->value ? "-fpie" : "-fno-pie";
> > +		  }
> > +		else if (!pic_option->value)
> > +		  (*decoded_options)[j].canonical_option[0] = "-fno-pie";
> > +		(*decoded_options)[j].value = pic_option->value;
> > +		j++;
> > +	      }
> > +	    else if (pie_option)
> > +	      {
> > +	        (*decoded_options)[j] = *pie_option;
> > +		j++;
> > +	      }
> > +	    /* Because we always append pic/PIE options this code path should
> > +	       not happen unless the LTO object was built by old lto1 which
> > +	       did not contain that logic yet.  */
> > +	    else
> > +	      remove_option (decoded_options, j, decoded_options_count);
> > +	  }
> > +	else if (pie_option->opt_index == OPT_fpie
> > +		 && (*decoded_options)[j].opt_index == OPT_fPIE)
> >  	  {
> >  	    (*decoded_options)[j] = *pie_option;
> >  	    j++;
> > 
> 
> -- 
> Richard Biener <rguenther@suse.de>
> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)
Richard Biener Aug. 31, 2018, 7:19 a.m. | #4
On Thu, 30 Aug 2018, Jan Hubicka wrote:

> > On Fri, 10 Aug 2018, Jan Hubicka wrote:
> > 
> > > Hi,
> > > this patch should fix merging of PIC and PIE options so we always resort
> > > to the least common denominator of the object files compiled (i.e. 
> > > linking together -fpic and -fPIE will result in -fpie binary).
> > > Note that we also use information about format of output passed by linker
> > > plugin so we will disable pic/pie when resulting binary is not relocatable.
> > > However for shared libraries and pie we want to pick right mode that makes
> > > sense.
> > > 
> > > I wrote simple script that tries all possible options of combining two files.
> > > Mode picked is specified in the output file.
> > > 
> > > To support targets that default to pic/pie well, I had to also hack
> > > lto_write_options to always stream what mode was used in the given file.
> > > 
> > > lto-bootstrapped/regtested x86_64-linux, OK?
> > > 
> > > Honza
> > > 
> > > 	PR lto/86517
> > > 	* lto-opts.c (lto_write_options): Always stream PIC/PIE mode.
> > > 	* lto-wrapper.c (merge_and_complain): Fix merging of PIC/PIE
> > > Index: lto-opts.c
> > > ===================================================================
> > > --- lto-opts.c	(revision 263356)
> > > +++ lto-opts.c	(working copy)
> > > @@ -78,6 +78,22 @@ lto_write_options (void)
> > >        && !global_options.x_flag_openacc)
> > >      append_to_collect_gcc_options (&temporary_obstack, &first_p,
> > >  				   "-fno-openacc");
> > > +  /* Append PIC/PIE mode because its default depends on target and it is
> > > +     subject of merging in lto-wrapper.  */
> > > +  if ((!global_options_set.x_flag_pic || global_options.x_flag_pic == 0)
> > 
> > why's that checked only for flag_pic?
> > Shouldn't it be consistent with flag_pie?
> > 
> > Isn't it so that setting either -f[no-]pic or -f[no-]pie fully specifies
> > the state?  So the == 0 check is superfluous?
> 
> Yep, it is superflows. I have changed it to test if at least one option is set,
> re-tested and going to commit.
> 
> OK for release branch after some soaking?

OK after Cauldron if nothing bad happened.

Richard.

> Honza
> 
> > 
> > The rest of the patch looks OK to me.
> > 
> > Thanks,
> > Richard.
> > 
> > > +      && !global_options_set.x_flag_pie)
> > > +    {
> > > +       append_to_collect_gcc_options (&temporary_obstack, &first_p,
> > > +				      global_options.x_flag_pic == 2
> > > +				      ? "-fPIC"
> > > +				      : global_options.x_flag_pic == 1
> > > +				      ? "-fpic"
> > > +				      : global_options.x_flag_pie == 2
> > > +				      ? "-fPIE"
> > > +				      : global_options.x_flag_pie == 1
> > > +				      ? "-fpie"
> > > +				      : "-fno-pie");
> > > +    }
> > >  
> > >    /* Append options from target hook and store them to offload_lto section.  */
> > >    if (lto_stream_offload_p)
> > > Index: lto-wrapper.c
> > > ===================================================================
> > > --- lto-wrapper.c	(revision 263356)
> > > +++ lto-wrapper.c	(working copy)
> > > @@ -408,6 +408,11 @@ merge_and_complain (struct cl_decoded_op
> > >       It is a common mistake to mix few -fPIC compiled objects into otherwise
> > >       non-PIC code.  We do not want to build everything with PIC then.
> > >  
> > > +     Similarly we merge PIE options, however in addition we keep
> > > +      -fPIC + -fPIE = -fPIE
> > > +      -fpic + -fPIE = -fpie
> > > +      -fPIC/-fpic + -fpie = -fpie
> > > +
> > >       It would be good to warn on mismatches, but it is bit hard to do as
> > >       we do not know what nothing translates to.  */
> > >      
> > > @@ -415,11 +420,38 @@ merge_and_complain (struct cl_decoded_op
> > >      if ((*decoded_options)[j].opt_index == OPT_fPIC
> > >          || (*decoded_options)[j].opt_index == OPT_fpic)
> > >        {
> > > -	if (!pic_option
> > > -	    || (pic_option->value > 0) != ((*decoded_options)[j].value > 0))
> > > -	  remove_option (decoded_options, j, decoded_options_count);
> > > -	else if (pic_option->opt_index == OPT_fPIC
> > > -		 && (*decoded_options)[j].opt_index == OPT_fpic)
> > > +	/* -fno-pic in one unit implies -fno-pic everywhere.  */
> > > +	if ((*decoded_options)[j].value == 0)
> > > +	  j++;
> > > +	/* If we have no pic option or merge in -fno-pic, we still may turn
> > > +	   existing pic/PIC mode into pie/PIE if -fpie/-fPIE is present.  */
> > > +	else if ((pic_option && pic_option->value == 0)
> > > +		 || !pic_option)
> > > +	  {
> > > +	    if (pie_option)
> > > +	      {
> > > +		bool big = (*decoded_options)[j].opt_index == OPT_fPIC
> > > +			   && pie_option->opt_index == OPT_fPIE;
> > > +	        (*decoded_options)[j].opt_index = big ? OPT_fPIE : OPT_fpie;
> > > +		if (pie_option->value)
> > > +	          (*decoded_options)[j].canonical_option[0] = big ? "-fPIE" : "-fpie";
> > > +		else
> > > +	          (*decoded_options)[j].canonical_option[0] = big ? "-fno-pie" : "-fno-pie";
> > > +		(*decoded_options)[j].value = pie_option->value;
> > > +	        j++;
> > > +	      }
> > > +	    else if (pic_option)
> > > +	      {
> > > +	        (*decoded_options)[j] = *pic_option;
> > > +	        j++;
> > > +	      }
> > > +	    /* We do not know if target defaults to pic or not, so just remove
> > > +	       option if it is missing in one unit but enabled in other.  */
> > > +	    else
> > > +	      remove_option (decoded_options, j, decoded_options_count);
> > > +	  }
> > > +	else if (pic_option->opt_index == OPT_fpic
> > > +		 && (*decoded_options)[j].opt_index == OPT_fPIC)
> > >  	  {
> > >  	    (*decoded_options)[j] = *pic_option;
> > >  	    j++;
> > > @@ -430,11 +462,42 @@ merge_and_complain (struct cl_decoded_op
> > >     else if ((*decoded_options)[j].opt_index == OPT_fPIE
> > >              || (*decoded_options)[j].opt_index == OPT_fpie)
> > >        {
> > > -	if (!pie_option
> > > -	    || pie_option->value != (*decoded_options)[j].value)
> > > -	  remove_option (decoded_options, j, decoded_options_count);
> > > -	else if (pie_option->opt_index == OPT_fPIE
> > > -		 && (*decoded_options)[j].opt_index == OPT_fpie)
> > > +	/* -fno-pie in one unit implies -fno-pie everywhere.  */
> > > +	if ((*decoded_options)[j].value == 0)
> > > +	  j++;
> > > +	/* If we have no pie option or merge in -fno-pie, we still preserve
> > > +	   PIE/pie if pic/PIC is present.  */
> > > +	else if ((pie_option && pie_option->value == 0)
> > > +		 || !pie_option)
> > > +	  {
> > > +	    /* If -fPIC/-fpic is given, merge it with -fPIE/-fpie.  */
> > > +	    if (pic_option)
> > > +	      {
> > > +		if (pic_option->opt_index == OPT_fpic
> > > +		    && (*decoded_options)[j].opt_index == OPT_fPIE)
> > > +		  {
> > > +	            (*decoded_options)[j].opt_index = OPT_fpie;
> > > +	            (*decoded_options)[j].canonical_option[0]
> > > +			 = pic_option->value ? "-fpie" : "-fno-pie";
> > > +		  }
> > > +		else if (!pic_option->value)
> > > +		  (*decoded_options)[j].canonical_option[0] = "-fno-pie";
> > > +		(*decoded_options)[j].value = pic_option->value;
> > > +		j++;
> > > +	      }
> > > +	    else if (pie_option)
> > > +	      {
> > > +	        (*decoded_options)[j] = *pie_option;
> > > +		j++;
> > > +	      }
> > > +	    /* Because we always append pic/PIE options this code path should
> > > +	       not happen unless the LTO object was built by old lto1 which
> > > +	       did not contain that logic yet.  */
> > > +	    else
> > > +	      remove_option (decoded_options, j, decoded_options_count);
> > > +	  }
> > > +	else if (pie_option->opt_index == OPT_fpie
> > > +		 && (*decoded_options)[j].opt_index == OPT_fPIE)
> > >  	  {
> > >  	    (*decoded_options)[j] = *pie_option;
> > >  	    j++;
> > > 
> > 
> > -- 
> > Richard Biener <rguenther@suse.de>
> > SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)
> 
>

Patch

Index: lto-opts.c
===================================================================
--- lto-opts.c	(revision 263356)
+++ lto-opts.c	(working copy)
@@ -78,6 +78,22 @@  lto_write_options (void)
       && !global_options.x_flag_openacc)
     append_to_collect_gcc_options (&temporary_obstack, &first_p,
 				   "-fno-openacc");
+  /* Append PIC/PIE mode because its default depends on target and it is
+     subject of merging in lto-wrapper.  */
+  if ((!global_options_set.x_flag_pic || global_options.x_flag_pic == 0)
+      && !global_options_set.x_flag_pie)
+    {
+       append_to_collect_gcc_options (&temporary_obstack, &first_p,
+				      global_options.x_flag_pic == 2
+				      ? "-fPIC"
+				      : global_options.x_flag_pic == 1
+				      ? "-fpic"
+				      : global_options.x_flag_pie == 2
+				      ? "-fPIE"
+				      : global_options.x_flag_pie == 1
+				      ? "-fpie"
+				      : "-fno-pie");
+    }
 
   /* Append options from target hook and store them to offload_lto section.  */
   if (lto_stream_offload_p)
Index: lto-wrapper.c
===================================================================
--- lto-wrapper.c	(revision 263356)
+++ lto-wrapper.c	(working copy)
@@ -408,6 +408,11 @@  merge_and_complain (struct cl_decoded_op
      It is a common mistake to mix few -fPIC compiled objects into otherwise
      non-PIC code.  We do not want to build everything with PIC then.
 
+     Similarly we merge PIE options, however in addition we keep
+      -fPIC + -fPIE = -fPIE
+      -fpic + -fPIE = -fpie
+      -fPIC/-fpic + -fpie = -fpie
+
      It would be good to warn on mismatches, but it is bit hard to do as
      we do not know what nothing translates to.  */
     
@@ -415,11 +420,38 @@  merge_and_complain (struct cl_decoded_op
     if ((*decoded_options)[j].opt_index == OPT_fPIC
         || (*decoded_options)[j].opt_index == OPT_fpic)
       {
-	if (!pic_option
-	    || (pic_option->value > 0) != ((*decoded_options)[j].value > 0))
-	  remove_option (decoded_options, j, decoded_options_count);
-	else if (pic_option->opt_index == OPT_fPIC
-		 && (*decoded_options)[j].opt_index == OPT_fpic)
+	/* -fno-pic in one unit implies -fno-pic everywhere.  */
+	if ((*decoded_options)[j].value == 0)
+	  j++;
+	/* If we have no pic option or merge in -fno-pic, we still may turn
+	   existing pic/PIC mode into pie/PIE if -fpie/-fPIE is present.  */
+	else if ((pic_option && pic_option->value == 0)
+		 || !pic_option)
+	  {
+	    if (pie_option)
+	      {
+		bool big = (*decoded_options)[j].opt_index == OPT_fPIC
+			   && pie_option->opt_index == OPT_fPIE;
+	        (*decoded_options)[j].opt_index = big ? OPT_fPIE : OPT_fpie;
+		if (pie_option->value)
+	          (*decoded_options)[j].canonical_option[0] = big ? "-fPIE" : "-fpie";
+		else
+	          (*decoded_options)[j].canonical_option[0] = big ? "-fno-pie" : "-fno-pie";
+		(*decoded_options)[j].value = pie_option->value;
+	        j++;
+	      }
+	    else if (pic_option)
+	      {
+	        (*decoded_options)[j] = *pic_option;
+	        j++;
+	      }
+	    /* We do not know if target defaults to pic or not, so just remove
+	       option if it is missing in one unit but enabled in other.  */
+	    else
+	      remove_option (decoded_options, j, decoded_options_count);
+	  }
+	else if (pic_option->opt_index == OPT_fpic
+		 && (*decoded_options)[j].opt_index == OPT_fPIC)
 	  {
 	    (*decoded_options)[j] = *pic_option;
 	    j++;
@@ -430,11 +462,42 @@  merge_and_complain (struct cl_decoded_op
    else if ((*decoded_options)[j].opt_index == OPT_fPIE
             || (*decoded_options)[j].opt_index == OPT_fpie)
       {
-	if (!pie_option
-	    || pie_option->value != (*decoded_options)[j].value)
-	  remove_option (decoded_options, j, decoded_options_count);
-	else if (pie_option->opt_index == OPT_fPIE
-		 && (*decoded_options)[j].opt_index == OPT_fpie)
+	/* -fno-pie in one unit implies -fno-pie everywhere.  */
+	if ((*decoded_options)[j].value == 0)
+	  j++;
+	/* If we have no pie option or merge in -fno-pie, we still preserve
+	   PIE/pie if pic/PIC is present.  */
+	else if ((pie_option && pie_option->value == 0)
+		 || !pie_option)
+	  {
+	    /* If -fPIC/-fpic is given, merge it with -fPIE/-fpie.  */
+	    if (pic_option)
+	      {
+		if (pic_option->opt_index == OPT_fpic
+		    && (*decoded_options)[j].opt_index == OPT_fPIE)
+		  {
+	            (*decoded_options)[j].opt_index = OPT_fpie;
+	            (*decoded_options)[j].canonical_option[0]
+			 = pic_option->value ? "-fpie" : "-fno-pie";
+		  }
+		else if (!pic_option->value)
+		  (*decoded_options)[j].canonical_option[0] = "-fno-pie";
+		(*decoded_options)[j].value = pic_option->value;
+		j++;
+	      }
+	    else if (pie_option)
+	      {
+	        (*decoded_options)[j] = *pie_option;
+		j++;
+	      }
+	    /* Because we always append pic/PIE options this code path should
+	       not happen unless the LTO object was built by old lto1 which
+	       did not contain that logic yet.  */
+	    else
+	      remove_option (decoded_options, j, decoded_options_count);
+	  }
+	else if (pie_option->opt_index == OPT_fpie
+		 && (*decoded_options)[j].opt_index == OPT_fPIE)
 	  {
 	    (*decoded_options)[j] = *pie_option;
 	    j++;