Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

cmake ENABLE_PIC forced off on Darwin/Xcode #16737

Open Quuxplusone opened 11 years ago

Quuxplusone commented 11 years ago
Bugzilla Link PR16738
Status NEW
Importance P enhancement
Reported by Rick Foos (Rfoos@SolengTech.com)
Reported on 2013-07-29 14:59:53 -0700
Last modified on 2016-03-21 15:27:53 -0700
Version trunk
Hardware Macintosh MacOS X
CC fang@csl.cornell.edu, llvm-bugs@lists.llvm.org, rafael@espindo.la, RandomDSdevel@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by PR14903
See also
+++ This bug was initially created as a clone of Bug #14903 +++
Cmake for Xcode disables PIC.
    # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
    # know how to disable this, so just force ENABLE_PIC off for now.

--- autoconf ENABLE_PIC logic for DARWIN
Makefile.rules
ifeq ($(ENABLE_PIC),1)
  ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
    # Nothing. Win32 defaults to PIC and warns when given -fPIC
  else
    ifeq ($(HOST_OS),Darwin)
      # Common symbols not allowed in dylib files
      CXX.Flags += -fno-common
      C.Flags   += -fno-common
    else
      # Linux and others; pass -fPIC
      CXX.Flags += -fPIC
      C.Flags   += -fPIC
    endif
  endif
else
  ifeq ($(HOST_OS),Darwin)
      CXX.Flags += -mdynamic-no-pic
      C.Flags   += -mdynamic-no-pic
  endif
endif

--- cmake ENABLE_PIC logic for darwin/xcode.
cmake/modules/HandleLLVMOptions.cmake

if( ENABLE_PIC )
  if( XCODE )
    # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
    # know how to disable this, so just force ENABLE_PIC off for now.
    message(WARNING "-fPIC not supported with Xcode.")
  elseif( WIN32 OR CYGWIN)
    # On Windows all code is PIC. MinGW warns if -fPIC is used.
  else()
    add_flag_or_print_warning("-fPIC")

    if( WIN32 OR CYGWIN)
      # MinGW warns if -fvisibility-inlines-hidden is used.
    else()
      check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
      append_if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS)
    endif()
  endif()
endif()
Quuxplusone commented 11 years ago

I build with cmake ENABLE_SHARED on darwin8 all the time, with the additional -fno-common flag, using apple-gcc-4.0.1 as the stage 1 compiler.

(How are ENABLE_PIC and ENABLE_SHARED related?)

Anyways, "-fPIC not supported with Xcode" seems like nonsense to me.

I also don't think this bug depends on 14903, if anything, the other way around.

Quuxplusone commented 9 years ago

Just wanted to note that this bug still exists as of today.

Quuxplusone commented 9 years ago

Um…will it ever be fixed?

Quuxplusone commented 8 years ago

@Rick Foos, @David Fang:

Huh: strangely, Apple's Xcode Build Setting Reference (https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html states under its section for GCC_DYNAMIC_NO_PIC (perhaps the 'GCC_*' prefix is left over from when Xcode used that compiler under the hood…?) that this setting, which the documentation (https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW113) says is equivalent to passing -m dynamic-no-pic to the compiler, is set to /NO/ by default! Perhaps the documentation is incorrect and somebody should contact Apple for clarification about this since the company doesn't seem to have updated the reference document of which I speak since, according to its 'Revision History' section (https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/9-Revision-4.0/history.html#//apple_ref/doc/uid/TP40003931-CH4-SW1,) it hasn't been updated since October 5th, 2010? I'd ask if this might be an error with any LLVM-related Xcode projects' configurations or the order in which they're initialized, but said projects aren't generated from CMakeLists.txt until you run cmake -G "Xcode" "/path/to/llvm".