MantisBT - CMake
View Issue Details
0015570CMake(No Category)public2015-05-14 14:222016-06-10 14:31
Stephen Kelly 
Kitware Robot 
normalminorhave not tried
closedmoved 
 
 
0015570: Review POSITION_INDEPENDENT_CODE use of -fPIE

cmLocalGenerator::AddPositionIndependentFlags uses -fPIE for executables and -fPIC for libraries. This caused issues in Qt:

 https://bugreports.qt.io/browse/QTBUG-45755 [^]
 
 https://codereview.qt-project.org/#/c/112060/ [^]
 
 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65886 [^]

Someone who understands the terms-of-art used in the discussion should review what cmake is doing here.
No tags attached.
Issue History
2015-05-14 14:22Stephen KellyNew Issue
2015-05-25 10:38Stephen KellyNote Added: 0038797
2015-05-25 12:49Stephen KellyNote Edited: 0038797bug_revision_view_page.php?bugnote_id=38797#r1788
2016-06-10 14:29Kitware RobotNote Added: 0042778
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0038797)
Stephen Kelly   
2015-05-25 10:38   
(edited on: 2015-05-25 12:49)
There is an option for building GCC in the works in the hjl/pie/master branch which makes GCC use -fPIE by default for executables:
 
 https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=64364101d6c888e20eb1146ee2baac4b08e684cf [^]


  Add --enable-default-pie option to GCC configure

  Add --enable-default-pie option to configure GCC to generate PIE by
  default.

  gcc/

  2015-05-19 Magnus Granberg <zorry@gentoo.org>
      H.J. Lu <hongjiu.lu@intel.com>

  * Makefile.in (COMPILER): Add @NO_PIE_CFLAGS@.
  (BUILD_CFLAGS): Likewise.
  (BUILD_CXXFLAGS): Likewise.
  (LINKER): Add @NO_PIE_FLAG@.
  (BUILD_LDFLAGS): Likewise.
  (libgcc.mvars): Set NO_PIE_CFLAGS to -fno-PIE for
  --enable-default-pie.
  * common.opt (fPIE): Initialize to -1.
  (fpie): Likewise.
  (no-pie): New option.
  (pie): Replace "Negative(shared)" with "Negative(no-pie)".
  * configure.ac: Add --enable-default-pie.
  (NO_PIE_CFLAGS): New. Check if -fno-PIE works. AC_SUBST.
  (NO_PIE_FLAG): New. Check if -no-pie works. AC_SUBST.
  * defaults.h (DEFAULT_FLAG_PIE): New. Default PIE to -fPIE.
  * gcc.c (NO_PIE_SPEC): New.
  (PIE_SPEC): Likewise.
  (NO_FPIE1_SPEC): Likewise.
  (FPIE1_SPEC): Likewise.
  (NO_FPIE2_SPEC): Likewise.
  (FPIE2_SPEC): Likewise.
  (NO_FPIE2_SPEC): Likewise.
  (FPIE_SPEC): Likewise.
  (NO_FPIE_SPEC): Likewise.
  (NO_FPIC1_SPEC): Likewise.
  (FPIC1_SPEC): Likewise.
  (NO_FPIC2_SPEC): Likewise.
  (FPIC2_SPEC): Likewise.
  (NO_FPIC2_SPEC): Likewise.
  (FPIC_SPEC): Likewise.
  (NO_FPIC_SPEC): Likewise.
  (NO_FPIE1_AND_FPIC1_SPEC): Likewise.
  (FPIE1_OR_FPIC1_SPEC): Likewise.
  (NO_FPIE2_AND_FPIC2_SPEC): Likewise.
  (FPIE2_OR_FPIC2_SPEC): Likewise.
  (NO_FPIE_AND_FPIC_SPEC): Likewise.
  (FPIE_OR_FPIC_SPEC): Likewise.
  (LD_PIE_SPEC): Likewise.
  (LINK_PIE_SPEC): Handle -no-pie. Use PIE_SPEC and LD_PIE_SPEC.
  * opts.c (finish_options): Update opts->x_flag_pie if it is -1.
  * config/darwin.h (PIE_SPEC): Renamed to ...
  (DARWIN_PIE_SPEC): This.
  (LINK_SPEC): Replace PIE_SPEC with DARWIN_PIE_SPEC.
  * config/darwin9.h (PIE_SPEC): Renamed to ...
  (DARWIN_PIE_SPEC): This.
  * config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Use
  PIE_SPEC and NO_PIE_SPEC if HAVE_LD_PIE is defined.
  * config/openbsd.h (ASM_SPEC): Use FPIE1_OR_FPIC1_SPEC and
  FPIE2_OR_FPIC2_SPEC.
  * config/m68k/netbsd-elf.h (ASM_SPEC): Likewise.
  * config/m68k/openbsd.h (ASM_SPEC): Likewise.
  * gcc/config/sol2.h (ASM_PIC_SPEC): Likewise.
  * config/arm/freebsd.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
  * config/arm/netbsd-elf.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
  * config/arm/semi.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
  * config/cris/linux.h (CRIS_ASM_SUBTARGET_SPEC): Likewise.
  * config/m32r/m32r.h (ASM_SPEC): Likewise.
  * config/m68k/uclinux.h (DRIVER_SELF_SPECS): Likewise.
  * config/rs6000/linux64.h (ASM_SPEC32): Likewise.
  * config/rs6000/sysv4.h (ASM_SPEC): Likewise.
  * config/sparc/freebsd.h (ASM_SPEC): Likewise.
  * config/sparc/linux.h (ASM_SPEC): Likewise.
  * config/sparc/linux64.h (ASM_SPEC): Likewise.
  * config/sparc/netbsd-elf.h (ASM_SPEC): Likewise.
  * config/sparc/openbsd64.h (ASM_SPEC): Likewise.
  * config/sparc/sp-elf.h (ASM_SPEC): Likewise.
  * config/sparc/sp64-elf.h (ASM_SPEC): Likewise.
  * config/sparc/sparc.h (ASM_SPEC): Likewise.
  * config/sparc/sysv4.h (ASM_SPEC): Likewise.
  * config/sparc/vxworks.h (ASM_SPEC): Likewise.
  * config/c6x/elf-common.h (ASM_SPEC): Use NO_FPIC2_SPEC,
  FPIC2_SPEC, FPIC1_SPEC and FPIC2_SPEC.
  * config/c6x/uclinux-elf.h (LINK_SPEC): Use FPIE_SPEC.
  * config/frv/frv.h (DRIVER_SELF_SPECS): Use FPIC_SPEC,
  NO_FPIC_SPEC and NO_FPIE1_AND_FPIC1_SPEC.
  (ASM_SPEC): Use FPIE1_OR_FPIC1_SPEC and FPIE2_OR_FPIC2_SPEC.
  * config/m68k/m68k.h (ASM_PCREL_SPEC): Use FPIC_SPEC and
  NO_FPIC_SPEC.
  * config/mips/gnu-user.h (NO_SHARED_SPECS): Use
  NO_FPIE_AND_FPIC_SPEC.
  * config/mips/vxworks.h (SUBTARGET_ASM_SPEC): Use FPIC_SPEC.
  * config/rs6000/freebsd64.h (ASM_SPEC32): Likewise.
  * config/rs6000/vxworks.h (ASM_SPEC): Likewise.
  * config/vax/linux.h (ASM_SPEC): Likewise.
  * doc/install.texi: Document --enable-default-pie.
  * doc/invoke.texi: Document -no-pie.
  * config.in: Regenerated.
  * configure: Likewise.

  gcc/ada/

  2015-05-19 H.J. Lu <hongjiu.lu@intel.com>

  * gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@.

  libgcc/

  2015-05-19 H.J. Lu <hongjiu.lu@intel.com>

  * Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS).



Given that, and given the response in the above linked bug report, there seems to be disagreement between Qt and GCC on whether Qt is doing the right thing.

I don't think CMake should change POSITION_INDEPENDENT_CODE behavior with executables to use -fPIC instead of -fPIE.

The Qt patch at

 https://codereview.qt-project.org/#/c/113025/ [^]

would make Qt not use the CMake POSITION_INDEPENDENT_CODE feature, as it appears to be currently at odds with what Qt wants.

(0042778)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.