From 622ff5c1f53a69f2ab273eaa3840e7c786972b4b Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 23 Mar 2017 14:27:53 +0000 Subject: [PATCH] LLVM 4.0.0 Final Release --- .gitignore | 1 + ...read-handling-for-out-of-tree-builds.patch | 193 +++ ...ix-R_AARCH64_MOVW_UABS_G3-relocation.patch | 435 ------ ...Fv2-ABI-updates-for-the-.opd-section.patch | 53 - 0001-Revert-Merging-r280589.patch | 119 -- ...breaks-the-docs-build-http-lab.llvm..patch | 30 - 0001-add-gcc-abi_tag-support.patch | 1232 ----------------- ...all-CheckAtomic.cmake-needed-by-lldb.patch | 39 - 0001-data-install-preserve-timestamps.patch | 22 - 0001-docs-fix-cmake-code-block-warning.patch | 44 - 0001-fix-docs-2.patch | 38 - 0001-fix-docs-3.patch | 46 - ...vious-Clang-trunk-patch-to-Clang-3.7.patch | 24 - 0002-linker-flags-speedup-memory.patch | 12 - clang-3.4-arm-hard-float.patch | 16 - fix-broken-include-path.patch | 12 - lldb-python-module-symlink.patch | 16 - lldb-python.patch | 16 - llvm-3.4-radeonsi-backport.patch | 459 ------ llvm-r294646.patch | 13 - llvm.spec | 47 +- pr12586.patch | 13 - rust-lang-llvm-pr47.patch | 272 ---- rust-lang-llvm-pr53.patch | 883 ------------ rust-lang-llvm-pr54.patch | 103 -- rust-lang-llvm-pr55.patch | 85 -- rust-lang-llvm-pr57.patch | 118 -- sources | 2 +- 28 files changed, 204 insertions(+), 4139 deletions(-) create mode 100644 0001-CMake-Fix-pthread-handling-for-out-of-tree-builds.patch delete mode 100644 0001-Fix-R_AARCH64_MOVW_UABS_G3-relocation.patch delete mode 100644 0001-PPC64LE-ELFv2-ABI-updates-for-the-.opd-section.patch delete mode 100644 0001-Revert-Merging-r280589.patch delete mode 100644 0001-This-code-block-breaks-the-docs-build-http-lab.llvm..patch delete mode 100644 0001-add-gcc-abi_tag-support.patch delete mode 100644 0001-cmake-Install-CheckAtomic.cmake-needed-by-lldb.patch delete mode 100644 0001-data-install-preserve-timestamps.patch delete mode 100644 0001-docs-fix-cmake-code-block-warning.patch delete mode 100644 0001-fix-docs-2.patch delete mode 100644 0001-fix-docs-3.patch delete mode 100644 0002-Adapt-previous-Clang-trunk-patch-to-Clang-3.7.patch delete mode 100644 0002-linker-flags-speedup-memory.patch delete mode 100644 clang-3.4-arm-hard-float.patch delete mode 100644 fix-broken-include-path.patch delete mode 100644 lldb-python-module-symlink.patch delete mode 100644 lldb-python.patch delete mode 100644 llvm-3.4-radeonsi-backport.patch delete mode 100644 llvm-r294646.patch delete mode 100644 pr12586.patch delete mode 100644 rust-lang-llvm-pr47.patch delete mode 100644 rust-lang-llvm-pr53.patch delete mode 100644 rust-lang-llvm-pr54.patch delete mode 100644 rust-lang-llvm-pr55.patch delete mode 100644 rust-lang-llvm-pr57.patch diff --git a/.gitignore b/.gitignore index 0f6b3e6..a55fffc 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ /llvm-3.8.1.src.tar.xz /llvm-3.9.0.src.tar.xz /llvm-3.9.1.src.tar.xz +/llvm-4.0.0.src.tar.xz diff --git a/0001-CMake-Fix-pthread-handling-for-out-of-tree-builds.patch b/0001-CMake-Fix-pthread-handling-for-out-of-tree-builds.patch new file mode 100644 index 0000000..0ad05d4 --- /dev/null +++ b/0001-CMake-Fix-pthread-handling-for-out-of-tree-builds.patch @@ -0,0 +1,193 @@ +From a61fc423f3c043314efd4c0cdb1367de2077ac36 Mon Sep 17 00:00:00 2001 +From: Eric Fiselier +Date: Fri, 10 Feb 2017 01:59:20 +0000 +Subject: [PATCH] [CMake] Fix pthread handling for out-of-tree builds + +LLVM defines `PTHREAD_LIB` which is used by AddLLVM.cmake and various projects +to correctly link the threading library when needed. Unfortunately +`PTHREAD_LIB` is defined by LLVM's `config-ix.cmake` file which isn't installed +and therefore can't be used when configuring out-of-tree builds. This causes +such builds to fail since `pthread` isn't being correctly linked. + +This patch attempts to fix that problem by renaming and exporting +`LLVM_PTHREAD_LIB` as part of`LLVMConfig.cmake`. I renamed `PTHREAD_LIB` +because It seemed likely to cause collisions with downstream users of +`LLVMConfig.cmake`. + + +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294690 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + cmake/config-ix.cmake | 2 +- + cmake/modules/AddLLVM.cmake | 6 +++--- + cmake/modules/LLVMConfig.cmake.in | 4 ++++ + examples/ParallelJIT/CMakeLists.txt | 2 +- + lib/CodeGen/CMakeLists.txt | 2 +- + lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt | 2 +- + lib/Fuzzer/CMakeLists.txt | 4 ++-- + lib/Support/CMakeLists.txt | 2 +- + unittests/ExecutionEngine/Orc/CMakeLists.txt | 2 +- + unittests/Support/CMakeLists.txt | 2 +- + utils/unittest/CMakeLists.txt | 4 ++-- + 11 files changed, 18 insertions(+), 14 deletions(-) + +diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake +index 50bcc50..6bd2b53 100755 +--- a/cmake/config-ix.cmake ++++ b/cmake/config-ix.cmake +@@ -115,7 +115,7 @@ if(HAVE_LIBPTHREAD) + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) + set(THREADS_HAVE_PTHREAD_ARG Off) + find_package(Threads REQUIRED) +- set(PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) ++ set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) + endif() + + # Don't look for these libraries on Windows. Also don't look for them if we're +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index b3c7746..cb4171c 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -718,11 +718,11 @@ macro(add_llvm_executable name) + if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO) + llvm_externalize_debuginfo(${name}) + endif() +- if (PTHREAD_LIB) ++ if (LLVM_PTHREAD_LIB) + # libpthreads overrides some standard library symbols, so main + # executable must be linked with it in order to provide consistent + # API for all shared libaries loaded by this executable. +- target_link_libraries(${name} ${PTHREAD_LIB}) ++ target_link_libraries(${name} ${LLVM_PTHREAD_LIB}) + endif() + endmacro(add_llvm_executable name) + +@@ -1027,7 +1027,7 @@ function(add_unittest test_suite test_name) + # libpthreads overrides some standard library symbols, so main + # executable must be linked with it in order to provide consistent + # API for all shared libaries loaded by this executable. +- target_link_libraries(${test_name} gtest_main gtest ${PTHREAD_LIB}) ++ target_link_libraries(${test_name} gtest_main gtest ${LLVM_PTHREAD_LIB}) + + add_dependencies(${test_suite} ${test_name}) + get_target_property(test_suite_folder ${test_suite} FOLDER) +diff --git a/cmake/modules/LLVMConfig.cmake.in b/cmake/modules/LLVMConfig.cmake.in +index 2aea2dc..7a8eb36 100644 +--- a/cmake/modules/LLVMConfig.cmake.in ++++ b/cmake/modules/LLVMConfig.cmake.in +@@ -45,6 +45,10 @@ set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@) + + set(LLVM_BUILD_32_BITS @LLVM_BUILD_32_BITS@) + ++if (NOT "@LLVM_PTHREAD_LIB@" STREQUAL "") ++ set(LLVM_PTHREAD_LIB "@LLVM_PTHREAD_LIB@") ++endif() ++ + set(LLVM_ENABLE_PLUGINS @LLVM_ENABLE_PLUGINS@) + set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS @LLVM_EXPORT_SYMBOLS_FOR_PLUGINS@) + set(LLVM_PLUGIN_EXT @LLVM_PLUGIN_EXT@) +diff --git a/examples/ParallelJIT/CMakeLists.txt b/examples/ParallelJIT/CMakeLists.txt +index e85b470..deeee07 100644 +--- a/examples/ParallelJIT/CMakeLists.txt ++++ b/examples/ParallelJIT/CMakeLists.txt +@@ -11,4 +11,4 @@ add_llvm_example(ParallelJIT + ParallelJIT.cpp + ) + +-target_link_libraries(ParallelJIT ${PTHREAD_LIB}) ++target_link_libraries(ParallelJIT ${LLVM_PTHREAD_LIB}) +diff --git a/lib/CodeGen/CMakeLists.txt b/lib/CodeGen/CMakeLists.txt +index a1e5fd4..a9a3d85 100644 +--- a/lib/CodeGen/CMakeLists.txt ++++ b/lib/CodeGen/CMakeLists.txt +@@ -150,7 +150,7 @@ add_llvm_library(LLVMCodeGen + ${LLVM_MAIN_INCLUDE_DIR}/llvm/CodeGen + ${LLVM_MAIN_INCLUDE_DIR}/llvm/CodeGen/PBQP + +- LINK_LIBS ${PTHREAD_LIB} ++ LINK_LIBS ${LLVM_PTHREAD_LIB} + + DEPENDS + intrinsics_gen +diff --git a/lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt b/lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt +index 3b8c4b9..e6c33b2 100644 +--- a/lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt ++++ b/lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt +@@ -4,7 +4,7 @@ if( HAVE_LIBDL ) + set(LLVM_INTEL_JIT_LIBS ${CMAKE_DL_LIBS}) + endif() + +-set(LLVM_INTEL_JIT_LIBS ${PTHREAD_LIB} ${LLVM_INTEL_JIT_LIBS}) ++set(LLVM_INTEL_JIT_LIBS ${LLVM_PTHREAD_LIB} ${LLVM_INTEL_JIT_LIBS}) + + + add_llvm_library(LLVMIntelJITEvents +diff --git a/lib/Fuzzer/CMakeLists.txt b/lib/Fuzzer/CMakeLists.txt +index 5ba126e..f490b36 100644 +--- a/lib/Fuzzer/CMakeLists.txt ++++ b/lib/Fuzzer/CMakeLists.txt +@@ -34,12 +34,12 @@ if( LLVM_USE_SANITIZE_COVERAGE ) + add_library(LLVMFuzzerNoMain STATIC + $ + ) +- target_link_libraries(LLVMFuzzerNoMain ${PTHREAD_LIB}) ++ target_link_libraries(LLVMFuzzerNoMain ${LLVM_PTHREAD_LIB}) + add_library(LLVMFuzzer STATIC + FuzzerMain.cpp + $ + ) +- target_link_libraries(LLVMFuzzer ${PTHREAD_LIB}) ++ target_link_libraries(LLVMFuzzer ${LLVM_PTHREAD_LIB}) + + if( LLVM_INCLUDE_TESTS ) + add_subdirectory(test) +diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt +index 3301364..f7cfa76 100644 +--- a/lib/Support/CMakeLists.txt ++++ b/lib/Support/CMakeLists.txt +@@ -17,7 +17,7 @@ elseif( CMAKE_HOST_UNIX ) + if( LLVM_ENABLE_THREADS AND HAVE_LIBATOMIC ) + set(system_libs ${system_libs} atomic) + endif() +- set(system_libs ${system_libs} ${PTHREAD_LIB}) ++ set(system_libs ${system_libs} ${LLVM_PTHREAD_LIB}) + if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ ) + set(system_libs ${system_libs} z) + endif() +diff --git a/unittests/ExecutionEngine/Orc/CMakeLists.txt b/unittests/ExecutionEngine/Orc/CMakeLists.txt +index 68f6d0c..80c344e 100644 +--- a/unittests/ExecutionEngine/Orc/CMakeLists.txt ++++ b/unittests/ExecutionEngine/Orc/CMakeLists.txt +@@ -21,4 +21,4 @@ add_llvm_unittest(OrcJITTests + RPCUtilsTest.cpp + ) + +-target_link_libraries(OrcJITTests ${PTHREAD_LIB}) ++target_link_libraries(OrcJITTests ${LLVM_PTHREAD_LIB}) +diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt +index 4c9bb5e..ea26079 100644 +--- a/unittests/Support/CMakeLists.txt ++++ b/unittests/Support/CMakeLists.txt +@@ -64,4 +64,4 @@ add_llvm_unittest(SupportTests + ) + + # ManagedStatic.cpp uses . +-target_link_libraries(SupportTests ${PTHREAD_LIB}) ++target_link_libraries(SupportTests ${LLVM_PTHREAD_LIB}) +diff --git a/utils/unittest/CMakeLists.txt b/utils/unittest/CMakeLists.txt +index a50733a..b42ac83 100644 +--- a/utils/unittest/CMakeLists.txt ++++ b/utils/unittest/CMakeLists.txt +@@ -40,8 +40,8 @@ if (NOT LLVM_ENABLE_THREADS) + add_definitions( -DGTEST_HAS_PTHREAD=0 ) + endif() + +-find_library(PTHREAD_LIBRARY_PATH pthread) +-if (PTHREAD_LIBRARY_PATH) ++find_library(LLVM_PTHREAD_LIBRARY_PATH pthread) ++if (LLVM_PTHREAD_LIBRARY_PATH) + list(APPEND LIBS pthread) + endif() + +-- +1.8.3.1 + diff --git a/0001-Fix-R_AARCH64_MOVW_UABS_G3-relocation.patch b/0001-Fix-R_AARCH64_MOVW_UABS_G3-relocation.patch deleted file mode 100644 index c5517ad..0000000 --- a/0001-Fix-R_AARCH64_MOVW_UABS_G3-relocation.patch +++ /dev/null @@ -1,435 +0,0 @@ -From 29cf3bd00fe84ddab138c9311fe288bb9da8a273 Mon Sep 17 00:00:00 2001 -From: root -Date: Thu, 9 Mar 2017 12:22:48 -0600 -Subject: [PATCH] Fix R_AARCH64_MOVW_UABS_G3 relocation - -Summary: The relocation is missing mask so an address that -has non-zero bits in 47:43 may overwrite the register -number. (Frequently shows up as target register changed -to xzr....) - -Reviewers: t.p.northover, lhames -Subscribers: davide, aemerson, rengolin, llvm-commits -Differential Revision: https://reviews.llvm.org/D27609 ---- - llvm-3.9.1.src/include/llvm/Object/ELFObjectFile.h | 2 +- - llvm-3.9.1.src/include/llvm/Object/RelocVisitor.h | 1 + - .../ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 67 +++++++++----- - .../RuntimeDyld/AArch64/ELF_ARM64_BE-relocations.s | 102 +++++++++++++++++++++ - .../RuntimeDyld/AArch64/ELF_ARM64_relocations.s | 99 ++++++++++++++++++++ - 5 files changed, 249 insertions(+), 22 deletions(-) - create mode 100644 llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_BE-relocations.s - create mode 100644 llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_relocations.s - -diff --git a/llvm-3.9.1.src/include/llvm/Object/ELFObjectFile.h b/llvm-3.9.1.src/include/llvm/Object/ELFObjectFile.h -index 07c6364..d3b83f9 100644 ---- a/llvm-3.9.1.src/include/llvm/Object/ELFObjectFile.h -+++ b/llvm-3.9.1.src/include/llvm/Object/ELFObjectFile.h -@@ -907,7 +907,7 @@ unsigned ELFObjectFile::getArch() const { - case ELF::EM_X86_64: - return Triple::x86_64; - case ELF::EM_AARCH64: -- return Triple::aarch64; -+ return IsLittleEndian ? Triple::aarch64 : Triple::aarch64_be; - case ELF::EM_ARM: - return Triple::arm; - case ELF::EM_AVR: -diff --git a/llvm-3.9.1.src/include/llvm/Object/RelocVisitor.h b/llvm-3.9.1.src/include/llvm/Object/RelocVisitor.h -index 5e0df98..b59e8ec 100644 ---- a/llvm-3.9.1.src/include/llvm/Object/RelocVisitor.h -+++ b/llvm-3.9.1.src/include/llvm/Object/RelocVisitor.h -@@ -86,6 +86,7 @@ private: - return RelocToApply(); - } - case Triple::aarch64: -+ case Triple::aarch64_be: - switch (RelocType) { - case llvm::ELF::R_AARCH64_ABS32: - return visitELF_AARCH64_ABS32(R, Value); -diff --git a/llvm-3.9.1.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm-3.9.1.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp -index 9cbdb13..9e04b5d 100644 ---- a/llvm-3.9.1.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp -+++ b/llvm-3.9.1.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp -@@ -309,6 +309,8 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section, - uint32_t *TargetPtr = - reinterpret_cast(Section.getAddressWithOffset(Offset)); - uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset); -+ // Data should use target endian. Code should always use little endian. -+ bool isBE = Arch == Triple::aarch64_be; - - DEBUG(dbgs() << "resolveAArch64Relocation, LocalAddress: 0x" - << format("%llx", Section.getAddressWithOffset(Offset)) -@@ -324,14 +326,22 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section, - case ELF::R_AARCH64_ABS64: { - uint64_t *TargetPtr = - reinterpret_cast(Section.getAddressWithOffset(Offset)); -- *TargetPtr = Value + Addend; -+ if (isBE) -+ support::ubig64_t::ref{TargetPtr} = Value + Addend; -+ else -+ support::ulittle64_t::ref{TargetPtr} = Value + Addend; - break; - } - case ELF::R_AARCH64_PREL32: { - uint64_t Result = Value + Addend - FinalAddress; - assert(static_cast(Result) >= INT32_MIN && - static_cast(Result) <= UINT32_MAX); -- *TargetPtr = static_cast(Result & 0xffffffffU); -+ if (isBE) -+ support::ubig32_t::ref{TargetPtr} = -+ static_cast(Result & 0xffffffffU); -+ else -+ support::ulittle32_t::ref{TargetPtr} = -+ static_cast(Result & 0xffffffffU); - break; - } - case ELF::R_AARCH64_CALL26: // fallthrough -@@ -339,6 +349,7 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section, - // Operation: S+A-P. Set Call or B immediate value to bits fff_fffc of the - // calculation. - uint64_t BranchImm = Value + Addend - FinalAddress; -+ uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr}; - - // "Check that -2^27 <= result < 2^27". - assert(isInt<28>(BranchImm)); -@@ -352,91 +363,105 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section, - } - case ELF::R_AARCH64_MOVW_UABS_G3: { - uint64_t Result = Value + Addend; -+ uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr}; - - // AArch64 code is emitted with .rela relocations. The data already in any - // bits affected by the relocation on entry is garbage. -- *TargetPtr &= 0xffe0001fU; -+ TargetValue &= 0xffe0001fU; - // Immediate goes in bits 20:5 of MOVZ/MOVK instruction -- *TargetPtr |= Result >> (48 - 5); -+ TargetValue |= ((Result & 0xffff000000000000ULL) >> (48 - 5)); - // Shift must be "lsl #48", in bits 22:21 -- assert((*TargetPtr >> 21 & 0x3) == 3 && "invalid shift for relocation"); -+ assert((TargetValue >> 21 & 0x3) == 3 && "invalid shift for relocation"); -+ support::ulittle32_t::ref{TargetPtr} = TargetValue; - break; - } - case ELF::R_AARCH64_MOVW_UABS_G2_NC: { - uint64_t Result = Value + Addend; -+ uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr}; - - // AArch64 code is emitted with .rela relocations. The data already in any - // bits affected by the relocation on entry is garbage. -- *TargetPtr &= 0xffe0001fU; -+ TargetValue &= 0xffe0001fU; - // Immediate goes in bits 20:5 of MOVZ/MOVK instruction -- *TargetPtr |= ((Result & 0xffff00000000ULL) >> (32 - 5)); -+ TargetValue |= ((Result & 0xffff00000000ULL) >> (32 - 5)); - // Shift must be "lsl #32", in bits 22:21 -- assert((*TargetPtr >> 21 & 0x3) == 2 && "invalid shift for relocation"); -+ assert((TargetValue >> 21 & 0x3) == 2 && "invalid shift for relocation"); -+ support::ulittle32_t::ref{TargetPtr} = TargetValue; - break; - } - case ELF::R_AARCH64_MOVW_UABS_G1_NC: { - uint64_t Result = Value + Addend; -+ uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr}; - - // AArch64 code is emitted with .rela relocations. The data already in any - // bits affected by the relocation on entry is garbage. -- *TargetPtr &= 0xffe0001fU; -+ TargetValue &= 0xffe0001fU; - // Immediate goes in bits 20:5 of MOVZ/MOVK instruction -- *TargetPtr |= ((Result & 0xffff0000U) >> (16 - 5)); -+ TargetValue |= ((Result & 0xffff0000U) >> (16 - 5)); - // Shift must be "lsl #16", in bits 22:2 -- assert((*TargetPtr >> 21 & 0x3) == 1 && "invalid shift for relocation"); -+ assert((TargetValue >> 21 & 0x3) == 1 && "invalid shift for relocation"); -+ support::ulittle32_t::ref{TargetPtr} = TargetValue; - break; - } - case ELF::R_AARCH64_MOVW_UABS_G0_NC: { - uint64_t Result = Value + Addend; -+ uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr}; - - // AArch64 code is emitted with .rela relocations. The data already in any - // bits affected by the relocation on entry is garbage. -- *TargetPtr &= 0xffe0001fU; -+ TargetValue &= 0xffe0001fU; - // Immediate goes in bits 20:5 of MOVZ/MOVK instruction -- *TargetPtr |= ((Result & 0xffffU) << 5); -+ TargetValue |= ((Result & 0xffffU) << 5); - // Shift must be "lsl #0", in bits 22:21. -- assert((*TargetPtr >> 21 & 0x3) == 0 && "invalid shift for relocation"); -+ assert((TargetValue >> 21 & 0x3) == 0 && "invalid shift for relocation"); -+ support::ulittle32_t::ref{TargetPtr} = TargetValue; - break; - } - case ELF::R_AARCH64_ADR_PREL_PG_HI21: { - // Operation: Page(S+A) - Page(P) - uint64_t Result = - ((Value + Addend) & ~0xfffULL) - (FinalAddress & ~0xfffULL); -+ uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr}; - - // Check that -2^32 <= X < 2^32 - assert(isInt<33>(Result) && "overflow check failed for relocation"); - - // AArch64 code is emitted with .rela relocations. The data already in any - // bits affected by the relocation on entry is garbage. -- *TargetPtr &= 0x9f00001fU; -+ TargetValue &= 0x9f00001fU; - // Immediate goes in bits 30:29 + 5:23 of ADRP instruction, taken - // from bits 32:12 of X. -- *TargetPtr |= ((Result & 0x3000U) << (29 - 12)); -- *TargetPtr |= ((Result & 0x1ffffc000ULL) >> (14 - 5)); -+ TargetValue |= ((Result & 0x3000U) << (29 - 12)); -+ TargetValue |= ((Result & 0x1ffffc000ULL) >> (14 - 5)); -+ support::ulittle32_t::ref{TargetPtr} = TargetValue; - break; - } - case ELF::R_AARCH64_LDST32_ABS_LO12_NC: { - // Operation: S + A - uint64_t Result = Value + Addend; -+ uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr}; - - // AArch64 code is emitted with .rela relocations. The data already in any - // bits affected by the relocation on entry is garbage. -- *TargetPtr &= 0xffc003ffU; -+ TargetValue &= 0xffc003ffU; - // Immediate goes in bits 21:10 of LD/ST instruction, taken - // from bits 11:2 of X -- *TargetPtr |= ((Result & 0xffc) << (10 - 2)); -+ TargetValue |= ((Result & 0xffc) << (10 - 2)); -+ support::ulittle32_t::ref{TargetPtr} = TargetValue; - break; - } - case ELF::R_AARCH64_LDST64_ABS_LO12_NC: { - // Operation: S + A - uint64_t Result = Value + Addend; -+ uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr}; - - // AArch64 code is emitted with .rela relocations. The data already in any - // bits affected by the relocation on entry is garbage. -- *TargetPtr &= 0xffc003ffU; -+ TargetValue &= 0xffc003ffU; - // Immediate goes in bits 21:10 of LD/ST instruction, taken - // from bits 11:3 of X -- *TargetPtr |= ((Result & 0xff8) << (10 - 3)); -+ TargetValue |= ((Result & 0xff8) << (10 - 3)); -+ support::ulittle32_t::ref{TargetPtr} = TargetValue; - break; - } - } -diff --git a/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_BE-relocations.s b/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_BE-relocations.s -new file mode 100644 -index 0000000..01d01e5 ---- /dev/null -+++ b/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_BE-relocations.s -@@ -0,0 +1,102 @@ -+# RUN: llvm-mc -triple=aarch64_be-none-linux-gnu -filetype=obj -o %T/be-reloc.o %s -+# RUN: llvm-rtdyld -triple=aarch64_be-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/be-reloc.o -+ -+ .text -+ .globl g -+ .p2align 2 -+ .type g,@function -+g: -+# R_AARCH64_MOVW_UABS_G3 -+ movz x0, #:abs_g3:f -+# R_AARCH64_MOVW_UABS_G2_NC -+ movk x0, #:abs_g2_nc:f -+# R_AARCH64_MOVW_UABS_G1_NC -+ movk x0, #:abs_g1_nc:f -+# R_AARCH64_MOVW_UABS_G0_NC -+ movk x0, #:abs_g0_nc:f -+ ret -+ .Lfunc_end0: -+ .size g, .Lfunc_end0-g -+ -+ .type k,@object -+ .data -+ .globl k -+ .p2align 3 -+k: -+ .xword f -+ .size k, 8 -+ -+# LE instructions read as BE -+# rtdyld-check: *{4}(g) = 0x6024e0d2 -+# rtdyld-check: *{4}(g + 4) = 0xe0acc8f2 -+# rtdyld-check: *{4}(g + 8) = 0x6035b1f2 -+# rtdyld-check: *{4}(g + 12) = 0xe0bd99f2 -+# rtdyld-check: *{8}k = f -+# RUN: llvm-mc -triple=aarch64_be-none-linux-gnu -filetype=obj -o %T/be-reloc.o %s -+# RUN: llvm-rtdyld -triple=aarch64_be-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/be-reloc.o -+ -+ .text -+ .globl g -+ .p2align 2 -+ .type g,@function -+g: -+# R_AARCH64_MOVW_UABS_G3 -+ movz x0, #:abs_g3:f -+# R_AARCH64_MOVW_UABS_G2_NC -+ movk x0, #:abs_g2_nc:f -+# R_AARCH64_MOVW_UABS_G1_NC -+ movk x0, #:abs_g1_nc:f -+# R_AARCH64_MOVW_UABS_G0_NC -+ movk x0, #:abs_g0_nc:f -+ ret -+ .Lfunc_end0: -+ .size g, .Lfunc_end0-g -+ -+ .type k,@object -+ .data -+ .globl k -+ .p2align 3 -+k: -+ .xword f -+ .size k, 8 -+ -+# LE instructions read as BE -+# rtdyld-check: *{4}(g) = 0x6024e0d2 -+# rtdyld-check: *{4}(g + 4) = 0xe0acc8f2 -+# rtdyld-check: *{4}(g + 8) = 0x6035b1f2 -+# rtdyld-check: *{4}(g + 12) = 0xe0bd99f2 -+# rtdyld-check: *{8}k = f -+# RUN: llvm-mc -triple=aarch64_be-none-linux-gnu -filetype=obj -o %T/be-reloc.o %s -+# RUN: llvm-rtdyld -triple=aarch64_be-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/be-reloc.o -+ -+ .text -+ .globl g -+ .p2align 2 -+ .type g,@function -+g: -+# R_AARCH64_MOVW_UABS_G3 -+ movz x0, #:abs_g3:f -+# R_AARCH64_MOVW_UABS_G2_NC -+ movk x0, #:abs_g2_nc:f -+# R_AARCH64_MOVW_UABS_G1_NC -+ movk x0, #:abs_g1_nc:f -+# R_AARCH64_MOVW_UABS_G0_NC -+ movk x0, #:abs_g0_nc:f -+ ret -+ .Lfunc_end0: -+ .size g, .Lfunc_end0-g -+ -+ .type k,@object -+ .data -+ .globl k -+ .p2align 3 -+k: -+ .xword f -+ .size k, 8 -+ -+# LE instructions read as BE -+# rtdyld-check: *{4}(g) = 0x6024e0d2 -+# rtdyld-check: *{4}(g + 4) = 0xe0acc8f2 -+# rtdyld-check: *{4}(g + 8) = 0x6035b1f2 -+# rtdyld-check: *{4}(g + 12) = 0xe0bd99f2 -+# rtdyld-check: *{8}k = f -diff --git a/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_relocations.s b/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_relocations.s -new file mode 100644 -index 0000000..e07fa97 ---- /dev/null -+++ b/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_relocations.s -@@ -0,0 +1,99 @@ -+# RUN: llvm-mc -triple=arm64-none-linux-gnu -filetype=obj -o %T/reloc.o %s -+# RUN: llvm-rtdyld -triple=arm64-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/reloc.o -+ -+ .text -+ .globl g -+ .p2align 2 -+ .type g,@function -+g: -+# R_AARCH64_MOVW_UABS_G3 -+ movz x0, #:abs_g3:f -+# R_AARCH64_MOVW_UABS_G2_NC -+ movk x0, #:abs_g2_nc:f -+# R_AARCH64_MOVW_UABS_G1_NC -+ movk x0, #:abs_g1_nc:f -+# R_AARCH64_MOVW_UABS_G0_NC -+ movk x0, #:abs_g0_nc:f -+ ret -+ .Lfunc_end0: -+ .size g, .Lfunc_end0-g -+ -+ .type k,@object -+ .data -+ .globl k -+ .p2align 3 -+k: -+ .xword f -+ .size k, 8 -+ -+# rtdyld-check: *{4}(g) = 0xd2e02460 -+# rtdyld-check: *{4}(g + 4) = 0xf2c8ace0 -+# rtdyld-check: *{4}(g + 8) = 0xf2b13560 -+# rtdyld-check: *{4}(g + 12) = 0xf299bde0 -+# rtdyld-check: *{8}k = f -+# RUN: llvm-mc -triple=arm64-none-linux-gnu -filetype=obj -o %T/reloc.o %s -+# RUN: llvm-rtdyld -triple=arm64-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/reloc.o -+ -+ .text -+ .globl g -+ .p2align 2 -+ .type g,@function -+g: -+# R_AARCH64_MOVW_UABS_G3 -+ movz x0, #:abs_g3:f -+# R_AARCH64_MOVW_UABS_G2_NC -+ movk x0, #:abs_g2_nc:f -+# R_AARCH64_MOVW_UABS_G1_NC -+ movk x0, #:abs_g1_nc:f -+# R_AARCH64_MOVW_UABS_G0_NC -+ movk x0, #:abs_g0_nc:f -+ ret -+ .Lfunc_end0: -+ .size g, .Lfunc_end0-g -+ -+ .type k,@object -+ .data -+ .globl k -+ .p2align 3 -+k: -+ .xword f -+ .size k, 8 -+ -+# rtdyld-check: *{4}(g) = 0xd2e02460 -+# rtdyld-check: *{4}(g + 4) = 0xf2c8ace0 -+# rtdyld-check: *{4}(g + 8) = 0xf2b13560 -+# rtdyld-check: *{4}(g + 12) = 0xf299bde0 -+# rtdyld-check: *{8}k = f -+# RUN: llvm-mc -triple=arm64-none-linux-gnu -filetype=obj -o %T/reloc.o %s -+# RUN: llvm-rtdyld -triple=arm64-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/reloc.o -+ -+ .text -+ .globl g -+ .p2align 2 -+ .type g,@function -+g: -+# R_AARCH64_MOVW_UABS_G3 -+ movz x0, #:abs_g3:f -+# R_AARCH64_MOVW_UABS_G2_NC -+ movk x0, #:abs_g2_nc:f -+# R_AARCH64_MOVW_UABS_G1_NC -+ movk x0, #:abs_g1_nc:f -+# R_AARCH64_MOVW_UABS_G0_NC -+ movk x0, #:abs_g0_nc:f -+ ret -+ .Lfunc_end0: -+ .size g, .Lfunc_end0-g -+ -+ .type k,@object -+ .data -+ .globl k -+ .p2align 3 -+k: -+ .xword f -+ .size k, 8 -+ -+# rtdyld-check: *{4}(g) = 0xd2e02460 -+# rtdyld-check: *{4}(g + 4) = 0xf2c8ace0 -+# rtdyld-check: *{4}(g + 8) = 0xf2b13560 -+# rtdyld-check: *{4}(g + 12) = 0xf299bde0 -+# rtdyld-check: *{8}k = f --- -2.12.0 - diff --git a/0001-PPC64LE-ELFv2-ABI-updates-for-the-.opd-section.patch b/0001-PPC64LE-ELFv2-ABI-updates-for-the-.opd-section.patch deleted file mode 100644 index 27a025a..0000000 --- a/0001-PPC64LE-ELFv2-ABI-updates-for-the-.opd-section.patch +++ /dev/null @@ -1,53 +0,0 @@ -From 04c252cc93fe5905a625773cd174ed6ca7651463 Mon Sep 17 00:00:00 2001 -From: Will Schmidt -Date: Mon, 24 Mar 2014 16:04:15 +0000 -Subject: [PATCH] [PPC64LE] ELFv2 ABI updates for the .opd section - -[PPC64LE] ELFv2 ABI updates for the .opd section -The PPC64 Little Endian (PPC64LE) target supports the ELFv2 ABI, and as -such, does not have a ".opd" section. This is keyed off a _CALL_ELF=2 -macro check. - -The CALL_ELF check is not clearly documented at this time. The basis -for usage in this patch is from the gcc thread here: -http://gcc.gnu.org/ml/gcc-patches/2013-11/msg01144.html - -> Adding comment from Uli: -Looks good to me. I think the old-style JIT doesn't really work -anyway for 64-bit, but at least with this patch LLVM will compile -and link again on a ppc64le host ... - - - - -git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204614 91177308-0d34-0410-b5e6-96231b3b80d8 ---- - lib/Target/PowerPC/PPCJITInfo.cpp | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/lib/Target/PowerPC/PPCJITInfo.cpp b/lib/Target/PowerPC/PPCJITInfo.cpp -index 5e3a48d..227919c 100644 ---- a/lib/Target/PowerPC/PPCJITInfo.cpp -+++ b/lib/Target/PowerPC/PPCJITInfo.cpp -@@ -214,6 +214,10 @@ asm( - ".text\n" - ".align 2\n" - ".globl PPC64CompilationCallback\n" -+#if _CALL_ELF == 2 -+ ".type PPC64CompilationCallback,@function\n" -+"PPC64CompilationCallback:\n" -+#else - ".section \".opd\",\"aw\",@progbits\n" - ".align 3\n" - "PPC64CompilationCallback:\n" -@@ -223,6 +227,7 @@ asm( - ".align 4\n" - ".type PPC64CompilationCallback,@function\n" - ".L.PPC64CompilationCallback:\n" -+#endif - # else - asm( - ".text\n" --- -1.9.3 - diff --git a/0001-Revert-Merging-r280589.patch b/0001-Revert-Merging-r280589.patch deleted file mode 100644 index ef950f4..0000000 --- a/0001-Revert-Merging-r280589.patch +++ /dev/null @@ -1,119 +0,0 @@ -From 95b15b3d2f180b15267032e16c947c0f9b8a112d Mon Sep 17 00:00:00 2001 -From: Dave Airlie -Date: Wed, 1 Mar 2017 13:02:38 +1000 -Subject: [PATCH] Revert "Merging r280589:" - -This reverts commit 25e2616626caafb896517e18cd8aa724fba2b200. ---- - lib/Target/AMDGPU/SIInstructions.td | 1 - - lib/Target/AMDGPU/SIWholeQuadMode.cpp | 7 +++++ - test/CodeGen/AMDGPU/wqm.ll | 49 +++-------------------------------- - 3 files changed, 11 insertions(+), 46 deletions(-) - -diff --git a/lib/Target/AMDGPU/SIInstructions.td b/lib/Target/AMDGPU/SIInstructions.td -index dde5f2f..18b7d5d 100644 ---- a/lib/Target/AMDGPU/SIInstructions.td -+++ b/lib/Target/AMDGPU/SIInstructions.td -@@ -2029,7 +2029,6 @@ 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 1534d58..b200c15 100644 ---- a/lib/Target/AMDGPU/SIWholeQuadMode.cpp -+++ b/lib/Target/AMDGPU/SIWholeQuadMode.cpp -@@ -219,6 +219,13 @@ 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 41e4264..809a7ba 100644 ---- a/test/CodeGen/AMDGPU/wqm.ll -+++ b/test/CodeGen/AMDGPU/wqm.ll -@@ -17,18 +17,17 @@ main_body: - ;CHECK-LABEL: {{^}}test2: - ;CHECK-NEXT: ; %main_body - ;CHECK-NEXT: s_wqm_b64 exec, exec -+;CHECK: image_sample - ;CHECK-NOT: exec --define amdgpu_ps void @test2(<8 x i32> inreg %rsrc, <4 x i32> inreg %sampler, float addrspace(1)* inreg %ptr, <4 x i32> %c) { -+;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) { - 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 -- -- 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 -+ ret float %data - } - - ; ... but disabled for stores (and, in this simple case, not re-enabled). -@@ -415,46 +414,6 @@ 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 --- -2.9.3 - diff --git a/0001-This-code-block-breaks-the-docs-build-http-lab.llvm..patch b/0001-This-code-block-breaks-the-docs-build-http-lab.llvm..patch deleted file mode 100644 index 9d43070..0000000 --- a/0001-This-code-block-breaks-the-docs-build-http-lab.llvm..patch +++ /dev/null @@ -1,30 +0,0 @@ -From ce04fe5f8eb9f3a27504db75672083c8aaf80ddd Mon Sep 17 00:00:00 2001 -From: Aaron Ballman -Date: Tue, 19 Jul 2016 17:46:55 +0000 -Subject: [PATCH] This code block breaks the docs build - (http://lab.llvm.org:8011/builders/llvm-sphinx-docs/builds/11920/steps/docs-llvm-html/logs/stdio), - but I cannot see anything immediately wrong with it and cannot reproduce the - diagnostic locally. Setting the code highlighting to none instead of nasm to - hopefully get the bot stumbling back towards green. - -git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275998 91177308-0d34-0410-b5e6-96231b3b80d8 ---- - docs/AMDGPUUsage.rst | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/docs/AMDGPUUsage.rst b/docs/AMDGPUUsage.rst -index 34a9b60..7d1ef11 100644 ---- a/docs/AMDGPUUsage.rst -+++ b/docs/AMDGPUUsage.rst -@@ -171,7 +171,7 @@ keys, see the comments in lib/Target/AMDGPU/AmdKernelCodeT.h - - Here is an example of a minimal amd_kernel_code_t specification: - --.. code-block:: nasm -+.. code-block:: none - - .hsa_code_object_version 1,0 - .hsa_code_object_isa --- -2.5.5 - diff --git a/0001-add-gcc-abi_tag-support.patch b/0001-add-gcc-abi_tag-support.patch deleted file mode 100644 index 89301f9..0000000 --- a/0001-add-gcc-abi_tag-support.patch +++ /dev/null @@ -1,1232 +0,0 @@ -From d7c20ff3406ee048dd5d0ff812f9e8b3d48bb192 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Stefan=20B=C3=BChler?= -Date: Thu, 3 Dec 2015 14:51:50 +0100 -Subject: [PATCH 1/3] add gcc abi_tag support - - ---- - docs/ItaniumMangleAbiTags.rst | 90 +++++ - include/clang/Basic/Attr.td | 8 + - include/clang/Basic/DiagnosticSemaKinds.td | 10 +- - include/clang/Sema/AttributeList.h | 3 +- - lib/AST/ItaniumMangle.cpp | 525 ++++++++++++++++++++++++----- - lib/Sema/SemaDeclAttr.cpp | 55 +++ - 6 files changed, 609 insertions(+), 82 deletions(-) - create mode 100644 docs/ItaniumMangleAbiTags.rst - -diff --git a/docs/ItaniumMangleAbiTags.rst b/docs/ItaniumMangleAbiTags.rst -new file mode 100644 -index 0000000..d390162 ---- /dev/null -+++ b/tools/clang/docs/ItaniumMangleAbiTags.rst -@@ -0,0 +1,90 @@ -+======== -+Abi Tags -+======== -+ -+Introduction -+============ -+ -+This text tries to describe gcc semantic for mangling "abi_tag" attributes -+described in https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html -+ -+There is no guarantee the following rules are correct, complete or make sense -+in any way as they were determined empirically by experiments with gcc5. -+ -+Declaration -+=========== -+ -+Abi tags are declared in an abi_tag attribute and can be applied to a -+function, variable, class or inline namespace declaration. The attribute takes -+one or more strings (called tags); the order does not matter. -+ -+See https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html for -+details. -+ -+Tags on an inline namespace are called "implicit tags", all other tags are -+"explicit tags". -+ -+Mangling -+======== -+ -+All tags that are "active" on a are emitted after the -+, before or , and are part of -+the same the is. -+ -+They are mangled as: -+ -+ ::= * # sort by name -+ ::= B -+ -+Example: -+ -+ __attribute__((abi_tag("test"))) -+ void Func(); -+ -+ gets mangled as: _Z4FuncB4testv (prettified as `Func[abi:test]()`) -+ -+Active tags -+=========== -+ -+A namespace has never any active tags; for types (class / struct / union / -+enum) the explicit tags are the active tags. -+ -+For variables and functions the active tags are the explicit tags plus any -+"required tags" which are not in the "available tags" set: -+ -+ derived-tags := (required-tags - available-tags) -+ active-tags := explicit-tags + derived-tags -+ -+Required tags for a function -+============================ -+ -+If a function is used as a local scope for another name, and is part of -+another function as local scope, it doesn't have any required tags. -+ -+If a function is used as a local scope for a guard variable name, it doesn't -+have any required tags. -+ -+Otherwise the function requires any implicit or explicit tag used in the name -+for the return type. -+ -+Required tags for a variable -+============================ -+ -+A variable requires any implicit or explicit tag used in its type. -+ -+Available tags -+============== -+ -+All tags used in the prefix and in the template arguments for a name are -+available; for functions also all tags from the (which -+might include the return type for template functions) are available. -+ -+For s all active tags used in the local part () are available, but not implicit tags which were not active! -+ -+Implicit and explicit tags used in the for a function (as -+in the type of a cast operator) are NOT available. -+ -+Example: a cast operator to std::string (which is -+std::__cxx11::basic_string<...>) will use 'cxx11' as active tag, as it is -+required from the return type `std::string` but not available. -diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td -index 6187bcb..c54ab34 100644 ---- a/tools/clang/include/clang/Basic/Attr.td -+++ b/tools/clang/include/clang/Basic/Attr.td -@@ -338,6 +338,14 @@ class IgnoredAttr : Attr { - // Attributes begin here - // - -+def AbiTag : Attr { -+ let Spellings = [GCC<"abi_tag">]; -+ let Args = [VariadicStringArgument<"Tags">]; -+ let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag, -+ "ExpectedStructClassVariableFunctionMethodOrInlineNamespace">; -+ let Documentation = [Undocumented]; -+} -+ - def AddressSpace : TypeAttr { - let Spellings = [GNU<"address_space">]; - let Args = [IntArgument<"AddressSpace">]; -diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td -index 82f5121..973456e 100644 ---- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td -+++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td -@@ -2323,7 +2323,8 @@ def warn_attribute_wrong_decl_type : Warning< - "Objective-C instance methods|init methods of interface or class extension declarations|" - "variables, functions and classes|Objective-C protocols|" - "functions and global variables|structs, unions, and typedefs|structs and typedefs|" -- "interface or protocol declarations|kernel functions}1">, -+ "interface or protocol declarations|kernel functions|" -+ "structs, classes, variables, functions, methods and inline namespaces}1">, - InGroup; - def err_attribute_wrong_decl_type : Error; - def warn_type_attribute_wrong_type : Warning< -@@ -3997,6 +3998,13 @@ def err_definition_of_explicitly_defaulted_member : Error< - def err_redefinition_extern_inline : Error< - "redefinition of a 'extern inline' function %0 is not supported in " - "%select{C99 mode|C++}1">; -+def err_attr_abi_tag_only_on_inline_namespace : -+ Error<"abi_tag attribute only allowed on inline namespaces">; -+def err_abi_tag_on_redeclaration : -+ Error<"cannot add abi_tag attribute in redeclaration">; -+def err_new_abi_tag_on_redeclaration : -+ Error<"abi_tag %0 missing in original declaration">; -+ - - def note_deleted_dtor_no_operator_delete : Note< - "virtual destructor requires an unambiguous, accessible 'operator delete'">; -diff --git a/include/clang/Sema/AttributeList.h b/include/clang/Sema/AttributeList.h -index 4d18633..b3a9333 100644 ---- a/tools/clang/include/clang/Sema/AttributeList.h -+++ b/tools/clang/include/clang/Sema/AttributeList.h -@@ -854,7 +854,8 @@ enum AttributeDeclKind { - ExpectedStructOrUnionOrTypedef, - ExpectedStructOrTypedef, - ExpectedObjectiveCInterfaceOrProtocol, -- ExpectedKernelFunction -+ ExpectedKernelFunction, -+ ExpectedStructClassVariableFunctionMethodOrInlineNamespace - }; - - } // end namespace clang -diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp -index dac803e..e32b659 100644 ---- a/tools/clang/lib/AST/ItaniumMangle.cpp -+++ b/tools/clang/lib/AST/ItaniumMangle.cpp -@@ -214,6 +214,8 @@ public: - class CXXNameMangler { - ItaniumMangleContextImpl &Context; - raw_ostream &Out; -+ bool NullOut = false; -+ bool DisableDerivedAbiTags = false; - - /// The "structor" is the top-level declaration being mangled, if - /// that's not a template specialization; otherwise it's the pattern -@@ -263,6 +265,167 @@ class CXXNameMangler { - - } FunctionTypeDepth; - -+ // abi_tag is a gcc attribute, taking one or more strings called "tags". -+ // -+ // the goal is to annotage against which version of a library an object was -+ // build and to be able to provide backwards compatibility ("dual abi"). -+ // -+ // for this the emitted mangled names have to be different, while you don't -+ // want the user to have to use different names in the source. -+ // -+ // the abi_tag can be present on Struct, Var and Function declarations as -+ // "explicit" tag, and on inline Namespace as "implicit" tag. Explicit tags -+ // are always emitted after the unqualified name, and (implicit) tags on -+ // namespace are not. -+ // -+ // For functions and variables there is a set of "implicitly available" -+ // tags. These tags are: all tags from the namespace/structs the name is -+ // embedded in, all tags from any template arguments of the name, and, for -+ // functions, alls tags used anywhere in the (i.e. -+ // parameters and sometimes the return type). -+ // -+ // For functions this is basically the list of all tags from the signature -+ // without the unqualified name and usually without the return type of the -+ // function. In `operator Type()` Type is NOT part of that list, as it is -+ // part of the unqualified name! -+ // -+ // Now all tags from the function return type/variable type which are not -+ // "implicitly available" must be added to the explicit list of tags, and -+ // are emitted after the unqualified name. -+ // -+ // Example: -+ // namespace std { -+ // inline namespace __cxx11 __attribute__((__abi_tag__("cxx11"))) { } -+ // inline namespace __cxx11 { -+ // struct string { }; -+ // } -+ // } -+ // -+ // std::string foo(); // needs abi tag "cxx11" on foo -+ // std::string foo(std::string); // does NOT need abi tag "cxx11" on foo -+ // __attribute__((__abi_tag__("cxx11"))) -+ // std::string foo2(std::string); // emit abi tag "cxx11" on foo anyway -+ // -+ // The tags are sorted by name before emitting, and are serialized as -+ // ::= B <"tag" source-name> -+ -+ typedef SmallVector AbiTagList; -+ -+ // state to gather all implicit and explicit tags used in a mangled name. -+ // must always have an instance of this while emitting any name to keep -+ // track. -+ // -+ // TODO(abitags): how to handle substituted names? they should add the tags used in -+ // the substitution to the list of available tags. -+ class AbiTagState final { -+ public: -+ //! all abi tags used implicitly or explicitly -+ std::set UsedAbiTags; -+ //! all explicit abi tags (i.e. not from namespace) -+ std::set EmittedAbiTags; -+ -+ AbiTagState* &LinkHead; -+ AbiTagState *Parent{nullptr}; -+ -+ bool LinkActive{false}; -+ -+ explicit AbiTagState(AbiTagState* &linkHead) -+ : LinkHead(linkHead) { -+ Parent = LinkHead; -+ LinkHead = this; -+ LinkActive = true; -+ } -+ -+ // no copy, no move -+ AbiTagState(AbiTagState const&) = delete; -+ AbiTagState& operator=(AbiTagState const&) = delete; -+ -+ ~AbiTagState() { -+ pop(); -+ } -+ -+ void pop() { -+ if (!LinkActive) return; -+ -+ assert(LinkHead == this && "abi tag link head must point to us on destruction"); -+ LinkActive = false; -+ if (Parent) { -+ Parent->UsedAbiTags.insert(UsedAbiTags.begin(), UsedAbiTags.end()); -+ Parent->EmittedAbiTags.insert(EmittedAbiTags.begin(), EmittedAbiTags.end()); -+ } -+ LinkHead = Parent; -+ } -+ -+ void write(raw_ostream &Out, const NamedDecl *ND, const AbiTagList *AdditionalAbiTags) { -+ ND = cast(ND->getCanonicalDecl()); -+ -+ if (dyn_cast(ND) || dyn_cast(ND)) { -+ // assert(AdditionalAbiTags && "function and variables need a list of additional abi tags"); -+ } else { -+ assert(!AdditionalAbiTags && "only function and variables need a list of additional abi tags"); -+ if (const auto* NS = dyn_cast(ND)) { -+ if (const auto* AbiTag = NS->getAttr()) { -+ for (const auto& Tag: AbiTag->tags()) { -+ UsedAbiTags.insert(Tag); -+ } -+ } -+ // don't emit abi tags for namespaces -+ return; -+ } -+ } -+ -+ AbiTagList TagList; -+ if (const auto* AbiTag = ND->getAttr()) { -+ for (const auto& Tag: AbiTag->tags()) { -+ UsedAbiTags.insert(Tag); -+ // AbiTag->tags() is sorted and has no duplicates -+ TagList.push_back(Tag); -+ } -+ } -+ -+ if (AdditionalAbiTags) { -+ for (const auto& Tag: *AdditionalAbiTags) { -+ UsedAbiTags.insert(Tag); -+ if (std::find(TagList.begin(), TagList.end(), Tag) == TagList.end()) { -+ // don't insert duplicates -+ TagList.push_back(Tag); -+ } -+ } -+ // AbiTag->tags() are already sorted; only add if we had additional tags -+ std::sort(TagList.begin(), TagList.end()); -+ } -+ -+ writeSortedUniqueAbiTags(Out, TagList); -+ } -+ -+ protected: -+ template -+ void writeSortedUniqueAbiTags(raw_ostream &Out, TagList const& AbiTags) { -+ for (const auto& Tag: AbiTags) { -+ EmittedAbiTags.insert(Tag); -+ Out << "B"; -+ Out << Tag.size(); -+ Out << Tag; -+ } -+ } -+ } *AbiTags = nullptr; -+ AbiTagState AbiTagsRoot{AbiTags}; -+ -+ struct TemporaryDisableDerivedAbiTags { -+ bool& StateRef; -+ bool OldState; -+ -+ TemporaryDisableDerivedAbiTags(bool& State, bool Disable = true) -+ : StateRef(State) { -+ OldState = StateRef; -+ StateRef = Disable; -+ } -+ TemporaryDisableDerivedAbiTags(TemporaryDisableDerivedAbiTags const&) = delete; -+ ~TemporaryDisableDerivedAbiTags() { -+ StateRef = OldState; -+ } -+ }; -+ - llvm::DenseMap Substitutions; - - ASTContext &getASTContext() const { return Context.getASTContext(); } -@@ -285,6 +448,10 @@ public: - : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), - SeqID(0) { } - -+ CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_) -+ : Context(Outer.Context), Out(Out_), NullOut(true), Structor(Outer.Structor), StructorType(Outer.StructorType), -+ SeqID(Outer.SeqID) { } -+ - #if MANGLE_CHECKER - ~CXXNameMangler() { - if (Out.str()[0] == '\01') -@@ -298,18 +465,21 @@ public: - #endif - raw_ostream &getStream() { return Out; } - -+ void disableDerivedAbiTags() { DisableDerivedAbiTags = true; } -+ - void mangle(const NamedDecl *D); - void mangleCallOffset(int64_t NonVirtual, int64_t Virtual); - void mangleNumber(const llvm::APSInt &I); - void mangleNumber(int64_t Number); - void mangleFloat(const llvm::APFloat &F); -- void mangleFunctionEncoding(const FunctionDecl *FD); -+ void mangleFunctionEncoding(const FunctionDecl *FD, bool ExcludeUnqualifiedName = false); - void mangleSeqID(unsigned SeqID); -- void mangleName(const NamedDecl *ND); -+ void mangleName(const NamedDecl *ND, bool ExcludeUnqualifiedName = false); - void mangleType(QualType T); - void mangleNameOrStandardSubstitution(const NamedDecl *ND); - - private: -+ void writeAbiTags(const NamedDecl *ND, const AbiTagList *AdditionalAbiTags = nullptr); - - bool mangleSubstitution(const NamedDecl *ND); - bool mangleSubstitution(QualType T); -@@ -336,31 +506,49 @@ private: - DeclarationName name, - unsigned KnownArity = UnknownArity); - -- void mangleName(const TemplateDecl *TD, -+ void mangleFunctionEncodingBareType(const FunctionDecl *FD); -+ -+ void mangleNameWithAbiTags(const NamedDecl *ND, -+ const AbiTagList *AdditionalAbiTags, -+ bool ExcludeUnqualifiedName); -+ void mangleTemplateName(const TemplateDecl *TD, -+ const AbiTagList *AdditionalAbiTags, -+ bool ExcludeUnqualifiedName, - const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs); -- void mangleUnqualifiedName(const NamedDecl *ND) { -- mangleUnqualifiedName(ND, ND->getDeclName(), UnknownArity); -+ void mangleUnqualifiedName(const NamedDecl *ND, const AbiTagList *AdditionalAbiTags) { -+ mangleUnqualifiedName(ND, ND->getDeclName(), UnknownArity, AdditionalAbiTags); - } - void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name, -- unsigned KnownArity); -- void mangleUnscopedName(const NamedDecl *ND); -- void mangleUnscopedTemplateName(const TemplateDecl *ND); -- void mangleUnscopedTemplateName(TemplateName); -+ unsigned KnownArity, const AbiTagList *AdditionalAbiTags); -+ void mangleUnscopedName(const NamedDecl *ND, const AbiTagList *AdditionalAbiTags); -+ void mangleUnscopedTemplateName(const TemplateDecl *ND, -+ const AbiTagList *AdditionalAbiTags); -+ void mangleUnscopedTemplateName(TemplateName, -+ const AbiTagList *AdditionalAbiTags); - void mangleSourceName(const IdentifierInfo *II); -- void mangleLocalName(const Decl *D); -+ void mangleLocalName(const Decl *D, -+ const AbiTagList *AdditionalAbiTags, -+ bool ExcludeUnqualifiedName); - void mangleBlockForPrefix(const BlockDecl *Block); - void mangleUnqualifiedBlock(const BlockDecl *Block); - void mangleLambda(const CXXRecordDecl *Lambda); - void mangleNestedName(const NamedDecl *ND, const DeclContext *DC, -- bool NoFunction=false); -+ const AbiTagList *AdditionalAbiTags, -+ bool NoFunction, -+ bool ExcludeUnqualifiedName); - void mangleNestedName(const TemplateDecl *TD, -+ const AbiTagList *AdditionalAbiTags, -+ bool ExcludeUnqualifiedName, - const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs); - void manglePrefix(NestedNameSpecifier *qualifier); - void manglePrefix(const DeclContext *DC, bool NoFunction=false); - void manglePrefix(QualType type); -- void mangleTemplatePrefix(const TemplateDecl *ND, bool NoFunction=false); -+ void mangleTemplatePrefix(const TemplateDecl *ND, -+ const AbiTagList *AdditionalAbiTags, -+ bool NoFunction = false, -+ bool ExcludeUnqualifiedName = false); - void mangleTemplatePrefix(TemplateName Template); - bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType, - StringRef Prefix = ""); -@@ -406,6 +594,10 @@ private: - void mangleTemplateParameter(unsigned Index); - - void mangleFunctionParam(const ParmVarDecl *parm); -+ -+ std::set getTagsFromPrefixAndTemplateArguments(const NamedDecl *ND); -+ AbiTagList makeAdditionalTagsForFunction(const FunctionDecl *FD); -+ AbiTagList makeAdditionalTagsForVariable(const VarDecl *VD); - }; - - } -@@ -456,6 +648,11 @@ bool ItaniumMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) { - return true; - } - -+void CXXNameMangler::writeAbiTags(const NamedDecl *ND, const AbiTagList *AdditionalAbiTags) { -+ assert(AbiTags && "require AbiTagState"); -+ if (AbiTags) AbiTags->write(Out, ND, DisableDerivedAbiTags ? nullptr : AdditionalAbiTags); -+} -+ - void CXXNameMangler::mangle(const NamedDecl *D) { - // ::= _Z - // ::= -@@ -471,14 +668,28 @@ void CXXNameMangler::mangle(const NamedDecl *D) { - mangleName(cast(D)); - } - --void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { -- // ::= -- mangleName(FD); -- -+void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD, bool ExcludeUnqualifiedName) { - // Don't mangle in the type if this isn't a decl we should typically mangle. -- if (!Context.shouldMangleDeclName(FD)) -+ if (!Context.shouldMangleDeclName(FD)) { -+ mangleNameWithAbiTags(FD, /* AdditionalAbiTags */ nullptr, ExcludeUnqualifiedName); - return; -+ } -+ -+ // ::= - -+ if (ExcludeUnqualifiedName) -+ { -+ // running makeAdditionalTagsForFunction would loop, don't need it here anyway -+ mangleNameWithAbiTags(FD, /* AdditionalAbiTags */ nullptr, ExcludeUnqualifiedName); -+ } else { -+ AbiTagList AdditionalAbiTags = makeAdditionalTagsForFunction(FD); -+ mangleNameWithAbiTags(FD, &AdditionalAbiTags, ExcludeUnqualifiedName); -+ } -+ -+ mangleFunctionEncodingBareType(FD); -+} -+ -+void CXXNameMangler::mangleFunctionEncodingBareType(const FunctionDecl *FD) { - if (FD->hasAttr()) { - FunctionTypeDepthState Saved = FunctionTypeDepth.push(); - Out << "Ua9enable_ifI"; -@@ -524,7 +735,7 @@ void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { - FD = PrimaryTemplate->getTemplatedDecl(); - } - -- mangleBareFunctionType(FD->getType()->getAs(), -+ mangleBareFunctionType(FD->getType()->getAs(), - MangleReturnType); - } - -@@ -582,7 +793,21 @@ isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) { - return nullptr; - } - --void CXXNameMangler::mangleName(const NamedDecl *ND) { -+// must not be run from mangleLocalName for the as it would loop otherwise. -+void CXXNameMangler::mangleName(const NamedDecl *ND, bool ExcludeUnqualifiedName) { -+ if (!ExcludeUnqualifiedName) { -+ if (const VarDecl *VD = dyn_cast(ND)) { -+ AbiTagList VariableAdditionalAbiTags = makeAdditionalTagsForVariable(VD); -+ mangleNameWithAbiTags(VD, &VariableAdditionalAbiTags, ExcludeUnqualifiedName); -+ return; -+ } -+ } -+ mangleNameWithAbiTags(ND, nullptr, ExcludeUnqualifiedName); -+} -+ -+void CXXNameMangler::mangleNameWithAbiTags(const NamedDecl *ND, -+ const AbiTagList *AdditionalAbiTags, -+ bool ExcludeUnqualifiedName) { - // ::= - // ::= - // ::= -@@ -598,7 +823,7 @@ void CXXNameMangler::mangleName(const NamedDecl *ND) { - while (!DC->isNamespace() && !DC->isTranslationUnit()) - DC = getEffectiveParentContext(DC); - else if (GetLocalClassDecl(ND)) { -- mangleLocalName(ND); -+ mangleLocalName(ND, AdditionalAbiTags, ExcludeUnqualifiedName); - return; - } - -@@ -608,76 +833,88 @@ void CXXNameMangler::mangleName(const NamedDecl *ND) { - // Check if we have a template. - const TemplateArgumentList *TemplateArgs = nullptr; - if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { -- mangleUnscopedTemplateName(TD); -+ if (!ExcludeUnqualifiedName) -+ mangleUnscopedTemplateName(TD, AdditionalAbiTags); - mangleTemplateArgs(*TemplateArgs); - return; - } - -- mangleUnscopedName(ND); -+ if (!ExcludeUnqualifiedName) -+ mangleUnscopedName(ND, AdditionalAbiTags); - return; - } - - if (isLocalContainerContext(DC)) { -- mangleLocalName(ND); -+ mangleLocalName(ND, AdditionalAbiTags, ExcludeUnqualifiedName); - return; - } - -- mangleNestedName(ND, DC); -+ mangleNestedName(ND, DC, AdditionalAbiTags, /* NoFunction */ false, ExcludeUnqualifiedName); - } --void CXXNameMangler::mangleName(const TemplateDecl *TD, -- const TemplateArgument *TemplateArgs, -- unsigned NumTemplateArgs) { -+ -+void CXXNameMangler::mangleTemplateName(const TemplateDecl *TD, -+ const AbiTagList *AdditionalAbiTags, -+ bool ExcludeUnqualifiedName, -+ const TemplateArgument *TemplateArgs, -+ unsigned NumTemplateArgs) { - const DeclContext *DC = IgnoreLinkageSpecDecls(getEffectiveDeclContext(TD)); - - if (DC->isTranslationUnit() || isStdNamespace(DC)) { -- mangleUnscopedTemplateName(TD); -+ if (!ExcludeUnqualifiedName) -+ mangleUnscopedTemplateName(TD, AdditionalAbiTags); - mangleTemplateArgs(TemplateArgs, NumTemplateArgs); - } else { -- mangleNestedName(TD, TemplateArgs, NumTemplateArgs); -+ mangleNestedName(TD, AdditionalAbiTags, ExcludeUnqualifiedName, TemplateArgs, NumTemplateArgs); - } - } - --void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) { -+void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND, const AbiTagList *AdditionalAbiTags) { - // ::= - // ::= St # ::std:: - - if (isStdNamespace(IgnoreLinkageSpecDecls(getEffectiveDeclContext(ND)))) - Out << "St"; - -- mangleUnqualifiedName(ND); -+ mangleUnqualifiedName(ND, AdditionalAbiTags); - } - --void CXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *ND) { -+void CXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *ND, -+ const AbiTagList *AdditionalAbiTags) { - // ::= - // ::= - if (mangleSubstitution(ND)) - return; - - // ::= -- if (const auto *TTP = dyn_cast(ND)) -+ if (const auto *TTP = dyn_cast(ND)) { -+ assert(!AdditionalAbiTags && "template template param cannot have abi tags"); // TODO(abitags) - mangleTemplateParameter(TTP->getIndex()); -- else -- mangleUnscopedName(ND->getTemplatedDecl()); -+ } else { -+ mangleUnscopedName(ND->getTemplatedDecl(), AdditionalAbiTags); -+ } - - addSubstitution(ND); - } - --void CXXNameMangler::mangleUnscopedTemplateName(TemplateName Template) { -+void CXXNameMangler::mangleUnscopedTemplateName(TemplateName Template, -+ const AbiTagList *AdditionalAbiTags) { - // ::= - // ::= - if (TemplateDecl *TD = Template.getAsTemplateDecl()) -- return mangleUnscopedTemplateName(TD); -+ return mangleUnscopedTemplateName(TD, AdditionalAbiTags); - - if (mangleSubstitution(Template)) - return; - -+ assert(!AdditionalAbiTags && "dependent template name cannot have abi tags"); // TODO(abitags) -+ - DependentTemplateName *Dependent = Template.getAsDependentTemplateName(); - assert(Dependent && "Not a dependent template name?"); - if (const IdentifierInfo *Id = Dependent->getIdentifier()) - mangleSourceName(Id); - else - mangleOperatorName(Dependent->getOperator(), UnknownArity); -- -+ - addSubstitution(Template); - } - -@@ -837,6 +1074,7 @@ void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier, - else - Out << "sr"; - mangleSourceName(qualifier->getAsNamespace()->getIdentifier()); -+ writeAbiTags(qualifier->getAsNamespace()); - break; - case NestedNameSpecifier::NamespaceAlias: - if (qualifier->getPrefix()) -@@ -845,6 +1083,7 @@ void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier, - else - Out << "sr"; - mangleSourceName(qualifier->getAsNamespaceAlias()->getIdentifier()); -+ writeAbiTags(qualifier->getAsNamespaceAlias()); - break; - - case NestedNameSpecifier::TypeSpec: -@@ -879,6 +1118,7 @@ void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier, - Out << "sr"; - - mangleSourceName(qualifier->getAsIdentifier()); -+ writeAbiTags(qualifier->getAsNamespaceAlias()); - break; - } - -@@ -924,7 +1164,8 @@ void CXXNameMangler::mangleUnresolvedName(NestedNameSpecifier *qualifier, - - void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, - DeclarationName Name, -- unsigned KnownArity) { -+ unsigned KnownArity, -+ const AbiTagList *AdditionalAbiTags) { - unsigned Arity = KnownArity; - // ::= - // ::= -@@ -943,6 +1184,7 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, - Out << 'L'; - - mangleSourceName(II); -+ writeAbiTags(ND, AdditionalAbiTags); - break; - } - -@@ -982,6 +1224,7 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, - assert(FD->getIdentifier() && "Data member name isn't an identifier!"); - - mangleSourceName(FD->getIdentifier()); -+ // TODO(abitags): not emitting abi tags: internal name anyway - break; - } - -@@ -1002,6 +1245,9 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, - assert(D->getDeclName().getAsIdentifierInfo() && - "Typedef was not named!"); - mangleSourceName(D->getDeclName().getAsIdentifierInfo()); -+ assert(!AdditionalAbiTags && "Type cannot have additional abi tags"); -+ // explicit abi tags are still possible; take from underlying type, not from typedef. -+ writeAbiTags(TD, nullptr); - break; - } - -@@ -1011,6 +1257,7 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, - // ::= + # Parameter types or 'v' for 'void'. - if (const CXXRecordDecl *Record = dyn_cast(TD)) { - if (Record->isLambda() && Record->getLambdaManglingNumber()) { -+ assert(!AdditionalAbiTags && "Lambda type cannot have additional abi tags"); - mangleLambda(Record); - break; - } -@@ -1022,6 +1269,7 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, - if (UnnamedMangle > 1) - Out << llvm::utostr(UnnamedMangle - 2); - Out << '_'; -+ writeAbiTags(TD, AdditionalAbiTags); - break; - } - -@@ -1054,6 +1302,7 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, - // Otherwise, use the complete constructor name. This is relevant if a - // class with a constructor is declared within a constructor. - mangleCXXCtorType(Ctor_Complete); -+ writeAbiTags(ND, AdditionalAbiTags); - break; - - case DeclarationName::CXXDestructorName: -@@ -1065,6 +1314,7 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, - // Otherwise, use the complete destructor name. This is relevant if a - // class with a destructor is declared within a destructor. - mangleCXXDtorType(Dtor_Complete); -+ writeAbiTags(ND, AdditionalAbiTags); - break; - - case DeclarationName::CXXOperatorName: -@@ -1080,6 +1330,7 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, - case DeclarationName::CXXConversionFunctionName: - case DeclarationName::CXXLiteralOperatorName: - mangleOperatorName(Name, Arity); -+ writeAbiTags(ND, AdditionalAbiTags); - break; - - case DeclarationName::CXXUsingDirective: -@@ -1096,7 +1347,9 @@ void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) { - - void CXXNameMangler::mangleNestedName(const NamedDecl *ND, - const DeclContext *DC, -- bool NoFunction) { -+ const AbiTagList *AdditionalAbiTags, -+ bool NoFunction, -+ bool ExcludeUnqualifiedName) { - // - // ::= N [] [] E - // ::= N [] [] -@@ -1116,30 +1369,35 @@ void CXXNameMangler::mangleNestedName(const NamedDecl *ND, - // Check if we have a template. - const TemplateArgumentList *TemplateArgs = nullptr; - if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { -- mangleTemplatePrefix(TD, NoFunction); -+ mangleTemplatePrefix(TD, AdditionalAbiTags, NoFunction, ExcludeUnqualifiedName); - mangleTemplateArgs(*TemplateArgs); - } - else { - manglePrefix(DC, NoFunction); -- mangleUnqualifiedName(ND); -+ if (!ExcludeUnqualifiedName) -+ mangleUnqualifiedName(ND, AdditionalAbiTags); - } - - Out << 'E'; - } - void CXXNameMangler::mangleNestedName(const TemplateDecl *TD, -+ const AbiTagList *AdditionalAbiTags, -+ bool ExcludeUnqualifiedName, - const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs) { - // ::= N [] E - - Out << 'N'; - -- mangleTemplatePrefix(TD); -+ mangleTemplatePrefix(TD, AdditionalAbiTags, ExcludeUnqualifiedName); - mangleTemplateArgs(TemplateArgs, NumTemplateArgs); - - Out << 'E'; - } - --void CXXNameMangler::mangleLocalName(const Decl *D) { -+void CXXNameMangler::mangleLocalName(const Decl *D, -+ const AbiTagList *AdditionalAbiTags, -+ bool ExcludeUnqualifiedName) { - // := Z E [] - // := Z E s [] - // := Z E d [ ] -@@ -1151,15 +1409,25 @@ void CXXNameMangler::mangleLocalName(const Decl *D) { - - Out << 'Z'; - -- if (const ObjCMethodDecl *MD = dyn_cast(DC)) -- mangleObjCMethodName(MD); -- else if (const BlockDecl *BD = dyn_cast(DC)) -- mangleBlockForPrefix(BD); -- else -- mangleFunctionEncoding(cast(DC)); -+ { -+ AbiTagState localAbiTags(AbiTags); -+ -+ if (const ObjCMethodDecl *MD = dyn_cast(DC)) -+ mangleObjCMethodName(MD); -+ else if (const BlockDecl *BD = dyn_cast(DC)) -+ mangleBlockForPrefix(BD); -+ else -+ mangleFunctionEncoding(cast(DC)); -+ -+ // implicit abi tags (from namespace) are not available in the following -+ // entity; reset to actually emitted tags, which are available. -+ localAbiTags.UsedAbiTags = localAbiTags.EmittedAbiTags; -+ } - - Out << 'E'; - -+ TemporaryDisableDerivedAbiTags TemporyDisable(DisableDerivedAbiTags, getStructor(dyn_cast(D)) != Structor); -+ - if (RD) { - // The parameter number is omitted for the last parameter, 0 for the - // second-to-last parameter, 1 for the third-to-last parameter, etc. The -@@ -1184,13 +1452,17 @@ void CXXNameMangler::mangleLocalName(const Decl *D) { - // Mangle the name relative to the closest enclosing function. - // equality ok because RD derived from ND above - if (D == RD) { -- mangleUnqualifiedName(RD); -+ if (!ExcludeUnqualifiedName) -+ mangleUnqualifiedName(RD, AdditionalAbiTags); - } else if (const BlockDecl *BD = dyn_cast(D)) { - manglePrefix(getEffectiveDeclContext(BD), true /*NoFunction*/); -- mangleUnqualifiedBlock(BD); -+ assert(!AdditionalAbiTags && "Block cannot have additional abi tags"); -+ if (!ExcludeUnqualifiedName) -+ mangleUnqualifiedBlock(BD); - } else { - const NamedDecl *ND = cast(D); -- mangleNestedName(ND, getEffectiveDeclContext(ND), true /*NoFunction*/); -+ mangleNestedName(ND, getEffectiveDeclContext(ND), -+ AdditionalAbiTags, true /*NoFunction*/, ExcludeUnqualifiedName); - } - } else if (const BlockDecl *BD = dyn_cast(D)) { - // Mangle a block in a default parameter; see above explanation for -@@ -1207,30 +1479,35 @@ void CXXNameMangler::mangleLocalName(const Decl *D) { - } - } - -- mangleUnqualifiedBlock(BD); -+ assert(!AdditionalAbiTags && "Block cannot have additional abi tags"); -+ if (!ExcludeUnqualifiedName) -+ mangleUnqualifiedBlock(BD); - } else { -- mangleUnqualifiedName(cast(D)); -- } -- -- if (const NamedDecl *ND = dyn_cast(RD ? RD : D)) { -- unsigned disc; -- if (Context.getNextDiscriminator(ND, disc)) { -- if (disc < 10) -- Out << '_' << disc; -- else -- Out << "__" << disc << '_'; -+ if (!ExcludeUnqualifiedName) -+ mangleUnqualifiedName(cast(D), AdditionalAbiTags); -+ } -+ -+ if (!ExcludeUnqualifiedName) { -+ if (const NamedDecl *ND = dyn_cast(RD ? RD : D)) { -+ unsigned disc; -+ if (Context.getNextDiscriminator(ND, disc)) { -+ if (disc < 10) -+ Out << '_' << disc; -+ else -+ Out << "__" << disc << '_'; -+ } - } - } - } - - void CXXNameMangler::mangleBlockForPrefix(const BlockDecl *Block) { - if (GetLocalClassDecl(Block)) { -- mangleLocalName(Block); -+ mangleLocalName(Block, /* AdditionalAbiTags */ nullptr, /* ExcludeUnqualifiedName */ false); - return; - } - const DeclContext *DC = getEffectiveDeclContext(Block); - if (isLocalContainerContext(DC)) { -- mangleLocalName(Block); -+ mangleLocalName(Block, /* AdditionalAbiTags */ nullptr, /* ExcludeUnqualifiedName */ false); - return; - } - manglePrefix(getEffectiveDeclContext(Block)); -@@ -1241,10 +1518,11 @@ void CXXNameMangler::mangleUnqualifiedBlock(const BlockDecl *Block) { - if (Decl *Context = Block->getBlockManglingContextDecl()) { - if ((isa(Context) || isa(Context)) && - Context->getDeclContext()->isRecord()) { -- if (const IdentifierInfo *Name -- = cast(Context)->getIdentifier()) { -+ const auto *ND = cast(Context); -+ if (const IdentifierInfo *Name = ND->getIdentifier()) { - mangleSourceName(Name); -- Out << 'M'; -+ writeAbiTags(ND, /* AdditionalAbiTags */ nullptr); -+ Out << 'M'; - } - } - } -@@ -1277,7 +1555,7 @@ void CXXNameMangler::mangleLambda(const CXXRecordDecl *Lambda) { - if (const IdentifierInfo *Name - = cast(Context)->getIdentifier()) { - mangleSourceName(Name); -- Out << 'M'; -+ Out << 'M'; - } - } - } -@@ -1359,11 +1637,11 @@ void CXXNameMangler::manglePrefix(const DeclContext *DC, bool NoFunction) { - // Check if we have a template. - const TemplateArgumentList *TemplateArgs = nullptr; - if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { -- mangleTemplatePrefix(TD); -+ mangleTemplatePrefix(TD, /* AdditionalAbiTags */ nullptr); - mangleTemplateArgs(*TemplateArgs); - } else { - manglePrefix(getEffectiveDeclContext(ND), NoFunction); -- mangleUnqualifiedName(ND); -+ mangleUnqualifiedName(ND, /* AdditionalAbiTags */ nullptr); - } - - addSubstitution(ND); -@@ -1374,27 +1652,30 @@ void CXXNameMangler::mangleTemplatePrefix(TemplateName Template) { - // ::= - // ::= - if (TemplateDecl *TD = Template.getAsTemplateDecl()) -- return mangleTemplatePrefix(TD); -+ return mangleTemplatePrefix(TD, /* AdditionalAbiTags */ nullptr); - - if (QualifiedTemplateName *Qualified = Template.getAsQualifiedTemplateName()) - manglePrefix(Qualified->getQualifier()); -- -+ - if (OverloadedTemplateStorage *Overloaded - = Template.getAsOverloadedTemplate()) { - mangleUnqualifiedName(nullptr, (*Overloaded->begin())->getDeclName(), -- UnknownArity); -+ UnknownArity, -+ /* AdditionalAbiTags */ nullptr); - return; - } -- -+ - DependentTemplateName *Dependent = Template.getAsDependentTemplateName(); - assert(Dependent && "Unknown template name kind?"); - if (NestedNameSpecifier *Qualifier = Dependent->getQualifier()) - manglePrefix(Qualifier); -- mangleUnscopedTemplateName(Template); -+ mangleUnscopedTemplateName(Template, /* AdditionalAbiTags */ nullptr); - } - - void CXXNameMangler::mangleTemplatePrefix(const TemplateDecl *ND, -- bool NoFunction) { -+ const AbiTagList *AdditionalAbiTags, -+ bool NoFunction, -+ bool ExcludeUnqualifiedName) { - // ::=