Commit ea002f50 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Jim Harris
Browse files

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: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-on: https://review.gerrithub.io/c/438801


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 18461cba
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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

+7 −0
Original line number Diff line number Diff line
@@ -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
+34 −6
Original line number Diff line number Diff line
@@ -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"
+0 −1
Original line number Diff line number Diff line
@@ -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

+0 −1
Original line number Diff line number Diff line
@@ -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

Loading