mirror of https://github.com/milvus-io/milvus.git
enhance: enable asan for milvus (#35687)
issue: #35626 pr: #35627 Signed-off-by: chyezh <chyezh@outlook.com>pull/35674/head
parent
7269d5eda2
commit
7062e6fcbf
26
Makefile
26
Makefile
|
@ -14,6 +14,7 @@ PWD := $(shell pwd)
|
|||
GOPATH := $(shell $(GO) env GOPATH)
|
||||
SHELL := /bin/bash
|
||||
OBJPREFIX := "github.com/milvus-io/milvus/cmd/milvus"
|
||||
MILVUS_GO_BUILD_TAGS := "dynamic,sonic"
|
||||
|
||||
INSTALL_PATH := $(PWD)/bin
|
||||
LIBRARY_PATH := $(PWD)/lib
|
||||
|
@ -29,6 +30,9 @@ endif
|
|||
use_asan = OFF
|
||||
ifdef USE_ASAN
|
||||
use_asan =${USE_ASAN}
|
||||
CGO_LDFLAGS := $(shell go env CGO_LDFLAGS) -fsanitize=address -fno-omit-frame-pointer
|
||||
CGO_CFLAGS := $(shell go env CGO_CFLAGS) -fsanitize=address -fno-omit-frame-pointer
|
||||
MILVUS_GO_BUILD_TAGS := $(MILVUS_GO_BUILD_TAGS),use_asan
|
||||
endif
|
||||
|
||||
use_dynamic_simd = ON
|
||||
|
@ -81,15 +85,15 @@ milvus: build-cpp print-build-info
|
|||
@echo "Building Milvus ..."
|
||||
@source $(PWD)/scripts/setenv.sh && \
|
||||
mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && \
|
||||
GO111MODULE=on $(GO) build -pgo=$(PGO_PATH)/default.pgo -ldflags="-r $${RPATH} -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
|
||||
-tags dynamic,sonic -o $(INSTALL_PATH)/milvus $(PWD)/cmd/main.go 1>/dev/null
|
||||
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=on $(GO) build -pgo=$(PGO_PATH)/default.pgo -ldflags="-r $${RPATH} -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
|
||||
-tags $(MILVUS_GO_BUILD_TAGS) -o $(INSTALL_PATH)/milvus $(PWD)/cmd/main.go 1>/dev/null
|
||||
|
||||
milvus-gpu: build-cpp-gpu print-gpu-build-info
|
||||
@echo "Building Milvus-gpu ..."
|
||||
@source $(PWD)/scripts/setenv.sh && \
|
||||
mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && \
|
||||
GO111MODULE=on $(GO) build -pgo=$(PGO_PATH)/default.pgo -ldflags="-r $${RPATH} -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS_GPU)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
|
||||
-tags dynamic,sonic -o $(INSTALL_PATH)/milvus $(PWD)/cmd/main.go 1>/dev/null
|
||||
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=on $(GO) build -pgo=$(PGO_PATH)/default.pgo -ldflags="-r $${RPATH} -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS_GPU)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
|
||||
-tags $(MILVUS_GO_BUILD_TAGS) -o $(INSTALL_PATH)/milvus $(PWD)/cmd/main.go 1>/dev/null
|
||||
|
||||
get-build-deps:
|
||||
@(env bash $(PWD)/scripts/install_deps.sh)
|
||||
|
@ -249,7 +253,7 @@ generated-proto: download-milvus-proto build-3rdparty get-proto-deps
|
|||
|
||||
build-cpp: generated-proto
|
||||
@echo "Building Milvus cpp library ..."
|
||||
@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -n ${use_disk_index} -y ${use_dynamic_simd} ${AZURE_OPTION} -x ${index_engine} -o ${use_opendal})
|
||||
@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -a ${use_asan} -n ${use_disk_index} -y ${use_dynamic_simd} ${AZURE_OPTION} -x ${index_engine} -o ${use_opendal})
|
||||
|
||||
build-cpp-gpu: generated-proto
|
||||
@echo "Building Milvus cpp gpu library ... "
|
||||
|
@ -363,20 +367,12 @@ codecov-cpp: build-cpp-with-coverage
|
|||
# Build each component and install binary to $GOPATH/bin.
|
||||
install: milvus
|
||||
@echo "Installing binary to './bin'"
|
||||
@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/milvus $(GOPATH)/bin/milvus
|
||||
@mkdir -p $(LIBRARY_PATH)
|
||||
-cp -r -P $(PWD)/internal/core/output/lib/*.dylib* $(LIBRARY_PATH) 2>/dev/null
|
||||
-cp -r -P $(PWD)/internal/core/output/lib/*.so* $(LIBRARY_PATH) 2>/dev/null
|
||||
-cp -r -P $(PWD)/internal/core/output/lib64/*.so* $(LIBRARY_PATH) 2>/dev/null
|
||||
@(env USE_ASAN=$(USE_ASAN) GOPATH=$(GOPATH) LIBRARY_PATH=$(LIBRARY_PATH) bash $(PWD)/scripts/install_milvus.sh)
|
||||
@echo "Installation successful."
|
||||
|
||||
gpu-install: milvus-gpu
|
||||
@echo "Installing binary to './bin'"
|
||||
@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/milvus $(GOPATH)/bin/milvus
|
||||
@mkdir -p $(LIBRARY_PATH)
|
||||
-cp -r -P $(PWD)/internal/core/output/lib/*.dylib* $(LIBRARY_PATH) 2>/dev/null
|
||||
-cp -r -P $(PWD)/internal/core/output/lib/*.so* $(LIBRARY_PATH) 2>/dev/null
|
||||
-cp -r -P $(PWD)/internal/core/output/lib64/*.so* $(LIBRARY_PATH) 2>/dev/null
|
||||
@(env USE_ASAN=$(USE_ASAN) GOPATH=$(GOPATH) LIBRARY_PATH=$(LIBRARY_PATH) bash $(PWD)/scripts/install_milvus.sh)
|
||||
@echo "Installation successful."
|
||||
|
||||
clean:
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
//go:build use_asan
|
||||
// +build use_asan
|
||||
|
||||
package asan
|
||||
|
||||
// void __lsan_do_leak_check(void);
|
||||
import "C"
|
||||
|
||||
func LsanDoLeakCheck() {
|
||||
C.__lsan_do_leak_check()
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
//go:build !use_asan
|
||||
// +build !use_asan
|
||||
|
||||
package asan
|
||||
|
||||
func LsanDoLeakCheck() {
|
||||
}
|
|
@ -25,12 +25,14 @@ import (
|
|||
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
"github.com/milvus-io/milvus/cmd/asan"
|
||||
"github.com/milvus-io/milvus/cmd/milvus"
|
||||
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
||||
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defer asan.LsanDoLeakCheck()
|
||||
idx := slices.Index(os.Args, "--run-with-subprocess")
|
||||
|
||||
// execute command as a subprocess if the command contains "--run-with-subprocess"
|
||||
|
|
|
@ -129,6 +129,11 @@ if (LINUX OR MSYS)
|
|||
"-Wno-error"
|
||||
"-Wno-all"
|
||||
)
|
||||
if (USE_ASAN STREQUAL "ON")
|
||||
message( STATUS "Building Milvus Core Using AddressSanitizer")
|
||||
add_compile_options(-fno-omit-frame-pointer -fsanitize=address)
|
||||
add_link_options(-fno-omit-frame-pointer -fsanitize=address)
|
||||
endif()
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
append_flags( CMAKE_CXX_FLAGS
|
||||
"-O3"
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Licensed to the LF AI & Data foundation under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set -e
|
||||
|
||||
mkdir -p "$GOPATH/bin" && cp -f "$PWD/bin/milvus" "$GOPATH/bin/milvus"
|
||||
mkdir -p "$LIBRARY_PATH"
|
||||
cp $PWD"/internal/core/output/lib/"*.dylib* "$LIBRARY_PATH" 2>/dev/null || true
|
||||
cp $PWD"/internal/core/output/lib/"*.so* "$LIBRARY_PATH" || true
|
||||
cp $PWD"/internal/core/output/lib64/"*.so* "$LIBRARY_PATH" 2>/dev/null || true
|
||||
|
||||
if [ "$USE_ASAN" == "ON" ]; then
|
||||
for LIB_PATH in $(ldconfig -p | grep -E '(asan|atomic)' | awk '{print $NF}'); do
|
||||
cp "$LIB_PATH" "$LIBRARY_PATH" 2>/dev/null
|
||||
done
|
||||
fi
|
Loading…
Reference in New Issue