com php-src: basic ASAN suport for clang on Windows: win32/build/config.w32 win32/build/confutils.js
| From: | Anatol Belski | Date: | Mon, 03 Apr 2017 10:02:51 +0000 |
| Subject: | com php-src: basic ASAN suport for clang on Windows: win32/build/config.w32 win32/build/confutils.js | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-97468@lists.php.net to get a copy of this message | ||
Commit: 731cb8a827b8f96b45037c1e92943b3206ad8557
Author: Anatol Belski <ab@php.net> Mon, 3 Apr 2017 11:46:51 +0200
Parents: 6d1fc6cd6f96ca44ceb7c8e85bfd8e3b8de6abc6
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=731cb8a827b8f96b45037c1e92943b3206ad8557
Log:
basic ASAN suport for clang on Windows
fix makefile generation for non clang
rename option
Changed paths:
M win32/build/config.w32
M win32/build/confutils.js
Diff:
diff --git a/win32/build/config.w32 b/win32/build/config.w32
index ae080a9..43b0362 100644
--- a/win32/build/config.w32
+++ b/win32/build/config.w32
@@ -311,6 +311,14 @@ if (CLANG_TOOLSET) {
-Wno-logical-op-parentheses -Wno-msvc-include -Wno-invalid-source-encoding -Wno-unknown-pragmas \
-Wno-unused-command-line-argument");
}
+
+ ARG_ENABLE("sanitizer", "Enable address sanitizer extension", "no");
+ if (PHP_SANITIZER == "yes") {
+ if (COMPILER_NUMERIC_VERSION < 500) {
+ ERROR("Clang at least 5.0.0 required for sanitation plugins");
+ }
+ add_asan_opts("CFLAGS", "LIBS", "LDFLAGS");
+ }
}
ARG_WITH("codegen-arch", "Architecture for code generation: ia32, sse, sse2, avx,
avx2", "no");
diff --git a/win32/build/confutils.js b/win32/build/confutils.js
index 4db2a7c..2c603b3 100644
--- a/win32/build/confutils.js
+++ b/win32/build/confutils.js
@@ -1191,10 +1191,11 @@ function SAPI(sapiname, file_list, makefiletarget, cflags, obj_dir)
MFO.WriteLine("$(BUILD_DIR)\\" + makefiletarget + ": $(DEPS_" + SAPI +
") $(" + SAPI + "_GLOBAL_OBJS) $(BUILD_DIR)\\$(PHPLIB) $(BUILD_DIR)\\" + resname
+ " $(BUILD_DIR)\\" + manifest_name);
}
+ var is_lib = makefiletarget.match(new RegExp("\\.lib$"));
if (makefiletarget.match(new RegExp("\\.dll$"))) {
ldflags = "/dll $(LDFLAGS)";
manifest = "-@$(_VC_MANIFEST_EMBED_DLL)";
- } else if (makefiletarget.match(new RegExp("\\.lib$"))) {
+ } else if (is_lib) {
ldflags = "$(ARFLAGS)";
ld = "@$(MAKE_LIB)";
} else {
@@ -1202,6 +1203,12 @@ function SAPI(sapiname, file_list, makefiletarget, cflags, obj_dir)
manifest = "-@$(_VC_MANIFEST_EMBED_EXE)";
}
+ if (PHP_SANITIZER == "yes") {
+ if (CLANG_TOOLSET) {
+ add_asan_opts("CFLAGS_" + SAPI, "LIBS_" + SAPI, (is_lib ?
"ARFLAGS_" : "LDFLAGS_") + SAPI);
+ }
+ }
+
if(is_pgo_desired(sapiname) && (PHP_PGI == "yes" || PHP_PGO != "no"))
{
// Add compiler and link flags if PGO options are selected
if (PHP_DEBUG != "yes" && PHP_PGI == "yes") {
@@ -2470,6 +2477,11 @@ function generate_makefile()
}
}
}
+ if (PHP_SANITIZER == "yes") {
+ if (CLANG_TOOLSET) {
+ extra_path = extra_path + ";" + get_clang_lib_dir() + "\\windows";
+ }
+ }
MF.WriteLine("set-tmp-env:");
MF.WriteLine(" @set PATH=" + extra_path + ";$(PATH)");
@@ -3365,3 +3377,51 @@ function check_binary_tools_sdk()
}
}
+function get_clang_lib_dir()
+{
+ var ret = null;
+ var ver = null;
+
+ if (COMPILER_NAME.match(/clang version ([\d\.]+) \((.*)\)/)) {
+ ver = RegExp.$1;
+ } else {
+ ERROR("Faled to determine clang lib path");
+ }
+
+ /* FIXME existence check, etc. */
+ if (X64) {
+ ret = PROGRAM_FILES + "\\LLVM\\lib\\clang\\" + ver + "\\lib";
+ } else {
+ ret = PROGRAM_FILESx86 + "\\LLVM\\lib\\clang\\" + ver + "\\lib";
+ }
+
+ return ret;
+}
+
+function add_asan_opts(cflags_name, libs_name, ldflags_name)
+{
+
+ var ver = null;
+
+ if (COMPILER_NAME.match(/clang version ([\d\.]+) \((.*)\)/)) {
+ ver = RegExp.$1;
+ } else {
+ ERROR("Faled to determine clang lib path");
+ }
+
+ if (!!cflags_name) {
+ ADD_FLAG(cflags_name, "-fsanitize=address");
+ }
+ if (!!libs_name) {
+ if (X64) {
+ ADD_FLAG(libs_name, "clang_rt.asan_dynamic-x86_64.lib
clang_rt..asan_dynamic_runtime_thunk-x86_64.lib");
+ } else {
+ ADD_FLAG(libs_name, "clang_rt.asan_dynamic-i386.lib
clang_rt.asan_dynamic_runtime_thunk-i386.lib");
+ }
+ }
+
+ if (!!ldflags_name) {
+ ADD_FLAG(ldflags_name, "/libpath:\"" + get_clang_lib_dir() +
"\\windows\"");
+ }
+}
+