diff --git a/programming/build/llvm/actions.py b/programming/build/llvm/actions.py index 15f1391f51..f55f71a40a 100644 --- a/programming/build/llvm/actions.py +++ b/programming/build/llvm/actions.py @@ -34,6 +34,8 @@ def setup(): shelltools.export("CC", "gcc") shelltools.export("CXX", "g++") + shelltools.system("patch -Np0 -d projects/compiler-rt < msan-prevent-initialization-failure-with-newer-glibc.patch") + shelltools.system("patch -Rp1 -i AMDGPU-Fix-an-interaction-between-WQM-and-polygon-stippling.patch") if get.buildTYPE() == "emul32": shelltools.export("CC", "gcc -m32") @@ -63,14 +65,17 @@ def setup(): cmaketools.configure("-DCMAKE_BUILD_TYPE=Release \ %s \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DLLVM_ENABLE_FFI=ON \ - -DCMAKE_BUILD_TYPE=Release \ - -DLLVM_BUILD_LLVM_DYLIB=ON \ - -DLLDB_DISABLE_LIBEDIT=1 \ - -DLLVM_INCLUDEDIR=/usr/include \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DLLVM_BUILD_LLVM_DYLIB=ON \ + -DLLVM_LINK_LLVM_DYLIB=ON \ + -DLLVM_INSTALL_UTILS=ON \ + -DLLVM_ENABLE_RTTI=ON \ + -DLLVM_ENABLE_FFI=ON \ + -DLLDB_DISABLE_LIBEDIT=1 \ + -DLLVM_INCLUDEDIR=/usr/include \ -DFFI_INCLUDE_DIR=/usr/lib/libffi-3.2.1/include \ - -DLLVM_TARGETS_TO_BUILD='host;AMDGPU'" % options, sourceDir=".." ) + -DLLVM_BINUTILS_INCDIR=/usr/include" % options, sourceDir=".." ) def build(): shelltools.makedirs("build") diff --git a/programming/build/llvm/files/AMDGPU-Fix-an-interaction-between-WQM-and-polygon-stippling.patch b/programming/build/llvm/files/AMDGPU-Fix-an-interaction-between-WQM-and-polygon-stippling.patch new file mode 100644 index 0000000000..f23b916828 --- /dev/null +++ b/programming/build/llvm/files/AMDGPU-Fix-an-interaction-between-WQM-and-polygon-stippling.patch @@ -0,0 +1,140 @@ +From 25e2616626caafb896517e18cd8aa724fba2b200 Mon Sep 17 00:00:00 2001 +From: Tom Stellard +Date: Tue, 29 Nov 2016 03:41:28 +0000 +Subject: [PATCH] Merging r280589: + +------------------------------------------------------------------------ +r280589 | nhaehnle | 2016-09-03 05:26:32 -0700 (Sat, 03 Sep 2016) | 19 lines + +AMDGPU: Fix an interaction between WQM and polygon stippling + +Summary: +This fixes a rare bug in polygon stippling with non-monolithic pixel shaders. + +The underlying problem is as follows: the prolog part contains the polygon +stippling sequence, i.e. a kill. The main part then enables WQM based on the +_reduced_ exec mask, effectively undoing most of the polygon stippling. + +Since we cannot know whether polygon stippling will be used, the main part +of a non-monolithic shader must always return to exact mode to fix this +problem. + +Reviewers: arsenm, tstellarAMD, mareko + +Subscribers: arsenm, llvm-commits, kzhuravl + +Differential Revision: https://reviews.llvm.org/D23131 + +------------------------------------------------------------------------ + +git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@288105 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + lib/Target/AMDGPU/SIInstructions.td | 1 + + lib/Target/AMDGPU/SIWholeQuadMode.cpp | 7 ----- + test/CodeGen/AMDGPU/wqm.ll | 49 ++++++++++++++++++++++++++++++++--- + 3 files changed, 46 insertions(+), 11 deletions(-) + +diff --git a/lib/Target/AMDGPU/SIInstructions.td b/lib/Target/AMDGPU/SIInstructions.td +index 18b7d5d..dde5f2f 100644 +--- a/lib/Target/AMDGPU/SIInstructions.td ++++ b/lib/Target/AMDGPU/SIInstructions.td +@@ -2029,6 +2029,7 @@ def SI_RETURN : PseudoInstSI < + let hasSideEffects = 1; + let SALU = 1; + let hasNoSchedulingInfo = 1; ++ let DisableWQM = 1; + } + + let Uses = [EXEC], Defs = [EXEC, VCC, M0], +diff --git a/lib/Target/AMDGPU/SIWholeQuadMode.cpp b/lib/Target/AMDGPU/SIWholeQuadMode.cpp +index b200c15..1534d58 100644 +--- a/lib/Target/AMDGPU/SIWholeQuadMode.cpp ++++ b/lib/Target/AMDGPU/SIWholeQuadMode.cpp +@@ -219,13 +219,6 @@ char SIWholeQuadMode::scanInstructions(MachineFunction &MF, + markInstruction(MI, Flags, Worklist); + GlobalFlags |= Flags; + } +- +- if (WQMOutputs && MBB.succ_empty()) { +- // This is a prolog shader. Make sure we go back to exact mode at the end. +- Blocks[&MBB].OutNeeds = StateExact; +- Worklist.push_back(&MBB); +- GlobalFlags |= StateExact; +- } + } + + return GlobalFlags; +diff --git a/test/CodeGen/AMDGPU/wqm.ll b/test/CodeGen/AMDGPU/wqm.ll +index 809a7ba..41e4264 100644 +--- a/test/CodeGen/AMDGPU/wqm.ll ++++ b/test/CodeGen/AMDGPU/wqm.ll +@@ -17,17 +17,18 @@ main_body: + ;CHECK-LABEL: {{^}}test2: + ;CHECK-NEXT: ; %main_body + ;CHECK-NEXT: s_wqm_b64 exec, exec +-;CHECK: image_sample + ;CHECK-NOT: exec +-;CHECK: _load_dword v0, +-define amdgpu_ps float @test2(<8 x i32> inreg %rsrc, <4 x i32> inreg %sampler, float addrspace(1)* inreg %ptr, <4 x i32> %c) { ++define amdgpu_ps void @test2(<8 x i32> inreg %rsrc, <4 x i32> inreg %sampler, float addrspace(1)* inreg %ptr, <4 x i32> %c) { + main_body: + %c.1 = call <4 x float> @llvm.SI.image.sample.v4i32(<4 x i32> %c, <8 x i32> %rsrc, <4 x i32> %sampler, i32 15, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0) + %c.2 = bitcast <4 x float> %c.1 to <4 x i32> + %c.3 = extractelement <4 x i32> %c.2, i32 0 + %gep = getelementptr float, float addrspace(1)* %ptr, i32 %c.3 + %data = load float, float addrspace(1)* %gep +- ret float %data ++ ++ call void @llvm.SI.export(i32 15, i32 1, i32 1, i32 0, i32 1, float %data, float undef, float undef, float undef) ++ ++ ret void + } + + ; ... but disabled for stores (and, in this simple case, not re-enabled). +@@ -414,6 +415,46 @@ entry: + ret void + } + ++; Must return to exact at the end of a non-void returning shader, ++; otherwise the EXEC mask exported by the epilog will be wrong. This is true ++; even if the shader has no kills, because a kill could have happened in a ++; previous shader fragment. ++; ++; CHECK-LABEL: {{^}}test_nonvoid_return: ++; CHECK: s_mov_b64 [[LIVE:s\[[0-9]+:[0-9]+\]]], exec ++; CHECK: s_wqm_b64 exec, exec ++; ++; CHECK: s_and_b64 exec, exec, [[LIVE]] ++; CHECK-NOT: exec ++define amdgpu_ps <4 x float> @test_nonvoid_return() nounwind { ++ %tex = call <4 x float> @llvm.SI.image.sample.v4i32(<4 x i32> undef, <8 x i32> undef, <4 x i32> undef, i32 15, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0) ++ %tex.i = bitcast <4 x float> %tex to <4 x i32> ++ %dtex = call <4 x float> @llvm.SI.image.sample.v4i32(<4 x i32> %tex.i, <8 x i32> undef, <4 x i32> undef, i32 15, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0) ++ ret <4 x float> %dtex ++} ++ ++; CHECK-LABEL: {{^}}test_nonvoid_return_unreachable: ++; CHECK: s_mov_b64 [[LIVE:s\[[0-9]+:[0-9]+\]]], exec ++; CHECK: s_wqm_b64 exec, exec ++; ++; CHECK: s_and_b64 exec, exec, [[LIVE]] ++; CHECK-NOT: exec ++define amdgpu_ps <4 x float> @test_nonvoid_return_unreachable(i32 inreg %c) nounwind { ++entry: ++ %tex = call <4 x float> @llvm.SI.image.sample.v4i32(<4 x i32> undef, <8 x i32> undef, <4 x i32> undef, i32 15, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0) ++ %tex.i = bitcast <4 x float> %tex to <4 x i32> ++ %dtex = call <4 x float> @llvm.SI.image.sample.v4i32(<4 x i32> %tex.i, <8 x i32> undef, <4 x i32> undef, i32 15, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0) ++ ++ %cc = icmp sgt i32 %c, 0 ++ br i1 %cc, label %if, label %else ++ ++if: ++ store volatile <4 x float> %dtex, <4 x float>* undef ++ unreachable ++ ++else: ++ ret <4 x float> %dtex ++} + + declare void @llvm.amdgcn.image.store.v4i32(<4 x float>, <4 x i32>, <8 x i32>, i32, i1, i1, i1, i1) #1 + declare void @llvm.amdgcn.buffer.store.f32(float, <4 x i32>, i32, i32, i1, i1) #1 diff --git a/programming/build/llvm/files/llvm_link.patch b/programming/build/llvm/files/llvm_link.patch deleted file mode 100644 index 60090783ab..0000000000 --- a/programming/build/llvm/files/llvm_link.patch +++ /dev/null @@ -1,440 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index ac3b978..dd50236 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -342,9 +342,21 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) - option (LLVM_BUILD_EXTERNAL_COMPILER_RT - "Build compiler-rt as an external project." OFF) - --option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" OFF) --option(LLVM_DYLIB_EXPORT_ALL "Export all symbols from libLLVM.dylib (default is C API only" OFF) --option(LLVM_DISABLE_LLVM_DYLIB_ATEXIT "Disable llvm-shlib's atexit destructors." ON) -+# You can configure which libraries from LLVM you want to include in the -+# shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited -+# list of LLVM components. All component names handled by llvm-config are valid. -+if(NOT DEFINED LLVM_DYLIB_COMPONENTS) -+ set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING -+ "Semicolon-separated list of components to include in libLLVM, or \"all\".") -+endif() -+option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF) -+option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_LINK_LLVM_DYLIB}) -+option(LLVM_DYLIB_EXPORT_ALL "Export all symbols from libLLVM.dylib (default is C API only" ${LLVM_LINK_LLVM_DYLIB}) -+set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT ON) -+if (LLVM_LINK_LLVM_DYLIB) -+ set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT OFF) -+endif() -+option(LLVM_DISABLE_LLVM_DYLIB_ATEXIT "Disable llvm-shlib's atexit destructors." ${LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT}) - if(LLVM_DISABLE_LLVM_DYLIB_ATEXIT) - set(DISABLE_LLVM_DYLIB_ATEXIT 1) - endif() -diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake -index 45f6746..6b6e6e0 100644 ---- a/cmake/modules/AddLLVM.cmake -+++ b/cmake/modules/AddLLVM.cmake -@@ -41,7 +41,7 @@ function(llvm_update_compile_flags name) - # Assume that; - # - LLVM_COMPILE_FLAGS is list. - # - PROPERTY COMPILE_FLAGS is string. -- string(REPLACE ";" " " target_compile_flags "${LLVM_COMPILE_FLAGS}") -+ string(REPLACE ";" " " target_compile_flags " ${LLVM_COMPILE_FLAGS}") - - if(update_src_props) - foreach(fn ${sources}) -@@ -303,6 +303,9 @@ endfunction(set_windows_version_resource_properties) - # MODULE - # Target ${name} might not be created on unsupported platforms. - # Check with "if(TARGET ${name})". -+# DISABLE_LLVM_LINK_LLVM_DYLIB -+# Do not link this library to libLLVM, even if -+# LLVM_LINK_LLVM_DYLIB is enabled. - # OUTPUT_NAME name - # Corresponds to OUTPUT_NAME in target properties. - # DEPENDS targets... -@@ -316,7 +319,7 @@ endfunction(set_windows_version_resource_properties) - # ) - function(llvm_add_library name) - cmake_parse_arguments(ARG -- "MODULE;SHARED;STATIC" -+ "MODULE;SHARED;STATIC;DISABLE_LLVM_LINK_LLVM_DYLIB" - "OUTPUT_NAME" - "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS" - ${ARGN}) -@@ -444,10 +447,14 @@ function(llvm_add_library name) - # property has been set to an empty value. - get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) - -- llvm_map_components_to_libnames(llvm_libs -- ${ARG_LINK_COMPONENTS} -- ${LLVM_LINK_COMPONENTS} -- ) -+ if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_STATIC AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB) -+ set(llvm_libs LLVM) -+ else() -+ llvm_map_components_to_libnames(llvm_libs -+ ${ARG_LINK_COMPONENTS} -+ ${LLVM_LINK_COMPONENTS} -+ ) -+ endif() - - if(CMAKE_VERSION VERSION_LESS 2.8.12) - # Link libs w/o keywords, assuming PUBLIC. -@@ -562,7 +569,22 @@ endmacro(add_llvm_loadable_module name) - - - macro(add_llvm_executable name) -- llvm_process_sources( ALL_FILES ${ARGN} ) -+ cmake_parse_arguments(ARG "DISABLE_LLVM_LINK_LLVM_DYLIB" "" "" ${ARGN}) -+ llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ) -+ -+ # Generate objlib -+ if(LLVM_ENABLE_OBJLIB) -+ # Generate an obj library for both targets. -+ set(obj_name "obj.${name}") -+ add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL -+ ${ALL_FILES} -+ ) -+ llvm_update_compile_flags(${obj_name}) -+ set(ALL_FILES "$") -+ -+ set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries") -+ endif() -+ - add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) - - if( EXCLUDE_FROM_ALL ) -@@ -588,9 +610,13 @@ macro(add_llvm_executable name) - add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) - endif(LLVM_EXPORTED_SYMBOL_FILE) - -+ if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB) -+ set(USE_SHARED USE_SHARED) -+ endif() -+ - set(EXCLUDE_FROM_ALL OFF) - set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR}) -- llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) -+ llvm_config( ${name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} ) - if( LLVM_COMMON_DEPENDS ) - add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) - endif( LLVM_COMMON_DEPENDS ) -@@ -651,7 +677,7 @@ endmacro(add_llvm_example name) - - - macro(add_llvm_utility name) -- add_llvm_executable(${name} ${ARGN}) -+ add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN}) - set_target_properties(${name} PROPERTIES FOLDER "Utils") - if( LLVM_INSTALL_UTILS ) - install (TARGETS ${name} -@@ -785,8 +811,13 @@ function(llvm_add_go_executable binary pkgpath) - set(cppflags "${cppflags} -I${d}") - endforeach(d) - set(ldflags "${CMAKE_EXE_LINKER_FLAGS}") -+ if (LLVM_LINK_LLVM_DYLIB) -+ set(linkmode "dylib") -+ else() -+ set(linkmode "component-libs") -+ endif() - add_custom_command(OUTPUT ${binpath} -- COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" -+ COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" "linkmode=${linkmode}" - ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath} - DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX} - ${llvmlibs} ${ARG_DEPENDS} -diff --git a/cmake/modules/LLVM-Config.cmake b/cmake/modules/LLVM-Config.cmake -index 22ac714..aa68b40 100644 ---- a/cmake/modules/LLVM-Config.cmake -+++ b/cmake/modules/LLVM-Config.cmake -@@ -31,7 +31,23 @@ endfunction(is_llvm_target_library) - - - macro(llvm_config executable) -- explicit_llvm_config(${executable} ${ARGN}) -+ cmake_parse_arguments(ARG "USE_SHARED" "" "" ${ARGN}) -+ set(link_components ${ARG_UNPARSED_ARGUMENTS}) -+ -+ if(USE_SHARED) -+ # If USE_SHARED is specified, then we link against libLLVM, -+ # but also against the component libraries below. This is -+ # done in case libLLVM does not contain all of the components -+ # the target requires. -+ # -+ # TODO strip LLVM_DYLIB_COMPONENTS out of link_components. -+ # To do this, we need special handling for "all", since that -+ # may imply linking to libraries that are not included in -+ # libLLVM. -+ target_link_libraries(${executable} LLVM) -+ endif() -+ -+ explicit_llvm_config(${executable} ${link_components}) - endmacro(llvm_config) - - -diff --git a/cmake/modules/TableGen.cmake b/cmake/modules/TableGen.cmake -index 85d720e..fcb445a 100644 ---- a/cmake/modules/TableGen.cmake -+++ b/cmake/modules/TableGen.cmake -@@ -73,6 +73,10 @@ endfunction() - macro(add_tablegen target project) - set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS}) - set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen) -+ -+ # FIXME: It leaks to user, callee of add_tablegen. -+ set(LLVM_ENABLE_OBJLIB ON) -+ - add_llvm_utility(${target} ${ARGN}) - set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS}) - -diff --git a/tools/llvm-go/llvm-go.go b/tools/llvm-go/llvm-go.go -index c5c3fd2..ed79ca6 100644 ---- a/tools/llvm-go/llvm-go.go -+++ b/tools/llvm-go/llvm-go.go -@@ -24,6 +24,11 @@ import ( - "strings" - ) - -+const ( -+ linkmodeComponentLibs = "component-libs" -+ linkmodeDylib = "dylib" -+) -+ - type pkg struct { - llvmpath, pkgpath string - } -@@ -66,11 +71,12 @@ var components = []string{ - func llvmConfig(args ...string) string { - configpath := os.Getenv("LLVM_CONFIG") - if configpath == "" { -- // strip llvm-go, add llvm-config -- configpath = os.Args[0][:len(os.Args[0])-7] + "llvm-config" -+ bin, _ := filepath.Split(os.Args[0]) -+ configpath = filepath.Join(bin, "llvm-config") - } - - cmd := exec.Command(configpath, args...) -+ cmd.Stderr = os.Stderr - out, err := cmd.Output() - if err != nil { - panic(err.Error()) -@@ -78,11 +84,21 @@ func llvmConfig(args ...string) string { - - outstr := string(out) - outstr = strings.TrimSuffix(outstr, "\n") -- return strings.Replace(outstr, "\n", " ", -1) -+ outstr = strings.Replace(outstr, "\n", " ", -1) -+ return outstr - } - --func llvmFlags() compilerFlags { -- ldflags := llvmConfig(append([]string{"--ldflags", "--libs", "--system-libs"}, components...)...) -+func llvmFlags(linkmode string) compilerFlags { -+ ldflags := llvmConfig("--ldflags") -+ switch linkmode { -+ case linkmodeComponentLibs: -+ ldflags += " " + llvmConfig(append([]string{"--libs"}, components...)...) -+ case linkmodeDylib: -+ ldflags += " -lLLVM" -+ default: -+ panic("invalid linkmode: " + linkmode) -+ } -+ ldflags += " " + llvmConfig("--system-libs") - if runtime.GOOS != "darwin" { - // OS X doesn't like -rpath with cgo. See: - // https://code.google.com/p/go/issues/detail?id=7293 -@@ -117,8 +133,8 @@ func printComponents() { - fmt.Println(strings.Join(components, " ")) - } - --func printConfig() { -- flags := llvmFlags() -+func printConfig(linkmode string) { -+ flags := llvmFlags(linkmode) - - fmt.Printf(`// +build !byollvm - -@@ -137,7 +153,7 @@ type (run_build_sh int) - `, flags.cpp, flags.cxx, flags.ld) - } - --func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags string) { -+func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, linkmode string) { - args = addTag(args, "byollvm") - - srcdir := llvmConfig("--src-root") -@@ -166,7 +182,7 @@ func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, l - newgopathlist = append(newgopathlist, filepath.SplitList(os.Getenv("GOPATH"))...) - newgopath := strings.Join(newgopathlist, string(filepath.ListSeparator)) - -- flags := llvmFlags() -+ flags := llvmFlags(linkmode) - - newenv := []string{ - "CC=" + cc, -@@ -178,7 +194,7 @@ func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, l - "PATH=" + newpath, - } - if llgo != "" { -- newenv = append(newenv, "GCCGO=" + llgo) -+ newenv = append(newenv, "GCCGO="+llgo) - } - - for _, v := range os.Environ() { -@@ -234,45 +250,44 @@ func main() { - ldflags := os.Getenv("CGO_LDFLAGS") - gocmd := "go" - llgo := "" -+ linkmode := linkmodeComponentLibs -+ -+ flags := []struct { -+ name string -+ dest *string -+ }{ -+ {"cc", &cc}, -+ {"cxx", &cxx}, -+ {"go", &gocmd}, -+ {"llgo", &llgo}, -+ {"cppflags", &cppflags}, -+ {"ldflags", &ldflags}, -+ {"linkmode", &linkmode}, -+ } - - args := os.Args[1:] -- DONE: for { -- switch { -- case len(args) == 0: -+LOOP: -+ for { -+ if len(args) == 0 { - usage() -- case strings.HasPrefix(args[0], "cc="): -- cc = args[0][3:] -- args = args[1:] -- case strings.HasPrefix(args[0], "cxx="): -- cxx = args[0][4:] -- args = args[1:] -- case strings.HasPrefix(args[0], "go="): -- gocmd = args[0][3:] -- args = args[1:] -- case strings.HasPrefix(args[0], "llgo="): -- llgo = args[0][5:] -- args = args[1:] -- case strings.HasPrefix(args[0], "cppflags="): -- cppflags = args[0][9:] -- args = args[1:] -- case strings.HasPrefix(args[0], "cxxflags="): -- cxxflags = args[0][9:] -- args = args[1:] -- case strings.HasPrefix(args[0], "ldflags="): -- ldflags = args[0][8:] -- args = args[1:] -- default: -- break DONE - } -+ for _, flag := range flags { -+ if strings.HasPrefix(args[0], flag.name+"=") { -+ *flag.dest = args[0][len(flag.name)+1:] -+ args = args[1:] -+ continue LOOP -+ } -+ } -+ break - } - - switch args[0] { - case "build", "get", "install", "run", "test": -- runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags) -+ runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, linkmode) - case "print-components": - printComponents() - case "print-config": -- printConfig() -+ printConfig(linkmode) - default: - usage() - } -diff --git a/tools/llvm-shlib/CMakeLists.txt b/tools/llvm-shlib/CMakeLists.txt -index 54d71d3..d9bd15f 100644 ---- a/tools/llvm-shlib/CMakeLists.txt -+++ b/tools/llvm-shlib/CMakeLists.txt -@@ -2,42 +2,6 @@ - # library is enabled by setting LLVM_BUILD_LLVM_DYLIB=yes on the CMake - # commandline. By default the shared library only exports the LLVM C API. - -- --# You can configure which libraries from LLVM you want to include in the shared --# library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited list of --# LLVM components. All compoenent names handled by llvm-config are valid. -- --if(NOT DEFINED LLVM_DYLIB_COMPONENTS) -- set(LLVM_DYLIB_COMPONENTS -- ${LLVM_TARGETS_TO_BUILD} -- Analysis -- BitReader -- BitWriter -- CodeGen -- Core -- DebugInfoDWARF -- DebugInfoPDB -- ExecutionEngine -- IPA -- IPO -- IRReader -- InstCombine -- Instrumentation -- Interpreter -- Linker -- MCDisassembler -- MCJIT -- ObjCARCOpts -- Object -- ScalarOpts -- Support -- Target -- TransformUtils -- Vectorize -- native -- ) --endif() -- - add_definitions( -DLLVM_VERSION_INFO=\"${PACKAGE_VERSION}\" ) - - set(SOURCES -@@ -46,6 +10,29 @@ set(SOURCES - - llvm_map_components_to_libnames(LIB_NAMES ${LLVM_DYLIB_COMPONENTS}) - -+if(LLVM_LINK_LLVM_DYLIB) -+ if(NOT LLVM_DYLIB_EXPORT_ALL) -+ message(FATAL_ERROR "LLVM_DYLIB_EXPORT_ALL must be ON when LLVM_LINK_LLVM_DYLIB is ON") -+ endif() -+ -+ # libLLVM.so should not have any dependencies on any other LLVM -+ # shared libraries. When using the "all" pseudo-component, -+ # LLVM_AVAILABLE_LIBS is added to the dependencies, which may -+ # contain shared libraries (e.g. libLTO). -+ # -+ # Also exclude libLLVMTableGen for the following reasons: -+ # - it is only used by internal *-tblgen utilities; -+ # - it pollutes the global options space. -+ foreach(lib ${LIB_NAMES}) -+ get_target_property(t ${lib} TYPE) -+ if("${lib}" STREQUAL "LLVMTableGen") -+ elseif("x${t}" STREQUAL "xSTATIC_LIBRARY") -+ list(APPEND FILTERED_LIB_NAMES ${lib}) -+ endif() -+ endforeach() -+ set(LIB_NAMES ${FILTERED_LIB_NAMES}) -+endif() -+ - if(NOT DEFINED LLVM_DYLIB_EXPORTED_SYMBOL_FILE) - - if( WIN32 AND NOT CYGWIN ) -@@ -95,7 +82,7 @@ else() - add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE}) - endif() - --add_llvm_library(LLVM SHARED ${SOURCES}) -+add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB ${SOURCES}) - - list(REMOVE_DUPLICATES LIB_NAMES) -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") # FIXME: It should be "GNU ld for elf" \ No newline at end of file diff --git a/programming/build/llvm/files/msan-prevent-initialization-failure-with-newer-glibc.patch b/programming/build/llvm/files/msan-prevent-initialization-failure-with-newer-glibc.patch new file mode 100644 index 0000000000..57387a6a12 --- /dev/null +++ b/programming/build/llvm/files/msan-prevent-initialization-failure-with-newer-glibc.patch @@ -0,0 +1,103 @@ +Index: lib/msan/msan_interceptors.cc +=================================================================== +--- lib/msan/msan_interceptors.cc (revision 282231) ++++ lib/msan/msan_interceptors.cc (revision 282232) +@@ -64,6 +64,23 @@ + return in_interceptor_scope; + } + ++static uptr allocated_for_dlsym; ++static const uptr kDlsymAllocPoolSize = 1024; ++static uptr alloc_memory_for_dlsym[kDlsymAllocPoolSize]; ++ ++static bool IsInDlsymAllocPool(const void *ptr) { ++ uptr off = (uptr)ptr - (uptr)alloc_memory_for_dlsym; ++ return off < sizeof(alloc_memory_for_dlsym); ++} ++ ++static void *AllocateFromLocalPool(uptr size_in_bytes) { ++ uptr size_in_words = RoundUpTo(size_in_bytes, kWordSize) / kWordSize; ++ void *mem = (void *)&alloc_memory_for_dlsym[allocated_for_dlsym]; ++ allocated_for_dlsym += size_in_words; ++ CHECK_LT(allocated_for_dlsym, kDlsymAllocPoolSize); ++ return mem; ++} ++ + #define ENSURE_MSAN_INITED() do { \ + CHECK(!msan_init_is_running); \ + if (!msan_inited) { \ +@@ -227,7 +244,7 @@ + + INTERCEPTOR(void, free, void *ptr) { + GET_MALLOC_STACK_TRACE; +- if (!ptr) return; ++ if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return; + MsanDeallocate(&stack, ptr); + } + +@@ -234,7 +251,7 @@ + #if !SANITIZER_FREEBSD + INTERCEPTOR(void, cfree, void *ptr) { + GET_MALLOC_STACK_TRACE; +- if (!ptr) return; ++ if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return; + MsanDeallocate(&stack, ptr); + } + #define MSAN_MAYBE_INTERCEPT_CFREE INTERCEPT_FUNCTION(cfree) +@@ -907,27 +924,29 @@ + + INTERCEPTOR(void *, calloc, SIZE_T nmemb, SIZE_T size) { + GET_MALLOC_STACK_TRACE; +- if (UNLIKELY(!msan_inited)) { ++ if (UNLIKELY(!msan_inited)) + // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym. +- const SIZE_T kCallocPoolSize = 1024; +- static uptr calloc_memory_for_dlsym[kCallocPoolSize]; +- static SIZE_T allocated; +- SIZE_T size_in_words = ((nmemb * size) + kWordSize - 1) / kWordSize; +- void *mem = (void*)&calloc_memory_for_dlsym[allocated]; +- allocated += size_in_words; +- CHECK(allocated < kCallocPoolSize); +- return mem; +- } ++ return AllocateFromLocalPool(nmemb * size); + return MsanCalloc(&stack, nmemb, size); + } + + INTERCEPTOR(void *, realloc, void *ptr, SIZE_T size) { + GET_MALLOC_STACK_TRACE; ++ if (UNLIKELY(IsInDlsymAllocPool(ptr))) { ++ uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym; ++ uptr copy_size = Min(size, kDlsymAllocPoolSize - offset); ++ void *new_ptr = AllocateFromLocalPool(size); ++ internal_memcpy(new_ptr, ptr, copy_size); ++ return new_ptr; ++ } + return MsanReallocate(&stack, ptr, size, sizeof(u64), false); + } + + INTERCEPTOR(void *, malloc, SIZE_T size) { + GET_MALLOC_STACK_TRACE; ++ if (UNLIKELY(!msan_inited)) ++ // Hack: dlsym calls malloc before REAL(malloc) is retrieved from dlsym. ++ return AllocateFromLocalPool(size); + return MsanReallocate(&stack, nullptr, size, sizeof(u64), false); + } + +Index: lib/asan/asan_malloc_linux.cc +=================================================================== +--- lib/asan/asan_malloc_linux.cc (revision 282231) ++++ lib/asan/asan_malloc_linux.cc (revision 282232) +@@ -78,7 +78,11 @@ + if (UNLIKELY(IsInDlsymAllocPool(ptr))) { + uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym; + uptr copy_size = Min(size, kDlsymAllocPoolSize - offset); +- void *new_ptr = asan_malloc(size, &stack); ++ void *new_ptr; ++ if (UNLIKELY(!asan_inited)) ++ new_ptr = AllocateFromLocalPool(size); ++ else ++ new_ptr = asan_malloc(size, &stack); + internal_memcpy(new_ptr, ptr, copy_size); + return new_ptr; + } diff --git a/programming/build/llvm/pspec.xml b/programming/build/llvm/pspec.xml index 08c91b822a..72fef57d0b 100644 --- a/programming/build/llvm/pspec.xml +++ b/programming/build/llvm/pspec.xml @@ -16,6 +16,10 @@ http://releases.llvm.org/3.9.1/clang-tools-extra-3.9.1.src.tar.xz http://releases.llvm.org/3.9.1/lldb-3.9.1.src.tar.xz http://releases.llvm.org/3.9.1/compiler-rt-3.9.1.src.tar.xz + + msan-prevent-initialization-failure-with-newer-glibc.patch + AMDGPU-Fix-an-interaction-between-WQM-and-polygon-stippling.patch + zlib-devel libxml2-devel @@ -30,9 +34,6 @@ binutils - - llvm_link.patch -