build: use linker specified by the LD env variable

Modifed scripts/detect_cc.sh to take additional parameter specifing
the linker to use. Default to LLD on FreeBSD systems.

Change-Id: Idf97e9676a144028c0803d272ae6f0e903b0dd1f
Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-on: https://review.gerrithub.io/c/438801
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Konrad Sztyber 2019-01-02 13:47:47 +01:00 committed by Jim Harris
parent 18461cba7c
commit ea002f5068
8 changed files with 42 additions and 12 deletions

View File

@ -78,7 +78,7 @@ pkgdep:
$(DIRS-y): mk/cc.mk include/spdk/config.h
mk/cc.mk:
$(Q)scripts/detect_cc.sh --cc=$(CC) --cxx=$(CXX) --lto=$(CONFIG_LTO) > $@.tmp; \
$(Q)scripts/detect_cc.sh --cc=$(CC) --cxx=$(CXX) --lto=$(CONFIG_LTO) --ld=$(LD) > $@.tmp; \
cmp -s $@.tmp $@ || mv $@.tmp $@ ; \
rm -f $@.tmp

View File

@ -112,9 +112,16 @@ LDFLAGS += -Wl,-z,relro,-z,now
# This is the default in most environments, but it doesn't hurt to set it explicitly.
LDFLAGS += -Wl,-z,noexecstack
# Specify the linker to use
LDFLAGS += -fuse-ld=$(LD_TYPE)
ifeq ($(OS),FreeBSD)
SYS_LIBS += -L/usr/local/lib
COMMON_CFLAGS += -I/usr/local/include
# Default to lld on FreeBSD
ifeq ($(origin LD),default)
LD = ld.lld
endif
endif
# Attach only if PMDK lib specified with configure

View File

@ -19,12 +19,13 @@ function usage()
err " -h, --help Display this help and exit"
err " --cc=path C compiler to use"
err " --cxx=path C++ compiler to use"
err " --ld=path Linker to use"
err " --lto=[y|n] Attempt to configure for LTO"
}
CC=cc
CXX=c++
LD=ld
LTO=n
for i in "$@"; do
@ -42,6 +43,9 @@ for i in "$@"; do
--lto=*)
LTO="${i#*=}"
;;
--ld=*)
LD="${i#*=}"
;;
--)
break
;;
@ -54,13 +58,27 @@ done
CC_TYPE=$($CC -v 2>&1 | grep -o -E '\w+ version' | head -1 | awk '{ print $1 }')
CXX_TYPE=$($CXX -v 2>&1 | grep -o -E '\w+ version' | head -1 | awk '{ print $1 }')
LD_TYPE=$(ld -v 2>&1 | awk '{print $2}')
if [ "$CC_TYPE" != "$CXX_TYPE" ]; then
err "C compiler is $CC_TYPE but C++ compiler is $CXX_TYPE"
err "This may result in errors"
fi
LD_TYPE=$($LD --version 2>&1 | head -n1 | awk '{print $1, $2}')
case "$LD_TYPE" in
"GNU ld"*)
LD_TYPE=bfd
;;
"GNU gold"*)
LD_TYPE=gold
;;
"LLD"*)
LD_TYPE=lld
;;
*)
err "Unsupported linker: $LD"
exit 1
esac
CCAR="ar"
if [ "$LTO" = "y" ]; then
if [ "$CC_TYPE" = "clang" ]; then
@ -74,7 +92,17 @@ if [ "$LTO" = "y" ]; then
fi
fi
echo "CC?=$CC"
echo "CXX?=$CXX"
function set_default() {
echo "ifeq (\$(origin $1),default)"
echo "$1 = $2"
echo "endif"
echo ""
}
set_default CC $CC
set_default CXX $CXX
set_default LD $LD
echo "CCAR=$CCAR"
echo "CC_TYPE=$CC_TYPE"
echo "LD_TYPE=$LD_TYPE"

View File

@ -33,7 +33,6 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk
TEST_FILE = bdev_ut.c

View File

@ -33,7 +33,6 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk
TEST_FILE = blob_ut.c

View File

@ -33,7 +33,6 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk
SPDK_LIB_LIST = conf trace jsonrpc json
TEST_FILE = app_ut.c

View File

@ -33,7 +33,6 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk
TEST_FILE = reduce_ut.c

View File

@ -33,7 +33,6 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk
TEST_FILE = thread_ut.c