From fd4eca73e75282cf89b6de7f6f3bb4cf2b0acbc6 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Mon, 25 Nov 2013 21:21:01 -0800 Subject: [PATCH] fPIC in x64 environment Summary: Check https://github.com/facebook/rocksdb/pull/15 for context. Apparently [1], we need -fPIC in x64 environments (this is added only in non-fbcode). In fbcode, I removed -fPIC per @dhruba's suggestion, since it introduces perf regression. I'm not sure what would are the implications of doing that, but looks like it works, and when releasing to the third-party, we're disabling -fPIC either way [2]. Would love a suggestion from someone who knows more about this [1] http://eli.thegreenplace.net/2011/11/11/position-independent-code-pic-in-shared-libraries-on-x64/ [2] https://our.intern.facebook.com/intern/wiki/index.php/Database/RocksDB/Third_Party Test Plan: make check works Reviewers: dhruba, emayanke, kailiu Reviewed By: dhruba CC: leveldb, dhruba, reconnect.grayhat Differential Revision: https://reviews.facebook.net/D14337 --- build_tools/build_detect_platform | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index c3fb8e3f1..59e2e4619 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -75,7 +75,7 @@ if test -z "$TARGET_OS"; then TARGET_OS=`uname -s` fi -COMMON_FLAGS="$COMMON_FLAGS ${CFLAGS} -fPIC" +COMMON_FLAGS="$COMMON_FLAGS ${CFLAGS}" CROSS_COMPILE= PLATFORM_CCFLAGS= PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS ${CXXFLAGS}" @@ -174,6 +174,12 @@ if [ "$CROSS_COMPILE" = "true" -o "$FBCODE_BUILD" = "true" ]; then # Also don't need any compilation tests if compiling on fbcode true else + # do fPIC on 64 bit in non-fbcode environment + case "$TARGET_OS" in + x86_64) + PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS -fPIC" + esac + # If -std=c++0x works, use . Otherwise use port_posix.h. $CXX $CFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null <