Skip to content

Commit

Permalink
Use LTO when it is called for
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkeane committed Aug 3, 2021
1 parent e278e8a commit acd1c0d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
12 changes: 11 additions & 1 deletion r/configure
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,17 @@ if [ $? -eq 0 ] || [ "$UNAME" = "Darwin" ]; then
fi
fi
# prepend PKG_DIRS and append BUNDLED_LIBS to PKG_LIBS
PKG_LIBS="$PKG_DIRS $PKG_LIBS $BUNDLED_LIBS -fno-lto"
PKG_LIBS="$PKG_DIRS $PKG_LIBS $BUNDLED_LIBS"

# If R has not been built with LTO, then we need to add -fno-lto
echo "******** checking if LTO needs to be disabled"
R_CONFIG_LTO=`"${R_HOME}"/bin/R CMD config LTO`
echo "******** The R CMD config LTO value is $R_CONFIG_LTO"
if [ "$R_CONFIG_LTO" = "" ]; then
echo "******** disabling LTO"
PKG_LIBS="$PKG_LIBS -fno-lto"
fi

echo "PKG_CFLAGS=$PKG_CFLAGS"
echo "PKG_LIBS=$PKG_LIBS"
else
Expand Down
5 changes: 5 additions & 0 deletions r/inst/build_arrow_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ else
ARROW_DEFAULT_PARAM="OFF"
fi

if echo "$ARROW_R_CXXFLAGS" | grep -q "flto"; then
ARROW_LTO="ON"
fi

mkdir -p "${BUILD_DIR}"
pushd "${BUILD_DIR}"
${CMAKE} -DARROW_BOOST_USE_SHARED=OFF \
Expand Down Expand Up @@ -75,6 +79,7 @@ ${CMAKE} -DARROW_BOOST_USE_SHARED=OFF \
-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON \
-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON \
-DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD:-ON} \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${ARROW_LTO:-ON} \
${EXTRA_CMAKE_FLAGS} \
-G ${CMAKE_GENERATOR:-"Unix Makefiles"} \
${SOURCE_DIR}
Expand Down
11 changes: 10 additions & 1 deletion r/tools/nixlibs.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,15 @@ build_libarrow <- function(src_dir, dst_dir) {
# tools::Rcmd introduced R 3.3
tools::Rcmd(paste("config", var), stdout = TRUE)
}

arrow_r_cxxflags <- Sys.getenv("ARROW_R_CXXFLAGS", "")

cat("************ Checking if LTO should be disabled, the LTO value is: ", R_CMD_config("LTO"))
if (R_CMD_config("LTO") == "") {
cat("************ Disabling LTO")
arrow_r_cxxflags <- paste(arrow_r_cxxflags, "-fno-lto")
}

env_var_list <- c(
SOURCE_DIR = src_dir,
BUILD_DIR = build_dir,
Expand All @@ -326,7 +335,7 @@ build_libarrow <- function(src_dir, dst_dir) {
CC = R_CMD_config("CC"),
CXX = paste(R_CMD_config("CXX11"), R_CMD_config("CXX11STD")),
# CXXFLAGS = R_CMD_config("CXX11FLAGS"), # We don't want the same debug symbols
ARROW_R_CXXFLAGS = paste(Sys.getenv("ARROW_R_CXXFLAGS", ""), "-fno-lto"),
ARROW_R_CXXFLAGS = arrow_r_cxxflags,
LDFLAGS = R_CMD_config("LDFLAGS")
)
env_vars <- paste0(names(env_var_list), '="', env_var_list, '"', collapse = " ")
Expand Down

0 comments on commit acd1c0d

Please sign in to comment.