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:
parent
18461cba7c
commit
ea002f5068
2
Makefile
2
Makefile
@ -78,7 +78,7 @@ pkgdep:
|
|||||||
$(DIRS-y): mk/cc.mk include/spdk/config.h
|
$(DIRS-y): mk/cc.mk include/spdk/config.h
|
||||||
|
|
||||||
mk/cc.mk:
|
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 $@ ; \
|
cmp -s $@.tmp $@ || mv $@.tmp $@ ; \
|
||||||
rm -f $@.tmp
|
rm -f $@.tmp
|
||||||
|
|
||||||
|
@ -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.
|
# This is the default in most environments, but it doesn't hurt to set it explicitly.
|
||||||
LDFLAGS += -Wl,-z,noexecstack
|
LDFLAGS += -Wl,-z,noexecstack
|
||||||
|
|
||||||
|
# Specify the linker to use
|
||||||
|
LDFLAGS += -fuse-ld=$(LD_TYPE)
|
||||||
|
|
||||||
ifeq ($(OS),FreeBSD)
|
ifeq ($(OS),FreeBSD)
|
||||||
SYS_LIBS += -L/usr/local/lib
|
SYS_LIBS += -L/usr/local/lib
|
||||||
COMMON_CFLAGS += -I/usr/local/include
|
COMMON_CFLAGS += -I/usr/local/include
|
||||||
|
# Default to lld on FreeBSD
|
||||||
|
ifeq ($(origin LD),default)
|
||||||
|
LD = ld.lld
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Attach only if PMDK lib specified with configure
|
# Attach only if PMDK lib specified with configure
|
||||||
|
@ -19,12 +19,13 @@ function usage()
|
|||||||
err " -h, --help Display this help and exit"
|
err " -h, --help Display this help and exit"
|
||||||
err " --cc=path C compiler to use"
|
err " --cc=path C compiler to use"
|
||||||
err " --cxx=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"
|
err " --lto=[y|n] Attempt to configure for LTO"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CC=cc
|
CC=cc
|
||||||
CXX=c++
|
CXX=c++
|
||||||
|
LD=ld
|
||||||
LTO=n
|
LTO=n
|
||||||
|
|
||||||
for i in "$@"; do
|
for i in "$@"; do
|
||||||
@ -42,6 +43,9 @@ for i in "$@"; do
|
|||||||
--lto=*)
|
--lto=*)
|
||||||
LTO="${i#*=}"
|
LTO="${i#*=}"
|
||||||
;;
|
;;
|
||||||
|
--ld=*)
|
||||||
|
LD="${i#*=}"
|
||||||
|
;;
|
||||||
--)
|
--)
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
@ -54,13 +58,27 @@ done
|
|||||||
|
|
||||||
CC_TYPE=$($CC -v 2>&1 | grep -o -E '\w+ version' | head -1 | awk '{ print $1 }')
|
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 }')
|
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
|
if [ "$CC_TYPE" != "$CXX_TYPE" ]; then
|
||||||
err "C compiler is $CC_TYPE but C++ compiler is $CXX_TYPE"
|
err "C compiler is $CC_TYPE but C++ compiler is $CXX_TYPE"
|
||||||
err "This may result in errors"
|
err "This may result in errors"
|
||||||
fi
|
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"
|
CCAR="ar"
|
||||||
if [ "$LTO" = "y" ]; then
|
if [ "$LTO" = "y" ]; then
|
||||||
if [ "$CC_TYPE" = "clang" ]; then
|
if [ "$CC_TYPE" = "clang" ]; then
|
||||||
@ -68,13 +86,23 @@ if [ "$LTO" = "y" ]; then
|
|||||||
err "Using LTO with clang requires the gold linker."
|
err "Using LTO with clang requires the gold linker."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
CCAR="llvm-ar"
|
CCAR="llvm-ar"
|
||||||
else
|
else
|
||||||
CCAR="gcc-ar"
|
CCAR="gcc-ar"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "CC?=$CC"
|
function set_default() {
|
||||||
echo "CXX?=$CXX"
|
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 "CCAR=$CCAR"
|
||||||
echo "CC_TYPE=$CC_TYPE"
|
echo "CC_TYPE=$CC_TYPE"
|
||||||
|
echo "LD_TYPE=$LD_TYPE"
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../../..)
|
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../../..)
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk
|
|
||||||
|
|
||||||
TEST_FILE = bdev_ut.c
|
TEST_FILE = bdev_ut.c
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk
|
|
||||||
|
|
||||||
TEST_FILE = blob_ut.c
|
TEST_FILE = blob_ut.c
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk
|
|
||||||
|
|
||||||
SPDK_LIB_LIST = conf trace jsonrpc json
|
SPDK_LIB_LIST = conf trace jsonrpc json
|
||||||
TEST_FILE = app_ut.c
|
TEST_FILE = app_ut.c
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk
|
|
||||||
|
|
||||||
TEST_FILE = reduce_ut.c
|
TEST_FILE = reduce_ut.c
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk
|
|
||||||
|
|
||||||
TEST_FILE = thread_ut.c
|
TEST_FILE = thread_ut.c
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user