[libunwind] r374969 - [libunwind][Android] Improve workaround for PIE zero-dlpi_addr bug
Author: rprichard Date: Tue Oct 15 19:38:47 2019 New Revision: 374969 URL: http://llvm.org/viewvc/llvm-project?rev=374969&view=rev Log: [libunwind][Android] Improve workaround for PIE zero-dlpi_addr bug Summary: The workaround added in https://reviews.llvm.org/rL299575 appears to be working around a bug in Android JB 4.1.x and 4.2.x (API 16 and 17). Starting in API 16, Android added support for PIE binaries, but the dynamic linker failed to initialize dlpi_addr to the address that the executable was loaded at. The bug was fixed in Android JB 4.3.x (API 18). Improve the true load bias calculation: * The code was assuming that the first segment would be the PT_PHDR segment. I think it's better to be explicit and search for PT_PHDR. (It will be almost as fast in practice.) * It's more correct to use p_vaddr rather than p_offset. If a PIE executable is linked with a non-zero image base (e.g. lld's -Wl,--image-base=), then we must use p_vaddr here. The "phdr->p_vaddr < image_base" condition seems unnecessary and maybe slightly wrong. If the OS were to load a binary at an address smaller than a vaddr in the binary, we would still want to do this workaround. The workaround is safe when the linker bug isn't present, because it should calculate an image_base equal to dlpi_addr. Note that with API 21 and up, this workaround should never activate for dynamically-linked objects, because non-PIE executables aren't allowed. Consolidate the fix into a single block of code that calculates the true image base, and make it clear that the fix no longer applies after API 18. See https://github.com/android/ndk/issues/505 for details. Reviewers: mclow.lists, srhines, danalbert, compnerd Reviewed By: compnerd Subscribers: srhines, krytarowski, christof, libcxx-commits Tags: #libc Differential Revision: https://reviews.llvm.org/D68971 Modified: libunwind/trunk/src/AddressSpace.hpp Modified: libunwind/trunk/src/AddressSpace.hpp URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/AddressSpace.hpp?rev=374969&r1=374968&r2=374969&view=diff == --- libunwind/trunk/src/AddressSpace.hpp (original) +++ libunwind/trunk/src/AddressSpace.hpp Tue Oct 15 19:38:47 2019 @@ -497,32 +497,40 @@ inline bool LocalAddressSpace::findUnwin #if !defined(Elf_Phdr) typedef ElfW(Phdr) Elf_Phdr; #endif +#if !defined(Elf_Addr) +typedef ElfW(Addr) Elf_Addr; +#endif + +Elf_Addr image_base = pinfo->dlpi_addr; + +#if defined(__ANDROID__) && __ANDROID_API__ < 18 +if (image_base == 0) { + // Normally, an image base of 0 indicates a non-PIE executable. On + // versions of Android prior to API 18, the dynamic linker reported a + // dlpi_addr of 0 for PIE executables. Compute the true image base + // using the PT_PHDR segment. + // See https://github.com/android/ndk/issues/505. + for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) { +const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i]; +if (phdr->p_type == PT_PHDR) { + image_base = reinterpret_cast(pinfo->dlpi_phdr) - + phdr->p_vaddr; + break; +} + } +} +#endif #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) #if !defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) #error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform." #endif size_t object_length; -#if defined(__ANDROID__) -#if !defined(Elf_Addr) -typedef ElfW(Addr) Elf_Addr; -#endif -Elf_Addr image_base = -pinfo->dlpi_phnum -? reinterpret_cast(pinfo->dlpi_phdr) - - reinterpret_cast(pinfo->dlpi_phdr) - ->p_offset -: 0; -#endif for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) { const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i]; if (phdr->p_type == PT_LOAD) { -uintptr_t begin = pinfo->dlpi_addr + phdr->p_vaddr; -#if defined(__ANDROID__) -if (pinfo->dlpi_addr == 0 && phdr->p_vaddr < image_base) - begin = begin + image_base; -#endif +uintptr_t begin = image_base + phdr->p_vaddr; uintptr_t end = begin + phdr->p_memsz; if (cbdata->targetAddr >= begin && cbdata->targetAddr < end) { cbdata->sects->dso_base = begin; @@ -531,11 +539,7 @@ inline bool LocalAddressSpace::findUnwin } } else if (phdr->p_type == PT_GNU_EH_FRAME) { EHHeaderParser::EHHeaderInfo hdrInfo; -uintptr_t eh_frame_hdr_start = pinfo->dlpi_addr + phdr->p_vaddr; -#if defined(__ANDROID__) -if (pinfo->dlpi_addr == 0 && phdr->p_vaddr < image_base) - eh_frame_hdr_start = eh_frame_hdr_start + image_base; -#endif +uintptr_t eh_frame_hdr_start = image_base + phdr->p_vaddr;
[libunwind] r375275 - [libunwind][Android] Fix findUnwindSections for ARM EHABI Bionic
Author: rprichard Date: Fri Oct 18 12:59:22 2019 New Revision: 375275 URL: http://llvm.org/viewvc/llvm-project?rev=375275&view=rev Log: [libunwind][Android] Fix findUnwindSections for ARM EHABI Bionic Summary: Fix the arm_section_length count. The meaning of the arm_section_length field changed from num-of-elements to num-of-bytes when the dl_unwind_find_exidx special case was removed (D30306 and D30681). The special case was restored in D39468, but that patch didn't account for the change in arm_section_length's meaning. That patch worked when it was applied to the NDK's fork of libunwind, because it never removed the special case in the first place, and the special case is probably disabled in the Android platform's copy of libunwind, because __ANDROID_API__ is greater than 21. Turn the dl_unwind_find_exidx special case on unconditionally for Bionic. Bionic's dl_unwind_find_exidx is much faster than using dl_iterate_phdr. (e.g. Bionic stores exidx info on an internal soinfo object.) Reviewers: thomasanderson, srhines, danalbert, ed, keith.walker.arm, mclow.lists, compnerd Reviewed By: srhines, danalbert Subscribers: srhines, kristof.beyls, christof, libcxx-commits Tags: #libc Differential Revision: https://reviews.llvm.org/D68972 Modified: libunwind/trunk/src/AddressSpace.hpp libunwind/trunk/src/UnwindCursor.hpp Modified: libunwind/trunk/src/AddressSpace.hpp URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/AddressSpace.hpp?rev=375275&r1=375274&r2=375275&view=diff == --- libunwind/trunk/src/AddressSpace.hpp (original) +++ libunwind/trunk/src/AddressSpace.hpp Fri Oct 18 12:59:22 2019 @@ -32,6 +32,13 @@ #endif #endif +#if defined(_LIBUNWIND_ARM_EHABI) +struct EHABIIndexEntry { + uint32_t functionOffset; + uint32_t data; +}; +#endif + #ifdef __APPLE__ #include namespace libunwind { @@ -462,12 +469,13 @@ inline bool LocalAddressSpace::findUnwin (void)targetAddr; (void)info; return true; -#elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__) && \ -(__ANDROID_API__ < 21) +#elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__) + // For ARM EHABI, Bionic didn't implement dl_iterate_phdr until API 21. After + // API 21, dl_iterate_phdr exists, but dl_unwind_find_exidx is much faster. int length = 0; info.arm_section = (uintptr_t)dl_unwind_find_exidx((_Unwind_Ptr)targetAddr, &length); - info.arm_section_length = (uintptr_t)length; + info.arm_section_length = (uintptr_t)length * sizeof(EHABIIndexEntry); if (info.arm_section && info.arm_section_length) return true; #elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) Modified: libunwind/trunk/src/UnwindCursor.hpp URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindCursor.hpp?rev=375275&r1=375274&r2=375275&view=diff == --- libunwind/trunk/src/UnwindCursor.hpp (original) +++ libunwind/trunk/src/UnwindCursor.hpp Fri Oct 18 12:59:22 2019 @@ -1222,11 +1222,6 @@ template bool U #endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) #if defined(_LIBUNWIND_ARM_EHABI) -struct EHABIIndexEntry { - uint32_t functionOffset; - uint32_t data; -}; - template struct EHABISectionIterator { typedef EHABISectionIterator _Self; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] fd802cc - [libunwind] Fix getSLEB128 on large values
Author: Ryan Prichard Date: 2020-07-15T19:12:56-07:00 New Revision: fd802cc4dea4ed1a233ff725f98c686dc2836bf3 URL: https://github.com/llvm/llvm-project/commit/fd802cc4dea4ed1a233ff725f98c686dc2836bf3 DIFF: https://github.com/llvm/llvm-project/commit/fd802cc4dea4ed1a233ff725f98c686dc2836bf3.diff LOG: [libunwind] Fix getSLEB128 on large values Previously, for large-enough values, getSLEB128 would attempt to shift a signed int in the range [0..0x7f] by 28, 35, 42... bits, which is undefined behavior and likely to fail. Avoid shifting (-1ULL) by 70 for large values. e.g. For INT64_MAX, the last two bytes will be: - 0x7f [bit==56] - 0x00 [bit==63] Differential Revision: https://reviews.llvm.org/D83742 Added: Modified: libunwind/src/AddressSpace.hpp Removed: diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index a4564cb67328..764aaa3489f2 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -290,11 +290,11 @@ inline int64_t LocalAddressSpace::getSLEB128(pint_t &addr, pint_t end) { if (p == pend) _LIBUNWIND_ABORT("truncated sleb128 expression"); byte = *p++; -result |= ((byte & 0x7f) << bit); +result |= (uint64_t)(byte & 0x7f) << bit; bit += 7; } while (byte & 0x80); // sign extend negative numbers - if ((byte & 0x40) != 0) + if ((byte & 0x40) != 0 && bit < 64) result |= (-1ULL) << bit; addr = (pint_t) p; return result; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] 52d0a78 - [libunwind] Fix CIE v1 return address parsing
Author: Ryan Prichard Date: 2020-07-15T19:12:55-07:00 New Revision: 52d0a78b831584c46eda78b7cf349ab93ce13df0 URL: https://github.com/llvm/llvm-project/commit/52d0a78b831584c46eda78b7cf349ab93ce13df0 DIFF: https://github.com/llvm/llvm-project/commit/52d0a78b831584c46eda78b7cf349ab93ce13df0.diff LOG: [libunwind] Fix CIE v1 return address parsing - For CIE version 1 (e.g. in DWARF 2.0.0), the return_address_register field is a ubyte [0..255]. - For CIE version 3 (e.g. in DWARF 3), the field is instead a ULEB128 constant. Previously, libunwind accepted a CIE version of 1 or 3, but always parsed the field as ULEB128. Clang always outputs CIE version 1 into .eh_frame. (It can output CIE version 3 or 4, but only into .debug_frame.) Differential Revision: https://reviews.llvm.org/D83741 Added: Modified: libunwind/src/DwarfParser.hpp Removed: diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp index d05ac468367f..c98c4f92a6ad 100644 --- a/libunwind/src/DwarfParser.hpp +++ b/libunwind/src/DwarfParser.hpp @@ -336,7 +336,8 @@ const char *CFI_Parser::parseCIE(A &addressSpace, pint_t cie, // parse data alignment factor cieInfo->dataAlignFactor = (int)addressSpace.getSLEB128(p, cieContentEnd); // parse return address register - uint64_t raReg = addressSpace.getULEB128(p, cieContentEnd); + uint64_t raReg = (version == 1) ? addressSpace.get8(p++) + : addressSpace.getULEB128(p, cieContentEnd); assert(raReg < 255 && "return address register too large"); cieInfo->returnAddressRegister = (uint8_t)raReg; // parse augmentation data based on augmentation string ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6c4ce20 - [Driver] Search computed sysroot for libc++ header paths
Author: Ryan Prichard Date: 2020-06-17T16:17:37-07:00 New Revision: 6c4ce202267ee089e611b7bee1dc4f3eb07ba23d URL: https://github.com/llvm/llvm-project/commit/6c4ce202267ee089e611b7bee1dc4f3eb07ba23d DIFF: https://github.com/llvm/llvm-project/commit/6c4ce202267ee089e611b7bee1dc4f3eb07ba23d.diff LOG: [Driver] Search computed sysroot for libc++ header paths Summary: The Android NDK's clang driver is used with an Android -target setting, and the driver automatically finds the Android sysroot at a path relative to the driver. The sysroot has the libc++ headers in it. Remove Hurd::computeSysRoot as it is equivalent to the new ToolChain::computeSysRoot method. Fixes PR46213. Reviewers: srhines, danalbert, #libc, kristina Reviewed By: srhines, danalbert Subscribers: ldionne, sthibaul, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D81622 Added: Modified: clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChains/Gnu.cpp clang/lib/Driver/ToolChains/Hurd.cpp clang/lib/Driver/ToolChains/Hurd.h clang/lib/Driver/ToolChains/Linux.h clang/lib/Driver/ToolChains/MSP430.h clang/lib/Driver/ToolChains/RISCVToolchain.h Removed: diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index e8bb86be5554..f33ed991f493 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -536,6 +536,10 @@ class ToolChain { /// FIXME: this really belongs on some sort of DeploymentTarget abstraction virtual bool hasBlocksRuntime() const { return true; } + /// Return the sysroot, possibly searching for a default sysroot using + /// target-specific logic. + virtual std::string computeSysRoot() const; + /// Add the clang cc1 arguments for system include paths. /// /// This routine is responsible for adding the necessary cc1 arguments to diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 2bda7de8ac3a..c21bc0dc2a79 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -750,6 +750,10 @@ std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args, return ComputeLLVMTriple(Args, InputType); } +std::string ToolChain::computeSysRoot() const { + return D.SysRoot; +} + void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { // Each toolchain should provide the appropriate include flags. diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index a392fa00ea75..93a285d42a08 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2846,7 +2846,6 @@ static std::string DetectLibcxxIncludePath(llvm::vfs::FileSystem &vfs, void Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const { - const std::string& SysRoot = getDriver().SysRoot; auto AddIncludePath = [&](std::string Path) { std::string IncludePath = DetectLibcxxIncludePath(getVFS(), Path); if (IncludePath.empty() || !getVFS().exists(IncludePath)) @@ -2862,6 +2861,7 @@ Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, // If this is a development, non-installed, clang, libcxx will // not be found at ../include/c++ but it likely to be found at // one of the following two locations: + std::string SysRoot = computeSysRoot(); if (AddIncludePath(SysRoot + "/usr/local/include/c++")) return; if (AddIncludePath(SysRoot + "/usr/include/c++")) diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp index 3448e4f4a294..a700d7b9064c 100644 --- a/clang/lib/Driver/ToolChains/Hurd.cpp +++ b/clang/lib/Driver/ToolChains/Hurd.cpp @@ -125,13 +125,6 @@ Tool *Hurd::buildAssembler() const { return new tools::gnutools::Assembler(*this); } -std::string Hurd::computeSysRoot() const { - if (!getDriver().SysRoot.empty()) -return getDriver().SysRoot; - - return std::string(); -} - std::string Hurd::getDynamicLinker(const ArgList &Args) const { if (getArch() == llvm::Triple::x86) return "/lib/ld.so"; diff --git a/clang/lib/Driver/ToolChains/Hurd.h b/clang/lib/Driver/ToolChains/Hurd.h index 8f88d7e8e58e..0612a55280a8 100644 --- a/clang/lib/Driver/ToolChains/Hurd.h +++ b/clang/lib/Driver/ToolChains/Hurd.h @@ -27,8 +27,6 @@ class LLVM_LIBRARY_VISIBILITY Hurd : public Generic_ELF { AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
[clang] 408a263 - [CUDA] Ignore __CLANG_ATOMIC_LLONG_LOCK_FREE on i386
Author: Ryan Prichard Date: 2022-07-21T17:23:29-07:00 New Revision: 408a2638fda63b381f8750e16c78bc3c845cfdfd URL: https://github.com/llvm/llvm-project/commit/408a2638fda63b381f8750e16c78bc3c845cfdfd DIFF: https://github.com/llvm/llvm-project/commit/408a2638fda63b381f8750e16c78bc3c845cfdfd.diff LOG: [CUDA] Ignore __CLANG_ATOMIC_LLONG_LOCK_FREE on i386 The default host CPU for an i386 triple is typically at least an i586, which has cmpxchg8b (Clang feature, "cx8"). Therefore, `__CLANG_ATOMIC_LLONG_LOCK_FREE` is 2 on the host, but the value should be 1 for the device. Also, grep for `__CLANG_ATOMIC_*` instead of `__GCC_ATOMIC_*`. The CLANG macros are always emitted, but the GCC macros are omitted for the *-windows-msvc targets. The `__GCC_HAVE_SYNC_COMPARE_AND_SWAP` macro always has GCC in its name, not CLANG, however. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D127465 Added: Modified: clang/test/Preprocessor/cuda-types.cu Removed: diff --git a/clang/test/Preprocessor/cuda-types.cu b/clang/test/Preprocessor/cuda-types.cu index b4de7fda147d7..0ff0d057830dc 100644 --- a/clang/test/Preprocessor/cuda-types.cu +++ b/clang/test/Preprocessor/cuda-types.cu @@ -1,48 +1,53 @@ -// Check that types, widths, __GCC_ATOMIC* macros, etc. match on the host and +// Check that types, widths, __CLANG_ATOMIC* macros, etc. match on the host and // device sides of CUDA compilations. Note that we filter out long double, as // this is intentionally diff erent on host and device. // +// Also ignore __CLANG_ATOMIC_LLONG_LOCK_FREE on i386. The default host CPU for +// an i386 triple is typically at least an i586, which has cmpxchg8b (Clang +// feature, "cx8"). Therefore, __CLANG_ATOMIC_LLONG_LOCK_FREE is 2 on the host, +// but the value should be 1 for the device. +// // FIXME: We really should make __GCC_HAVE_SYNC_COMPARE_AND_SWAP identical on // host and device, but architecturally this is diff icult at the moment. // RUN: mkdir -p %t // RUN: %clang --cuda-host-only -nocudainc -target i386-unknown-linux-gnu -x cuda -E -dM -o - /dev/null \ -// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __GCC_ATOMIC' \ -// RUN: | grep -Ev '__LDBL|_LONG_DOUBLE' > %t/i386-host-defines-filtered +// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __CLANG_ATOMIC' \ +// RUN: | grep -Ev '__LDBL|_LONG_DOUBLE|_ATOMIC_LLONG_LOCK_FREE' > %t/i386-host-defines-filtered // RUN: %clang --cuda-device-only -nocudainc -nocudalib -target i386-unknown-linux-gnu -x cuda -E -dM -o - /dev/null \ -// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __GCC_ATOMIC' \ -// RUN: | grep -Ev '__LDBL|_LONG_DOUBLE' > %t/i386-device-defines-filtered +// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __CLANG_ATOMIC' \ +// RUN: | grep -Ev '__LDBL|_LONG_DOUBLE|_ATOMIC_LLONG_LOCK_FREE' > %t/i386-device-defines-filtered // RUN: diff %t/i386-host-defines-filtered %t/i386-device-defines-filtered // RUN: %clang --cuda-host-only -nocudainc -target x86_64-unknown-linux-gnu -x cuda -E -dM -o - /dev/null \ -// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __GCC_ATOMIC' \ +// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __CLANG_ATOMIC' \ // RUN: | grep -Ev '__LDBL|_LONG_DOUBLE' > %t/x86_64-host-defines-filtered // RUN: %clang --cuda-device-only -nocudainc -nocudalib -target x86_64-unknown-linux-gnu -x cuda -E -dM -o - /dev/null \ -// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __GCC_ATOMIC' \ +// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __CLANG_ATOMIC' \ // RUN: | grep -Ev '__LDBL|_LONG_DOUBLE' > %t/x86_64-device-defines-filtered // RUN: diff %t/x86_64-host-defines-filtered %t/x86_64-device-defines-filtered // RUN: %clang --cuda-host-only -nocudainc -target powerpc64-unknown-linux-gnu -x cuda -E -dM -o - /dev/null \ -// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __GCC_ATOMIC' \ +// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __CLANG_ATOMIC' \ // RUN: | grep -Ev '__LDBL|_LONG_DOUBLE' > %t/powerpc64-host-defines-filtered // RUN: %clang --cuda-device-only -nocudainc -nocudalib -target powerpc64-unknown-linux-gnu -x cuda -E -dM -o - /dev/null \ -// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __GCC_ATOMIC' \ +// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __CLANG_ATOMIC' \ // RUN: | grep -Ev '__LDBL|_LONG_DOUBLE' > %t/powerpc64-device-defines-filtered // RUN: diff %t/powerpc64-host-defines-filtered %t/powerpc64-device-defines-filtered // RUN: %clang --cuda-host-only -nocudainc -target i386-windows-msvc -x cuda -E -dM -o - /dev/null \ -// RUN: | grep -E 'define __[^ ]*(TYPE|MAX|SIZEOF|WIDTH)|define __GCC_ATOMIC' \ -// RUN: | grep -Ev '__LDBL|_LONG_DOUBLE' > %t/i386-msvc-host-def
[clang] 02a2527 - [Frontend] Correct values of ATOMIC_*_LOCK_FREE to match builtin
Author: Ryan Prichard Date: 2022-07-21T17:23:29-07:00 New Revision: 02a25279aedcd959d060bba585adc0fe1cec3782 URL: https://github.com/llvm/llvm-project/commit/02a25279aedcd959d060bba585adc0fe1cec3782 DIFF: https://github.com/llvm/llvm-project/commit/02a25279aedcd959d060bba585adc0fe1cec3782.diff LOG: [Frontend] Correct values of ATOMIC_*_LOCK_FREE to match builtin Correct the logic used to set `ATOMIC_*_LOCK_FREE` preprocessor macros not to rely on the ABI alignment of types. Instead, just assume all those types are aligned correctly by default since clang uses safe alignment for `_Atomic` types even if the underlying types are aligned to a lower boundary by default. For example, the `long long` and `double` types on x86 are aligned to 32-bit boundary by default. However, `_Atomic long long` and `_Atomic double` are aligned to 64-bit boundary, therefore satisfying the requirements of lock-free atomic operations. This fixes PR #19355 by correcting the value of `__GCC_ATOMIC_LLONG_LOCK_FREE` on x86, and therefore also fixing the assumption made in libc++ tests. This also fixes PR #30581 by applying a consistent logic between the functions used to implement both interfaces. Reviewed By: hfinkel, efriedma Differential Revision: https://reviews.llvm.org/D28213 Added: Modified: clang/lib/Frontend/InitPreprocessor.cpp clang/test/Preprocessor/init-x86.c clang/test/Sema/atomic-ops.c Removed: diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 655490ba06e5d..20bfbf144a30a 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -298,12 +298,12 @@ static void DefineFastIntType(unsigned TypeWidth, bool IsSigned, /// Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with /// the specified properties. -static const char *getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign, -unsigned InlineWidth) { +static const char *getLockFreeValue(unsigned TypeWidth, unsigned InlineWidth) { // Fully-aligned, power-of-2 sizes no larger than the inline // width will be inlined as lock-free operations. - if (TypeWidth == TypeAlign && (TypeWidth & (TypeWidth - 1)) == 0 && - TypeWidth <= InlineWidth) + // Note: we do not need to check alignment since _Atomic(T) is always + // appropriately-aligned in clang. + if ((TypeWidth & (TypeWidth - 1)) == 0 && TypeWidth <= InlineWidth) return "2"; // "always lock free" // We cannot be certain what operations the lib calls might be // able to implement as lock-free on future processors. @@ -1142,7 +1142,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI, #define DEFINE_LOCK_FREE_MACRO(TYPE, Type) \ Builder.defineMacro(Prefix + #TYPE "_LOCK_FREE", \ getLockFreeValue(TI.get##Type##Width(), \ - TI.get##Type##Align(), \ InlineWidthBits)); DEFINE_LOCK_FREE_MACRO(BOOL, Bool); DEFINE_LOCK_FREE_MACRO(CHAR, Char); @@ -1157,7 +1156,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI, DEFINE_LOCK_FREE_MACRO(LLONG, LongLong); Builder.defineMacro(Prefix + "POINTER_LOCK_FREE", getLockFreeValue(TI.getPointerWidth(0), - TI.getPointerAlign(0), InlineWidthBits)); #undef DEFINE_LOCK_FREE_MACRO }; diff --git a/clang/test/Preprocessor/init-x86.c b/clang/test/Preprocessor/init-x86.c index 339941fcf3ee6..9c4e328bdf79d 100644 --- a/clang/test/Preprocessor/init-x86.c +++ b/clang/test/Preprocessor/init-x86.c @@ -185,9 +185,9 @@ // I386:#define __i386__ 1 // I386:#define i386 1 -// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=i386-pc-linux-gnu -target-cpu pentium4 < /dev/null | FileCheck -match-full-lines -check-prefix I386-LINUX -check-prefix I386-LINUX-ALIGN32 %s -// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=i386-pc-linux-gnu -target-cpu pentium4 < /dev/null | FileCheck -match-full-lines -check-prefix I386-LINUX -check-prefix I386-LINUX-CXX -check-prefix I386-LINUX-ALIGN32 %s -// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=i386-pc-linux-gnu -target-cpu pentium4 -malign-double < /dev/null | FileCheck -match-full-lines -check-prefix I386-LINUX -check-prefix I386-LINUX-ALIGN64 %s +// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=i386-pc-linux-gnu -target-cpu i486 < /dev/null | FileCheck -match-full-lines -check-prefix I386-LINUX -check-prefix I386-LINUX-ALIGN32 %s +// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=i386-pc-linux-gnu -targ
[libcxx] [compiler-rt] [mlir] [libcxxabi] [clang] [lld] [openmp] [llvm] [runtimes] Use LLVM libunwind from libc++abi by default (PR #77687)
@@ -22,6 +22,9 @@ set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "") set(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY ON CACHE BOOL "") set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "") +# Android uses its own unwinder library +set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "") rprichard wrote: The Android NDK currently sources all of libunwind, libc++abi, and libc++ from the same LLVM commit, so maybe it's better to build the unwinder library at the same time as libc++. OTOH, Android's libc.so exports libunwind's EH API as of API 30 (Android 11), so eventually the NDK might be using an unwinder that's from a much older LLVM commit. It'll be a long time before the NDK targets API 30 as a minimum. IIRC, when I last looked at the Linux libc++ CI tests (i.e. non-Android), the LLVM libunwind was built in the same runtimes CMake invocation as libc++, but the result wasn't actually used or tested. When I set up Android CI testing, I initially had it build libunwind as part of the CI testing, but I wanted the result to resemble what the NDK actually ships, which required a separate step for libunwind (and patching the result into a new resource dir) (see https://reviews.llvm.org/D139147?id=549856, search for "Build libunwind.a"). This patching was dropped in favor of using a libunwind.a from an Android Clang build. https://github.com/llvm/llvm-project/pull/77687 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] fb1abe0 - [libunwind][DWARF] Fix end of .eh_frame calculation
Author: Ryan Prichard Date: 2020-09-16T19:00:57-07:00 New Revision: fb1abe00635c1ec28e55921709904d5ca2e86a74 URL: https://github.com/llvm/llvm-project/commit/fb1abe00635c1ec28e55921709904d5ca2e86a74 DIFF: https://github.com/llvm/llvm-project/commit/fb1abe00635c1ec28e55921709904d5ca2e86a74.diff LOG: [libunwind][DWARF] Fix end of .eh_frame calculation * When .eh_frame is located using .eh_frame_hdr (PT_GNU_EH_FRAME), the start of .eh_frame is known, but not the size. In this case, the unwinder must rely on a terminator present at the end of .eh_frame. Set dwarf_section_length to UINTPTR_MAX to indicate this. * Add a new field, text_segment_length, that the FrameHeaderCache uses to track the size of the PT_LOAD segment indicated by dso_base. * Compute ehSectionEnd by adding sectionLength to ehSectionStart, never to fdeHint. Fixes PR46829. Differential Revision: https://reviews.llvm.org/D87750 Added: Modified: libunwind/src/AddressSpace.hpp libunwind/src/DwarfParser.hpp libunwind/src/FrameHeaderCache.hpp libunwind/src/UnwindCursor.hpp libunwind/test/frameheadercache_test.pass.cpp Removed: diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index eccc2153c697..26397c28798e 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -119,6 +119,10 @@ struct UnwindInfoSections { // No dso_base for SEH or ARM EHABI. uintptr_t dso_base; #endif +#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \ +defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) + uintptr_t text_segment_length; +#endif #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) uintptr_t dwarf_section; uintptr_t dwarf_section_length; @@ -410,7 +414,7 @@ static bool checkAddrInSegment(const Elf_Phdr *phdr, size_t image_base, uintptr_t end = begin + phdr->p_memsz; if (cbdata->targetAddr >= begin && cbdata->targetAddr < end) { cbdata->sects->dso_base = begin; - cbdata->sects->dwarf_section_length = phdr->p_memsz; + cbdata->sects->text_segment_length = phdr->p_memsz; return true; } } @@ -450,8 +454,12 @@ static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, found_hdr = EHHeaderParser::decodeEHHdr( *cbdata->addressSpace, eh_frame_hdr_start, phdr->p_memsz, hdrInfo); - if (found_hdr) + if (found_hdr) { +// .eh_frame_hdr records the start of .eh_frame, but not its size. +// Rely on a zero terminator to find the end of the section. cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr; +cbdata->sects->dwarf_section_length = UINTPTR_MAX; + } } else if (!found_obj) { found_obj = checkAddrInSegment(phdr, image_base, cbdata); } @@ -462,7 +470,6 @@ static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, return 1; } } - cbdata->sects->dwarf_section_length = 0; return 0; } diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp index 1ce2cf2943a2..86c0522afd3f 100644 --- a/libunwind/src/DwarfParser.hpp +++ b/libunwind/src/DwarfParser.hpp @@ -136,7 +136,7 @@ class CFI_Parser { }; static bool findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart, - uint32_t sectionLength, pint_t fdeHint, FDE_Info *fdeInfo, + uintptr_t sectionLength, pint_t fdeHint, FDE_Info *fdeInfo, CIE_Info *cieInfo); static const char *decodeFDE(A &addressSpace, pint_t fdeStart, FDE_Info *fdeInfo, CIE_Info *cieInfo); @@ -167,7 +167,7 @@ const char *CFI_Parser::decodeFDE(A &addressSpace, pint_t fdeStart, p += 8; } if (cfiLength == 0) -return "FDE has zero length"; // end marker +return "FDE has zero length"; // zero terminator uint32_t ciePointer = addressSpace.get32(p); if (ciePointer == 0) return "FDE is really a CIE"; // this is a CIE not an FDE @@ -212,11 +212,13 @@ const char *CFI_Parser::decodeFDE(A &addressSpace, pint_t fdeStart, /// Scan an eh_frame section to find an FDE for a pc template bool CFI_Parser::findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart, -uint32_t sectionLength, pint_t fdeHint, +uintptr_t sectionLength, pint_t fdeHint, FDE_Info *fdeInfo, CIE_Info *cieInfo) { //fprintf(stderr, "findFDE(0x%llX)\n", (long long)pc); pint_t p = (fdeHint != 0) ? fdeHint : ehSectionStart; - const pint_t ehSectionEnd = p + sectionLength; + const pint_t ehSectionEnd = (sectionLength == UINTPTR_MAX) + ? static_cast(-1) + : (ehSectionStart + sectionLength); while (p < ehSectionEnd) { pint_t currentCFI = p; //fprintf(stderr, "findFDE() CFI a
[libunwind] b16d665 - [libunwind] Combine dl_iterate_phdr codepaths for DWARF and EHABI
Author: Ryan Prichard Date: 2020-09-23T15:40:39-07:00 New Revision: b16d6653c01cee37f51a98dd4092c4ef302c47a5 URL: https://github.com/llvm/llvm-project/commit/b16d6653c01cee37f51a98dd4092c4ef302c47a5 DIFF: https://github.com/llvm/llvm-project/commit/b16d6653c01cee37f51a98dd4092c4ef302c47a5.diff LOG: [libunwind] Combine dl_iterate_phdr codepaths for DWARF and EHABI dl_iterate_phdr is used to search for unwind info provided by either PT_GNU_EH_FRAME or PT_ARM_EXIDX. Most of the code between the two is the same, so combine them, and factor out what's different into checkForUnwindInfoSegment. Details: - The FrameHeaderCache can now be enabled for ARM EHABI. - findUnwindSectionsByPhdr now finds the last PT_ARM_EXIDX rather than the first. There should only be one segment. - The dso_base and text_segment_length fields of UnwindInfoSections are now needed for dl_iterate_phdr when using EHABI, to hold the low and high PC values for a cache entry. Reviewed By: compnerd, danielkiss, #libunwind, saugustine Differential Revision: https://reviews.llvm.org/D87880 Added: Modified: libunwind/src/AddressSpace.hpp libunwind/test/frameheadercache_test.pass.cpp Removed: diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 26397c28798e..7a926ec0be55 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -114,13 +114,13 @@ namespace libunwind { /// Used by findUnwindSections() to return info about needed sections. struct UnwindInfoSections { -#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) || defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) || \ -defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND) - // No dso_base for SEH or ARM EHABI. +#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) || \ +defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND) || \ +defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) + // No dso_base for SEH. uintptr_t dso_base; #endif -#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \ -defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) +#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) uintptr_t text_segment_length; #endif #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) @@ -394,11 +394,6 @@ struct _LIBUNWIND_HIDDEN dl_iterate_cb_data { uintptr_t targetAddr; }; -#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) - #if !defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) -#error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform." - #endif - #if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) #include "FrameHeaderCache.hpp" @@ -421,6 +416,38 @@ static bool checkAddrInSegment(const Elf_Phdr *phdr, size_t image_base, return false; } +static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, size_t image_base, + dl_iterate_cb_data *cbdata) { +#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) + if (phdr->p_type == PT_GNU_EH_FRAME) { +EHHeaderParser::EHHeaderInfo hdrInfo; +uintptr_t eh_frame_hdr_start = image_base + phdr->p_vaddr; +cbdata->sects->dwarf_index_section = eh_frame_hdr_start; +cbdata->sects->dwarf_index_section_length = phdr->p_memsz; +if (EHHeaderParser::decodeEHHdr( +*cbdata->addressSpace, eh_frame_hdr_start, phdr->p_memsz, +hdrInfo)) { + // .eh_frame_hdr records the start of .eh_frame, but not its size. + // Rely on a zero terminator to find the end of the section. + cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr; + cbdata->sects->dwarf_section_length = UINTPTR_MAX; + return true; +} + } + return false; +#elif defined(_LIBUNWIND_ARM_EHABI) + if (phdr->p_type == PT_ARM_EXIDX) { +uintptr_t exidx_start = image_base + phdr->p_vaddr; +cbdata->sects->arm_section = exidx_start; +cbdata->sects->arm_section_length = phdr->p_memsz; +return true; + } + return false; +#else +#error Need one of _LIBUNWIND_SUPPORT_DWARF_INDEX or _LIBUNWIND_ARM_EHABI +#endif +} + static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t pinfo_size, void *data) { auto cbdata = static_cast(data); @@ -435,35 +462,22 @@ static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, #endif Elf_Addr image_base = calculateImageBase(pinfo); - bool found_obj = false; - bool found_hdr = false; + bool found_text = false; + bool found_unwind = false; // Third phdr is usually the executable phdr. if (pinfo->dlpi_phnum > 2) -found_obj = checkAddrInSegment(&pinfo->dlpi_phdr[2], image_base, cbdata); +found_text = checkAddrInSegment(&pinfo->dlpi_phdr[2], image_base, cbdata); - // PT_GNU_EH_FRAME is usually near the end. Iterate backward. We already know - // that there is one or more phdrs. + // PT_GNU_EH_FRAME and PT_ARM_EXIDX are usual
[libunwind] 881aba7 - [libunwind] Optimize dl_iterate_phdr's findUnwindSectionsByPhdr
Author: Ryan Prichard Date: 2020-09-23T15:40:39-07:00 New Revision: 881aba7071c6e4cc2417e875ca5027ec7c0a92a3 URL: https://github.com/llvm/llvm-project/commit/881aba7071c6e4cc2417e875ca5027ec7c0a92a3 DIFF: https://github.com/llvm/llvm-project/commit/881aba7071c6e4cc2417e875ca5027ec7c0a92a3.diff LOG: [libunwind] Optimize dl_iterate_phdr's findUnwindSectionsByPhdr Currently, findUnwindSectionsByPhdr is slightly micro-optimized for the case where the first callback has the target address, and is otherwise very inefficient -- it decodes .eh_frame_hdr even when no PT_LOAD matches the PC. (If the FrameHeaderCache is enabled, then the micro-optimization only helps the first time unwind info is looked up.) Instead, it makes more sense to optimize for the case where the callback *doesn't* find the target address, so search for a PT_LOAD segment first, and only look for the unwind info section if a matching PT_LOAD is found. This change helps on an Android benchmark with 100 shared objects, where the DSO at the end of the dl_iterate_phdr list throws 1 exceptions. Assuming the frame cache is disabled, this change cuts about 30-40% off the benchmark's runtime. Reviewed By: compnerd, saugustine, #libunwind Differential Revision: https://reviews.llvm.org/D87881 Added: Modified: libunwind/src/AddressSpace.hpp Removed: diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 7a926ec0be55..171318ff6370 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -462,29 +462,37 @@ static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, #endif Elf_Addr image_base = calculateImageBase(pinfo); - bool found_text = false; - bool found_unwind = false; - // Third phdr is usually the executable phdr. - if (pinfo->dlpi_phnum > 2) -found_text = checkAddrInSegment(&pinfo->dlpi_phdr[2], image_base, cbdata); + // Most shared objects seen in this callback function likely don't contain the + // target address, so optimize for that. Scan for a matching PT_LOAD segment + // first and bail when it isn't found. + bool found_text = false; + for (Elf_Half i = 0; i < pinfo->dlpi_phnum; ++i) { +if (checkAddrInSegment(&pinfo->dlpi_phdr[i], image_base, cbdata)) { + found_text = true; + break; +} + } + if (!found_text) +return 0; // PT_GNU_EH_FRAME and PT_ARM_EXIDX are usually near the end. Iterate - // backward. We already know that there is one or more phdrs. + // backward. + bool found_unwind = false; for (Elf_Half i = pinfo->dlpi_phnum; i > 0; i--) { const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i - 1]; -if (!found_unwind && checkForUnwindInfoSegment(phdr, image_base, cbdata)) +if (checkForUnwindInfoSegment(phdr, image_base, cbdata)) { found_unwind = true; -else if (!found_text && checkAddrInSegment(phdr, image_base, cbdata)) - found_text = true; -if (found_text && found_unwind) { -#if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) - TheFrameHeaderCache.add(cbdata->sects); -#endif - return 1; + break; } } - return 0; + if (!found_unwind) +return 0; + +#if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) + TheFrameHeaderCache.add(cbdata->sects); +#endif + return 1; } #endif // defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] 3c1b2e3 - [libunwind] Make findUnwindSectionsByPhdr static
Author: Ryan Prichard Date: 2020-08-22T17:12:52-07:00 New Revision: 3c1b2e338dfdf4f305b1cb40e2ebcb93a7e470c3 URL: https://github.com/llvm/llvm-project/commit/3c1b2e338dfdf4f305b1cb40e2ebcb93a7e470c3 DIFF: https://github.com/llvm/llvm-project/commit/3c1b2e338dfdf4f305b1cb40e2ebcb93a7e470c3.diff LOG: [libunwind] Make findUnwindSectionsByPhdr static Currently, this function is present in the dynsym table of libunwind.so (on ELF targets). Make the function static instead. In the previous release (LLVM 10.x), this function was instead a lambda function inside LocalAddressSpace::findUnwindSections, and because LocalAddressSpace was marked with _LIBUNWIND_HIDDEN, the lambda function was also a hidden symbol. Differential Revision: https://reviews.llvm.org/D86372 Added: Modified: libunwind/src/AddressSpace.hpp Removed: diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 2443bd761cc4..b3949b2d27a4 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -432,8 +432,8 @@ static bool checkAddrInSegment(const Elf_Phdr *phdr, size_t image_base, return false; } -int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t pinfo_size, - void *data) { +static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, +size_t pinfo_size, void *data) { auto cbdata = static_cast(data); if (pinfo->dlpi_phnum == 0 || cbdata->targetAddr < pinfo->dlpi_addr) return 0; @@ -482,7 +482,8 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t pinfo_size, // Given all the #ifdef's above, the code here is for // defined(LIBUNWIND_ARM_EHABI) -int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) { +static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, +void *data) { auto *cbdata = static_cast(data); bool found_obj = false; bool found_hdr = false; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] 9e32d7b - [libunwind] Remove static_assert / __has_feature macros
Author: Ryan Prichard Date: 2020-08-24T14:07:20-07:00 New Revision: 9e32d7b6e7e6615dbc5049a53f8e2ba03ae0292f URL: https://github.com/llvm/llvm-project/commit/9e32d7b6e7e6615dbc5049a53f8e2ba03ae0292f DIFF: https://github.com/llvm/llvm-project/commit/9e32d7b6e7e6615dbc5049a53f8e2ba03ae0292f.diff LOG: [libunwind] Remove static_assert / __has_feature macros The static_assert macro broke on GCC when a scope had two asserts and a condition that depended on a template parameter. Remove the macro and rely on the compiler's C++11 static_assert feature. The __has_feature macro was only used here to determine whether to define the static_assert macro. Reviewed By: mstorsjo, #libunwind Differential Revision: https://reviews.llvm.org/D86411 Added: Modified: libunwind/src/config.h Removed: diff --git a/libunwind/src/config.h b/libunwind/src/config.h index 842fd829af19..c6f71c1b93d3 100644 --- a/libunwind/src/config.h +++ b/libunwind/src/config.h @@ -18,16 +18,6 @@ #include #include -// Define static_assert() unless already defined by compiler. -#ifndef __has_feature - #define __has_feature(__x) 0 -#endif -#if !(__has_feature(cxx_static_assert)) && !defined(static_assert) - #define static_assert(__b, __m) \ - extern int compile_time_assert_failed[ ( __b ) ? 1 : -1 ] \ - __attribute__( ( unused ) ); -#endif - // Platform specific configuration defines. #ifdef __APPLE__ #if defined(FOR_DYLD) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] 7a45759 - [libunwind] Minor fixes in libunwind
Author: Ryan Prichard Date: 2020-08-26T18:22:03-07:00 New Revision: 7a457593efecc8f3e806cd3d022c480bc80d4fbb URL: https://github.com/llvm/llvm-project/commit/7a457593efecc8f3e806cd3d022c480bc80d4fbb DIFF: https://github.com/llvm/llvm-project/commit/7a457593efecc8f3e806cd3d022c480bc80d4fbb.diff LOG: [libunwind] Minor fixes in libunwind * When _LIBUNWIND_SUPPORT_COMPACT_UNWIND is defined in config.h, define it to "1" like the other macros. These macros are still checked using "#if defined(...)", however. * Include libunwind.h in AddressSpace.hpp before using _LIBUNWIND_ARM_EHABI. * Rename ProcessFrameHeaderCache to TheFrameHeaderCache, because some configurations (e.g. Android / hermetic static libraries) can have one cache per shared object in the process. (When there are more copies, it's more important not to waste memory in the cache.) * Add 3 missing header files to LIBUNWIND_HEADERS. Differential Revision: https://reviews.llvm.org/D86254 Added: Modified: libunwind/src/AddressSpace.hpp libunwind/src/CMakeLists.txt libunwind/src/config.h Removed: diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 717aa336fd13..e6f2609d679b 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -17,6 +17,12 @@ #include #include +#include "libunwind.h" +#include "config.h" +#include "dwarf2.h" +#include "EHHeaderParser.hpp" +#include "Registers.hpp" + #ifndef _LIBUNWIND_USE_DLADDR #if !defined(_LIBUNWIND_IS_BAREMETAL) && !defined(_WIN32) #define _LIBUNWIND_USE_DLADDR 1 @@ -39,12 +45,6 @@ struct EHABIIndexEntry { }; #endif -#include "libunwind.h" -#include "config.h" -#include "dwarf2.h" -#include "EHHeaderParser.hpp" -#include "Registers.hpp" - #ifdef __APPLE__ struct dyld_unwind_sections @@ -414,8 +414,9 @@ struct _LIBUNWIND_HIDDEN dl_iterate_cb_data { #if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) #include "FrameHeaderCache.hpp" -// There should be just one of these per process. -static FrameHeaderCache ProcessFrameHeaderCache; +// Typically there is one cache per process, but when libunwind is built as a +// hermetic static library, then each shared object may have its own cache. +static FrameHeaderCache TheFrameHeaderCache; #endif static bool checkAddrInSegment(const Elf_Phdr *phdr, size_t image_base, @@ -438,7 +439,7 @@ static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, if (pinfo->dlpi_phnum == 0 || cbdata->targetAddr < pinfo->dlpi_addr) return 0; #if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) - if (ProcessFrameHeaderCache.find(pinfo, pinfo_size, data)) + if (TheFrameHeaderCache.find(pinfo, pinfo_size, data)) return 1; #else // Avoid warning about unused variable. @@ -472,7 +473,7 @@ static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, } if (found_obj && found_hdr) { #if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) - ProcessFrameHeaderCache.add(cbdata->sects); + TheFrameHeaderCache.add(cbdata->sects); #endif return 1; } diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt index 8f79b1cf8740..928bc5992471 100644 --- a/libunwind/src/CMakeLists.txt +++ b/libunwind/src/CMakeLists.txt @@ -42,9 +42,12 @@ set(LIBUNWIND_HEADERS dwarf2.h DwarfInstructions.hpp DwarfParser.hpp +EHHeaderParser.hpp +FrameHeaderCache.hpp libunwind_ext.h Registers.hpp RWMutex.hpp +Unwind-EHABI.h UnwindCursor.hpp ../include/libunwind.h ../include/unwind.h diff --git a/libunwind/src/config.h b/libunwind/src/config.h index c6f71c1b93d3..2014b8cb77ab 100644 --- a/libunwind/src/config.h +++ b/libunwind/src/config.h @@ -21,10 +21,10 @@ // Platform specific configuration defines. #ifdef __APPLE__ #if defined(FOR_DYLD) -#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND +#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 #else -#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND -#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 +#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif #elif defined(_WIN32) #ifdef __SEH__ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] 3071d5f - [libunwind] Factor out getInfoFromFdeCie. NFCI.
Author: Ryan Prichard Date: 2020-08-26T18:22:06-07:00 New Revision: 3071d5ffba2337174f95f984bc1603a2be8b797d URL: https://github.com/llvm/llvm-project/commit/3071d5ffba2337174f95f984bc1603a2be8b797d DIFF: https://github.com/llvm/llvm-project/commit/3071d5ffba2337174f95f984bc1603a2be8b797d.diff LOG: [libunwind] Factor out getInfoFromFdeCie. NFCI. Differential Revision: https://reviews.llvm.org/D86255 Added: Modified: libunwind/src/UnwindCursor.hpp Removed: diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp index 54913360ca29..e6a36764fc79 100644 --- a/libunwind/src/UnwindCursor.hpp +++ b/libunwind/src/UnwindCursor.hpp @@ -925,6 +925,9 @@ class UnwindCursor : public AbstractUnwindCursor{ #endif #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) + bool getInfoFromFdeCie(const typename CFI_Parser::FDE_Info &fdeInfo, + const typename CFI_Parser::CIE_Info &cieInfo, + pint_t pc, uintptr_t dso_base); bool getInfoFromDwarfSection(pint_t pc, const UnwindInfoSections §s, uint32_t fdeSectionOffsetHint=0); int stepWithDwarfFDE() { @@ -1476,6 +1479,32 @@ bool UnwindCursor::getInfoFromEHABISection( #endif #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) +template +bool UnwindCursor::getInfoFromFdeCie( +const typename CFI_Parser::FDE_Info &fdeInfo, +const typename CFI_Parser::CIE_Info &cieInfo, pint_t pc, +uintptr_t dso_base) { + typename CFI_Parser::PrologInfo prolog; + if (CFI_Parser::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo, pc, + R::getArch(), &prolog)) { +// Save off parsed FDE info +_info.start_ip = fdeInfo.pcStart; +_info.end_ip= fdeInfo.pcEnd; +_info.lsda = fdeInfo.lsda; +_info.handler = cieInfo.personality; +// Some frameless functions need SP altered when resuming in function, so +// propagate spExtraArgSize. +_info.gp= prolog.spExtraArgSize; +_info.flags = 0; +_info.format= dwarfEncoding(); +_info.unwind_info = fdeInfo.fdeStart; +_info.unwind_info_size = static_cast(fdeInfo.fdeLength); +_info.extra = static_cast(dso_base); +return true; + } + return false; +} + template bool UnwindCursor::getInfoFromDwarfSection(pint_t pc, const UnwindInfoSections §s, @@ -1516,21 +1545,7 @@ bool UnwindCursor::getInfoFromDwarfSection(pint_t pc, &fdeInfo, &cieInfo); } if (foundFDE) { -typename CFI_Parser::PrologInfo prolog; -if (CFI_Parser::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo, pc, -R::getArch(), &prolog)) { - // Save off parsed FDE info - _info.start_ip = fdeInfo.pcStart; - _info.end_ip= fdeInfo.pcEnd; - _info.lsda = fdeInfo.lsda; - _info.handler = cieInfo.personality; - _info.gp= prolog.spExtraArgSize; - _info.flags = 0; - _info.format= dwarfEncoding(); - _info.unwind_info = fdeInfo.fdeStart; - _info.unwind_info_size = (uint32_t)fdeInfo.fdeLength; - _info.extra = (unw_word_t) sects.dso_base; - +if (getInfoFromFdeCie(fdeInfo, cieInfo, pc, sects.dso_base)) { // Add to cache (to make next lookup faster) if we had no hint // and there was no index. if (!foundInCache && (fdeSectionOffsetHint == 0)) { @@ -1932,58 +1947,24 @@ void UnwindCursor::setInfoBasedOnIPRegister(bool isReturnAddress) { // dynamically registered for it. pint_t cachedFDE = DwarfFDECache::findFDE(0, pc); if (cachedFDE != 0) { -CFI_Parser::FDE_Info fdeInfo; -CFI_Parser::CIE_Info cieInfo; -const char *msg = CFI_Parser::decodeFDE(_addressSpace, -cachedFDE, &fdeInfo, &cieInfo); -if (msg == NULL) { - typename CFI_Parser::PrologInfo prolog; - if (CFI_Parser::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo, - pc, R::getArch(), &prolog)) { -// save off parsed FDE info -_info.start_ip = fdeInfo.pcStart; -_info.end_ip = fdeInfo.pcEnd; -_info.lsda = fdeInfo.lsda; -_info.handler = cieInfo.personality; -_info.gp = prolog.spExtraArgSize; - // Some frameless functions need SP - // altered when resuming in function. -_info.flags= 0; -_info.format = dwarfEncoding(); -_info.unwind_info = fdeInfo.fdeStart; -_info.unwind_info_size =
[libunwind] 673484b - [libunwind] Minor SJLJ config cleanup. NFCI.
Author: Ryan Prichard Date: 2020-09-03T15:59:45-07:00 New Revision: 673484b34189b1bccf73a2ec96968092bc8a26a7 URL: https://github.com/llvm/llvm-project/commit/673484b34189b1bccf73a2ec96968092bc8a26a7 DIFF: https://github.com/llvm/llvm-project/commit/673484b34189b1bccf73a2ec96968092bc8a26a7.diff LOG: [libunwind] Minor SJLJ config cleanup. NFCI. Simplify: defined(__ARM_DWARF_EH__) || !defined(__arm__) to: !defined(_LIBUNWIND_ARM_EHABI) A later patch benefits from the simplicity. This change will result in the two DWARF macros being defined when __USING_SJLJ_EXCEPTIONS__ is defined, but: * That's already the case with the __APPLE__ and _WIN32 clauses. * That's also already the case with other architectures. * With __USING_SJLJ_EXCEPTIONS__, most of the unwinder is #ifdef'ed away. Generally, when __USING_SJLJ_EXCEPTIONS__ is defined, most of the libunwind code is removed by the preprocessor. e.g. None of the hpp files are included, and almost all of the .c and .cpp files are defined away, except in Unwind-sjlj.c. Unwind_AppleExtras.cpp is an exception because it includes two hpp files, which it doesn't use. Remove the unneeded includes for consistency with the general rule. Reviewed By: steven_wu Differential Revision: https://reviews.llvm.org/D86767 Added: Modified: libunwind/src/Unwind_AppleExtras.cpp libunwind/src/config.h Removed: diff --git a/libunwind/src/Unwind_AppleExtras.cpp b/libunwind/src/Unwind_AppleExtras.cpp index 1d9948aced35..e3d41ca2b4e9 100644 --- a/libunwind/src/Unwind_AppleExtras.cpp +++ b/libunwind/src/Unwind_AppleExtras.cpp @@ -8,8 +8,6 @@ //===--===// #include "config.h" -#include "AddressSpace.hpp" -#include "DwarfParser.hpp" // static linker symbols to prevent wrong two level namespace for _Unwind symbols diff --git a/libunwind/src/config.h b/libunwind/src/config.h index 2014b8cb77ab..fd177dd7338c 100644 --- a/libunwind/src/config.h +++ b/libunwind/src/config.h @@ -18,6 +18,8 @@ #include #include +#include <__libunwind_config.h> + // Platform specific configuration defines. #ifdef __APPLE__ #if defined(FOR_DYLD) @@ -33,7 +35,7 @@ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif #else - #if defined(__ARM_DWARF_EH__) || !defined(__arm__) + #if !defined(_LIBUNWIND_ARM_EHABI) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1 #endif @@ -81,6 +83,8 @@ #error Unsupported target #endif +// Apple/armv7k defaults to DWARF/Compact unwinding, but its libunwind also +// needs to include the SJLJ APIs. #if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__) #define _LIBUNWIND_BUILD_SJLJ_APIS #endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] 88bf133 - [libunwind] Replace chain-of-ifdefs for dl_iterate_phdr
Author: Ryan Prichard Date: 2020-09-08T15:49:35-07:00 New Revision: 88bf133c99c3124842c182a019306f83f2c1b856 URL: https://github.com/llvm/llvm-project/commit/88bf133c99c3124842c182a019306f83f2c1b856 DIFF: https://github.com/llvm/llvm-project/commit/88bf133c99c3124842c182a019306f83f2c1b856.diff LOG: [libunwind] Replace chain-of-ifdefs for dl_iterate_phdr Define a _LIBUNWIND_USE_DL_ITERATE_PHDR macro in config.h when there is no other unwind info lookup method. Also define a _LIBUNWIND_USE_DL_UNWIND_FIND_EXIDX macro to factor out (__BIONIC__ and _LIBUNWIND_ARM_EHABI). Differential Revision: https://reviews.llvm.org/D86768 Added: Modified: libunwind/src/AddressSpace.hpp libunwind/src/config.h libunwind/test/frameheadercache_test.pass.cpp Removed: diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index e6f2609d679b..cc298c9bbb83 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -98,22 +98,15 @@ extern char __eh_frame_hdr_end; extern char __exidx_start; extern char __exidx_end; -#elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) - -// ELF-based systems may use dl_iterate_phdr() to access sections -// containing unwinding information. The ElfW() macro for pointer-size -// independent ELF header traversal is not provided by on some -// systems (e.g., FreeBSD). On these systems the data structures are -// just called Elf_XXX. Define ElfW() locally. -#ifndef _WIN32 -#include -#else +#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32) + #include #include -#endif -#if !defined(ElfW) -#define ElfW(type) Elf_##type -#endif + +#elif defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) || \ + defined(_LIBUNWIND_USE_DL_UNWIND_FIND_EXIDX) + +#include #endif @@ -351,23 +344,14 @@ LocalAddressSpace::getEncodedP(pint_t &addr, pint_t end, uint8_t encoding, return result; } -#ifdef __APPLE__ -#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL) -#elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL) -#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32) -#elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32) -#elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__) -// Code inside findUnwindSections handles all these cases. -// -// Although the above ifdef chain is ugly, there doesn't seem to be a cleaner -// way to handle it. The generalized boolean expression is: -// -// A OR (B AND C) OR (D AND C) OR (B AND E) OR (F AND E) OR (D AND G) -// -// Running it through various boolean expression simplifiers gives expressions -// that don't help at all. -#elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) +#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) +// The ElfW() macro for pointer-size independent ELF header traversal is not +// provided by on some systems (e.g., FreeBSD). On these systems the +// data structures are just called Elf_XXX. Define ElfW() locally. +#if !defined(ElfW) + #define ElfW(type) Elf_##type +#endif #if !defined(Elf_Half) typedef ElfW(Half) Elf_Half; #endif @@ -482,9 +466,7 @@ static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, return 0; } -#else // defined(LIBUNWIND_SUPPORT_DWARF_UNWIND) -// Given all the #ifdef's above, the code here is for -// defined(LIBUNWIND_ARM_EHABI) +#elif defined(_LIBUNWIND_ARM_EHABI) static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) { @@ -516,8 +498,9 @@ static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, } return found_obj && found_hdr; } -#endif // defined(LIBUNWIND_SUPPORT_DWARF_UNWIND) -#endif // defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) + +#endif +#endif // defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, @@ -601,16 +584,14 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, (void)targetAddr; (void)info; return true; -#elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__) - // For ARM EHABI, Bionic didn't implement dl_iterate_phdr until API 21. After - // API 21, dl_iterate_phdr exists, but dl_unwind_find_exidx is much faster. +#elif defined(_LIBUNWIND_USE_DL_UNWIND_FIND_EXIDX) int length = 0; info.arm_section = (uintptr_t)dl_unwind_find_exidx((_Unwind_Ptr)targetAddr, &length); info.arm_section_length = (uintptr_t)length * sizeof(EHABIIndexEntry); if (info.arm_section && info.arm_section_length) return true; -#elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) +#elif defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) dl_iterate_cb_data cb_data = {this, &info, targetAddr}; int found = dl_iterate_phdr(findUnwin
[libunwind] 09d4929 - [libunwind] Bare-metal DWARF: set dso_base to 0
Author: Ryan Prichard Date: 2020-09-09T15:43:35-07:00 New Revision: 09d492902f178f60b3ab986360eadde9b5c8d359 URL: https://github.com/llvm/llvm-project/commit/09d492902f178f60b3ab986360eadde9b5c8d359 DIFF: https://github.com/llvm/llvm-project/commit/09d492902f178f60b3ab986360eadde9b5c8d359.diff LOG: [libunwind] Bare-metal DWARF: set dso_base to 0 Previously, DwarfFDECache::findFDE used 0 as a special value meaning "search the entire cache, including dynamically-registered FDEs". Switch this special value to -1, which doesn't make sense as a DSO base. Fixes PR47335. Reviewed By: compnerd, #libunwind Differential Revision: https://reviews.llvm.org/D86748 Added: Modified: libunwind/src/AddressSpace.hpp libunwind/src/UnwindCursor.hpp Removed: diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index cc298c9bbb83..eccc2153c697 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -518,6 +518,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, return true; } #elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL) + info.dso_base = 0; // Bare metal is statically linked, so no need to ask the dynamic loader info.dwarf_section_length = (uintptr_t)(&__eh_frame_end - &__eh_frame_start); info.dwarf_section =(uintptr_t)(&__eh_frame_start); diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp index e6a36764fc79..206b5e398321 100644 --- a/libunwind/src/UnwindCursor.hpp +++ b/libunwind/src/UnwindCursor.hpp @@ -81,6 +81,7 @@ template class _LIBUNWIND_HIDDEN DwarfFDECache { typedef typename A::pint_t pint_t; public: + static constexpr pint_t kSearchAll = static_cast(-1); static pint_t findFDE(pint_t mh, pint_t pc); static void add(pint_t mh, pint_t ip_start, pint_t ip_end, pint_t fde); static void removeAllIn(pint_t mh); @@ -138,7 +139,7 @@ typename A::pint_t DwarfFDECache::findFDE(pint_t mh, pint_t pc) { pint_t result = 0; _LIBUNWIND_LOG_IF_FALSE(_lock.lock_shared()); for (entry *p = _buffer; p < _bufferUsed; ++p) { -if ((mh == p->mh) || (mh == 0)) { +if ((mh == p->mh) || (mh == kSearchAll)) { if ((p->ip_start <= pc) && (pc < p->ip_end)) { result = p->fde; break; @@ -1945,7 +1946,8 @@ void UnwindCursor::setInfoBasedOnIPRegister(bool isReturnAddress) { #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) // There is no static unwind info for this pc. Look to see if an FDE was // dynamically registered for it. - pint_t cachedFDE = DwarfFDECache::findFDE(0, pc); + pint_t cachedFDE = DwarfFDECache::findFDE(DwarfFDECache::kSearchAll, + pc); if (cachedFDE != 0) { typename CFI_Parser::FDE_Info fdeInfo; typename CFI_Parser::CIE_Info cieInfo; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 729899f - [libunwind] unw_* alias fixes for ELF and Mach-O
Author: Ryan Prichard Date: 2021-02-22T16:54:05-08:00 New Revision: 729899f7b6bf6aff65988d895d7a639391a67608 URL: https://github.com/llvm/llvm-project/commit/729899f7b6bf6aff65988d895d7a639391a67608 DIFF: https://github.com/llvm/llvm-project/commit/729899f7b6bf6aff65988d895d7a639391a67608.diff LOG: [libunwind] unw_* alias fixes for ELF and Mach-O Rename the CMake option, LIBUNWIND_HERMETIC_STATIC_LIBRARY, to LIBUNWIND_HIDE_SYMBOLS. Rename the C macro define, _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS, to _LIBUNWIND_HIDE_SYMBOLS, because now the macro adds a .hidden directive rather than merely suppress visibility annotations. For ELF, when LIBUNWIND_HIDE_SYMBOLS is enabled, mark unw_getcontext as hidden. This symbol is the only one defined using src/assembly.h's WEAK_ALIAS macro. Other unw_* weak aliases are defined in C++ and are already hidden. Mach-O doesn't support weak aliases, so remove .weak_reference and weak_import. When LIBUNWIND_HIDE_SYMBOLS is enabled, output .private_extern for the unw_* aliases. In assembly.h, add missing SYMBOL_NAME macro invocations, which are used to prefix symbol names with '_' on some targets. Fixes PR46709. Reviewed By: #libunwind, phosek, compnerd, steven_wu Differential Revision: https://reviews.llvm.org/D93003 Added: Modified: clang/cmake/caches/Fuchsia-stage2.cmake libunwind/CMakeLists.txt libunwind/src/CMakeLists.txt libunwind/src/assembly.h libunwind/src/config.h llvm/utils/gn/secondary/libunwind/src/BUILD.gn Removed: diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake index 1c14d2fec404..7f84f74d348f 100644 --- a/clang/cmake/caches/Fuchsia-stage2.cmake +++ b/clang/cmake/caches/Fuchsia-stage2.cmake @@ -179,7 +179,7 @@ if(FUCHSIA_SDK) set(RUNTIMES_${target}-unknown-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} CACHE PATH "") set(RUNTIMES_${target}-unknown-fuchsia_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "") set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "") -set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "") +set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_HIDE_SYMBOLS ON CACHE BOOL "") set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "") set(RUNTIMES_${target}-unknown-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "") set(RUNTIMES_${target}-unknown-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "") diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index 140700030aff..628f0aaa0506 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -102,7 +102,7 @@ elseif(LIBUNWIND_BUILD_32_BITS) message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS=ON is not supported on this platform.") endif() -option(LIBUNWIND_HERMETIC_STATIC_LIBRARY +option(LIBUNWIND_HIDE_SYMBOLS "Do not export any symbols from the static library." OFF) #=== @@ -321,7 +321,7 @@ endif() # Disable DLL annotations on Windows for static builds. if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED) - add_definitions(-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) + add_definitions(-D_LIBUNWIND_HIDE_SYMBOLS) endif() if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA) diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt index a7045d2c317f..f59dfdde9f03 100644 --- a/libunwind/src/CMakeLists.txt +++ b/libunwind/src/CMakeLists.txt @@ -164,11 +164,11 @@ if (LIBUNWIND_ENABLE_STATIC) LINKER_LANGUAGE C OUTPUT_NAME "unwind") - if(LIBUNWIND_HERMETIC_STATIC_LIBRARY) + if(LIBUNWIND_HIDE_SYMBOLS) append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility=hidden) append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden) target_compile_options(unwind_static PRIVATE ${UNWIND_STATIC_LIBRARY_FLAGS}) -target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) +target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_HIDE_SYMBOLS) endif() list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static") diff --git a/libunwind/src/assembly.h b/libunwind/src/assembly.h index f2f7c848307e..dcd38198501c 100644 --- a/libunwind/src/assembly.h +++ b/libunwind/src/assembly.h @@ -70,12 +70,15 @@ #if defined(__APPLE__) #define SYMBOL_IS_FUNC(name) -#define EXPORT_SYMBOL(name) #define HIDDEN_SYMBOL(name) .private_extern name -#define WEAK_SYMBOL(name) .weak_reference name +#if defined(_LIBUNWIND_HIDE_SYMBOLS) +#define EXPORT_SYMBOL(name) HIDDEN_SYMBOL(name) +#else +#define EXPORT_SYMBOL(name) +#endif #define WEAK_ALIAS(name, aliasname) \ .globl SYMBOL_NAME(aliasname) SEPARATOR
[libunwind] 729899f - [libunwind] unw_* alias fixes for ELF and Mach-O
Author: Ryan Prichard Date: 2021-02-22T16:54:05-08:00 New Revision: 729899f7b6bf6aff65988d895d7a639391a67608 URL: https://github.com/llvm/llvm-project/commit/729899f7b6bf6aff65988d895d7a639391a67608 DIFF: https://github.com/llvm/llvm-project/commit/729899f7b6bf6aff65988d895d7a639391a67608.diff LOG: [libunwind] unw_* alias fixes for ELF and Mach-O Rename the CMake option, LIBUNWIND_HERMETIC_STATIC_LIBRARY, to LIBUNWIND_HIDE_SYMBOLS. Rename the C macro define, _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS, to _LIBUNWIND_HIDE_SYMBOLS, because now the macro adds a .hidden directive rather than merely suppress visibility annotations. For ELF, when LIBUNWIND_HIDE_SYMBOLS is enabled, mark unw_getcontext as hidden. This symbol is the only one defined using src/assembly.h's WEAK_ALIAS macro. Other unw_* weak aliases are defined in C++ and are already hidden. Mach-O doesn't support weak aliases, so remove .weak_reference and weak_import. When LIBUNWIND_HIDE_SYMBOLS is enabled, output .private_extern for the unw_* aliases. In assembly.h, add missing SYMBOL_NAME macro invocations, which are used to prefix symbol names with '_' on some targets. Fixes PR46709. Reviewed By: #libunwind, phosek, compnerd, steven_wu Differential Revision: https://reviews.llvm.org/D93003 Added: Modified: clang/cmake/caches/Fuchsia-stage2.cmake libunwind/CMakeLists.txt libunwind/src/CMakeLists.txt libunwind/src/assembly.h libunwind/src/config.h llvm/utils/gn/secondary/libunwind/src/BUILD.gn Removed: diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake index 1c14d2fec404..7f84f74d348f 100644 --- a/clang/cmake/caches/Fuchsia-stage2.cmake +++ b/clang/cmake/caches/Fuchsia-stage2.cmake @@ -179,7 +179,7 @@ if(FUCHSIA_SDK) set(RUNTIMES_${target}-unknown-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} CACHE PATH "") set(RUNTIMES_${target}-unknown-fuchsia_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "") set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "") -set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "") +set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_HIDE_SYMBOLS ON CACHE BOOL "") set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "") set(RUNTIMES_${target}-unknown-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "") set(RUNTIMES_${target}-unknown-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "") diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index 140700030aff..628f0aaa0506 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -102,7 +102,7 @@ elseif(LIBUNWIND_BUILD_32_BITS) message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS=ON is not supported on this platform.") endif() -option(LIBUNWIND_HERMETIC_STATIC_LIBRARY +option(LIBUNWIND_HIDE_SYMBOLS "Do not export any symbols from the static library." OFF) #=== @@ -321,7 +321,7 @@ endif() # Disable DLL annotations on Windows for static builds. if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED) - add_definitions(-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) + add_definitions(-D_LIBUNWIND_HIDE_SYMBOLS) endif() if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA) diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt index a7045d2c317f..f59dfdde9f03 100644 --- a/libunwind/src/CMakeLists.txt +++ b/libunwind/src/CMakeLists.txt @@ -164,11 +164,11 @@ if (LIBUNWIND_ENABLE_STATIC) LINKER_LANGUAGE C OUTPUT_NAME "unwind") - if(LIBUNWIND_HERMETIC_STATIC_LIBRARY) + if(LIBUNWIND_HIDE_SYMBOLS) append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility=hidden) append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden) target_compile_options(unwind_static PRIVATE ${UNWIND_STATIC_LIBRARY_FLAGS}) -target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) +target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_HIDE_SYMBOLS) endif() list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static") diff --git a/libunwind/src/assembly.h b/libunwind/src/assembly.h index f2f7c848307e..dcd38198501c 100644 --- a/libunwind/src/assembly.h +++ b/libunwind/src/assembly.h @@ -70,12 +70,15 @@ #if defined(__APPLE__) #define SYMBOL_IS_FUNC(name) -#define EXPORT_SYMBOL(name) #define HIDDEN_SYMBOL(name) .private_extern name -#define WEAK_SYMBOL(name) .weak_reference name +#if defined(_LIBUNWIND_HIDE_SYMBOLS) +#define EXPORT_SYMBOL(name) HIDDEN_SYMBOL(name) +#else +#define EXPORT_SYMBOL(name) +#endif #define WEAK_ALIAS(name, aliasname) \ .globl SYMBOL_NAME(aliasname) SEPARATOR
[clang] 91f8aac - [Android] Use -l:libunwind.a with --rtlib=compiler-rt
Author: Ryan Prichard Date: 2021-02-25T15:40:02-08:00 New Revision: 91f8aacc040f5a458cfc2a10c4039e0028931455 URL: https://github.com/llvm/llvm-project/commit/91f8aacc040f5a458cfc2a10c4039e0028931455 DIFF: https://github.com/llvm/llvm-project/commit/91f8aacc040f5a458cfc2a10c4039e0028931455.diff LOG: [Android] Use -l:libunwind.a with --rtlib=compiler-rt On Android, the unwinder isn't part of the C++ STL and isn't (in older versions) exported from libc.so. Instead, the driver links the static unwinder archive implicitly. Currently, the Android NDK implicitly links libgcc.a to provide both builtins and the unwinder. To support switching to compiler-rt builtins and libunwind, make --rtlib=compiler-rt behave the same way on Android, and implicitly pass -l:libunwind.a to the linker. Adjust the -ldl logic. For the Android NDK, the unwinder (whether libgcc.a or libunwind.a) is linked statically and calls a function in the dynamic loader for finding unwind tables (e.g. dl_iterate_phdr). On Android, this function is in libc.a for static executables and libdl.so otherwise, so -ldl is needed. (glibc doesn't need -ldl because its libc.so exports dl_iterate_phdr.) Differential Revision: https://reviews.llvm.org/D96403 Added: Modified: clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp Removed: diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 3f500617d843..f8b03b635dd7 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -929,9 +929,12 @@ ToolChain::UnwindLibType ToolChain::GetUnwindLibType( unwindLibType = ToolChain::UNW_None; else if (LibName == "platform" || LibName == "") { ToolChain::RuntimeLibType RtLibType = GetRuntimeLibType(Args); -if (RtLibType == ToolChain::RLT_CompilerRT) - unwindLibType = ToolChain::UNW_None; -else if (RtLibType == ToolChain::RLT_Libgcc) +if (RtLibType == ToolChain::RLT_CompilerRT) { + if (getTriple().isAndroid()) +unwindLibType = ToolChain::UNW_CompilerRT; + else +unwindLibType = ToolChain::UNW_None; +} else if (RtLibType == ToolChain::RLT_Libgcc) unwindLibType = ToolChain::UNW_Libgcc; } else if (LibName == "libunwind") { if (GetRuntimeLibType(Args) == RLT_Libgcc) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 375b6b32b631..e20b01a8deab 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1366,11 +1366,17 @@ bool tools::isObjCAutoRefCount(const ArgList &Args) { enum class LibGccType { UnspecifiedLibGcc, StaticLibGcc, SharedLibGcc }; -static LibGccType getLibGccType(const Driver &D, const ArgList &Args) { +static LibGccType getLibGccType(const ToolChain &TC, const Driver &D, +const ArgList &Args) { if (Args.hasArg(options::OPT_static_libgcc) || Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_static_pie)) return LibGccType::StaticLibGcc; - if (Args.hasArg(options::OPT_shared_libgcc) || D.CCCIsCXX()) + if (Args.hasArg(options::OPT_shared_libgcc)) +return LibGccType::SharedLibGcc; + // The Android NDK only provides libunwind.a, not libunwind.so. + if (TC.getTriple().isAndroid()) +return LibGccType::StaticLibGcc; + if (D.CCCIsCXX()) return LibGccType::SharedLibGcc; return LibGccType::UnspecifiedLibGcc; } @@ -1392,12 +1398,12 @@ static void AddUnwindLibrary(const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args) { ToolChain::UnwindLibType UNW = TC.GetUnwindLibType(Args); // Targets that don't use unwind libraries. - if (TC.getTriple().isAndroid() || TC.getTriple().isOSIAMCU() || - TC.getTriple().isOSBinFormatWasm() || + if ((TC.getTriple().isAndroid() && UNW == ToolChain::UNW_Libgcc) || + TC.getTriple().isOSIAMCU() || TC.getTriple().isOSBinFormatWasm() || UNW == ToolChain::UNW_None) return; - LibGccType LGT = getLibGccType(D, Args); + LibGccType LGT = getLibGccType(TC, D, Args); bool AsNeeded = LGT == LibGccType::UnspecifiedLibGcc && !TC.getTriple().isAndroid() && !TC.getTriple().isOSCygMing(); if (AsNeeded) @@ -1434,20 +1440,12 @@ static void AddUnwindLibrary(const ToolChain &TC, const Driver &D, static void AddLibgcc(const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args) { - LibGccType LGT = getLibGccType(D, Args); + LibGccType LGT = getLibGccType(TC, D, Args); if (LGT != LibGccType::SharedLibGcc) CmdArgs.push_back("-lgcc"); AddUnwindLibrary(TC, D, CmdArgs, Args); if (LGT == LibGccType::SharedLibGcc) CmdArgs.push_back("-lgcc"); - - // According to Android ABI, we have to link with libdl if we are - // linking with non-static li
[clang] a478b0a - [Android] Default to --rtlib=compiler-rt
Author: Ryan Prichard Date: 2021-03-09T18:09:53-08:00 New Revision: a478b0a199f4928041390d1f35dd5e226936b42c URL: https://github.com/llvm/llvm-project/commit/a478b0a199f4928041390d1f35dd5e226936b42c DIFF: https://github.com/llvm/llvm-project/commit/a478b0a199f4928041390d1f35dd5e226936b42c.diff LOG: [Android] Default to --rtlib=compiler-rt By default, the driver uses the compiler-rt builtins and links with -l:libunwind.a. Restore the previous behavior by passing --rtlib=libgcc. Reviewed By: danalbert Differential Revision: https://reviews.llvm.org/D96404 Added: Modified: clang/lib/Driver/ToolChains/Linux.cpp clang/lib/Driver/ToolChains/Linux.h clang/test/Driver/linux-ld.c Removed: diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index 93a56be6a7a4..ad98013dd4f0 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -363,6 +363,12 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) addPathIfExists(D, SysRoot + "/usr/lib", Paths); } +ToolChain::RuntimeLibType Linux::GetDefaultRuntimeLibType() const { + if (getTriple().isAndroid()) +return ToolChain::RLT_CompilerRT; + return Generic_ELF::GetDefaultRuntimeLibType(); +} + ToolChain::CXXStdlibType Linux::GetDefaultCXXStdlibType() const { if (getTriple().isAndroid()) return ToolChain::CST_Libcxx; diff --git a/clang/lib/Driver/ToolChains/Linux.h b/clang/lib/Driver/ToolChains/Linux.h index a45236bc10d3..05e01a208456 100644 --- a/clang/lib/Driver/ToolChains/Linux.h +++ b/clang/lib/Driver/ToolChains/Linux.h @@ -35,6 +35,7 @@ class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF { llvm::opt::ArgStringList &CC1Args) const override; void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + RuntimeLibType GetDefaultRuntimeLibType() const override; CXXStdlibType GetDefaultCXXStdlibType() const override; bool IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const override; diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c index 5263928ff3b9..eba09d2970cc 100644 --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -288,7 +288,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-CLANG-ANDROID-NONE %s // CHECK-CLANG-ANDROID-NONE: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" -// CHECK-CLANG-ANDROID-NONE: "-lgcc" "-ldl" "-lc" +// CHECK-CLANG-ANDROID-NONE: "-l:libunwind.a" "-ldl" "-lc" // // RUN: %clang -shared -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: --target=aarch64-linux-android -rtlib=platform --unwindlib=platform \ @@ -296,7 +296,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-CLANG-ANDROID-SHARED %s // CHECK-CLANG-ANDROID-SHARED: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" -// CHECK-CLANG-ANDROID-SHARED: "-lgcc" "-ldl" "-lc" +// CHECK-CLANG-ANDROID-SHARED: "-l:libunwind.a" "-ldl" "-lc" // // RUN: %clang -static -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: --target=aarch64-linux-android -rtlib=platform --unwindlib=platform \ @@ -304,7 +304,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-CLANG-ANDROID-STATIC %s // CHECK-CLANG-ANDROID-STATIC: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" -// CHECK-CLANG-ANDROID-STATIC: "--start-group" "-lgcc" "-lc" "--end-group" +// CHECK-CLANG-ANDROID-STATIC: "--start-group" "{{[^"]*}}{{/|}}libclang_rt.builtins-aarch64-android.a" "-l:libunwind.a" "-lc" "--end-group" // // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: --target=x86_64-unknown-linux -rtlib=platform --unwindlib=platform \ @@ -1353,10 +1353,12 @@ // CHECK-ANDROID: "--enable-new-dtags" // CHECK-ANDROID: "{{.*}}{{/|}}crtbegin_dynamic.o" // CHECK-ANDROID: "-L[[SYSROOT]]/usr/lib" -// CHECK-ANDROID-NOT: "gcc_s" -// CHECK-ANDROID: "-lgcc" +// CHECK-ANDROID-NOT: "-lgcc_s" +// CHECK-ANDROID-NOT: "-lgcc" +// CHECK-ANDROID: "-l:libunwind.a" // CHECK-ANDROID: "-ldl" -// CHECK-ANDROID-NOT: "gcc_s" +// CHECK-ANDROID-NOT: "-lgcc_s" +// CHECK-ANDROID-NOT: "-lgcc" // CHECK-ANDROID: "{{.*}}{{/|}}crtend_android.o" // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: --target=arm-linux-androideabi -rtlib=platform --unwindlib=platform \ @@ -1409,10 +1411,12 @@ // CHECK-ANDROID-SO-NOT: "-Bsymbolic" // CHECK-ANDROID-SO: "{{.*}}{{/|}}crtbegin_so.o" // CHECK-ANDROID-SO: "-L[[SYSROOT]]/usr/lib" -// CHECK-ANDROID-SO-NOT: "gcc_s" -// CHECK-ANDROID-SO: "-lgcc" +// CHECK-ANDROID-SO-NOT: "-lgcc_s" +// CHECK-ANDROID-SO-NOT: "-lgcc" +// CHECK-ANDROID-SO: "-l:libunwind.a" //
[clang] 106a992 - [Headers][ARM] Allow `struct _Unwind_Exception` in unwind.h
Author: Ryan Prichard Date: 2022-12-09T15:16:20-08:00 New Revision: 106a99276f9e7b9eec9542cc2b4dcd8489eb1a6b URL: https://github.com/llvm/llvm-project/commit/106a99276f9e7b9eec9542cc2b4dcd8489eb1a6b DIFF: https://github.com/llvm/llvm-project/commit/106a99276f9e7b9eec9542cc2b4dcd8489eb1a6b.diff LOG: [Headers][ARM] Allow `struct _Unwind_Exception` in unwind.h Use the same approach as used in libunwind/include/unwind_arm_ehabi.h (D89570) and GCC's unwind-arm-common.h, so that _Unwind_Exception can be used both with and without the struct tag. Fixes a build failure in libcxxabi/test/forced_unwind1.pass.cpp. Reviewed By: danielkiss Differential Revision: https://reviews.llvm.org/D139503 Added: Modified: clang/lib/Headers/unwind.h Removed: diff --git a/clang/lib/Headers/unwind.h b/clang/lib/Headers/unwind.h index 971a62da0d212..33e1792cd1fb7 100644 --- a/clang/lib/Headers/unwind.h +++ b/clang/lib/Headers/unwind.h @@ -65,7 +65,8 @@ struct _Unwind_Context; #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \ defined(__ARM_DWARF_EH__) || defined(__SEH__)) struct _Unwind_Control_Block; -typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */ +typedef struct _Unwind_Control_Block _Unwind_Control_Block; +#define _Unwind_Exception _Unwind_Control_Block /* Alias */ #else struct _Unwind_Exception; typedef struct _Unwind_Exception _Unwind_Exception; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)
rprichard wrote: > I was waiting for your recent PRs to land, but the android failures seem to > persist even after them. Yeah that's also what I noticed. My PRs were aimed at getting the Android Dockerfile buildable again, but once it was buildable, the feature testing failed. It _seemed_ that after this PR, the CMake feature test for a flag `-foo` wasn't even passing `-foo` to the Clang driver, but maybe I was reading too much into the CMake log output. It definitely wasn't handling the bootstrapping situation correctly -- it was trying to detect whether the driver supported `-nostdlib++` and concluded that it didn't, because it couldn't link an executable using `-lc++` (because libc++ hadn't been built yet). My suspicion was that this PR broke CMake feature testing for any cross-compiled configurations. https://github.com/llvm/llvm-project/pull/96171 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)
rprichard wrote: This check in libcxx/cmake/config-ix.cmake seems to break: ``` check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG) ``` It appears that it isn't passing either `-nostdlib++` or `-lc++` to the clang linker command-line, but then `-lc++` _is_ passed to `ld.lld` because `-nostdlib++` is missing. The check fails because libc++ hasn't been built yet. It seems that the older function had been dealing with this: ``` -function(llvm_check_compiler_linker_flag lang flag out_var) - # If testing a flag with check_c_compiler_flag, it gets added to the compile - # command only, but not to the linker command in that test. If the flag - # is vital for linking to succeed, the test would fail even if it would - # have succeeded if it was included on both commands. - # - # Therefore, try adding the flag to CMAKE_REQUIRED_FLAGS, which gets - # added to both compiling and linking commands in the tests. ... ``` It sounds like the right fix is to use `check_linker_flag` though? I can test that... https://github.com/llvm/llvm-project/pull/96171 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)
rprichard wrote: > This check in libcxx/cmake/config-ix.cmake seems to break: > > ``` > check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG) > ``` This particular check was already using `check_cxx_compiler_flag` before this PR, so it was broken(?), but it apparently doesn't matter because the real check is in runtimes/CMakeLists.txt instead, and that was previously using `llvm_check_compiler_linker_flag`. Not sure how the runtimes build influences the libcxx/libcxxabi builds. It feels like `CXX_SUPPORTS_NOSTDLIBXX_FLAG` from the runtimes build is being inherited? https://github.com/llvm/llvm-project/pull/96171 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)
rprichard wrote: The previous `llvm_check_compiler_linker_flag` passes the same flag to both the compile step and the linker step. Apparently, it's like a combined `check_compiler_flag` and `check_linker_flag`. CMake apparently doesn't implement this directly (https://stackoverflow.com/questions/78503180/cmake-how-to-check-for-a-compiler-and-linker-flag-at-the-same-time), but it's not too hard to implement it ourselves. The LLVM implementation is much better than the one proposed on StackOverflow. If we just want to do a cleanup, then `llvm_check_compiler_linker_flag` can be simplified a lot: ```cmake include(CMakePushCheckState) include(CheckCompilerFlag) function(llvm_check_compiler_linker_flag lang flag out_var) # If testing a flag with check_compiler_flag, it gets added to the compile # command only, but not to the linker command in that test. If the flag # is vital for linking to succeed, the test would fail even if it would # have succeeded if it was included on both commands. # # Therefore, try adding the flag to CMAKE_REQUIRED_FLAGS, which gets # added to both compiling and linking commands in the tests. cmake_push_check_state() set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}") check_compiler_flag("${lang}" "" ${out_var}) cmake_pop_check_state() endfunction() ``` Almost all the uses of `llvm_check_compiler_linker_flag` that https://github.com/llvm/llvm-project/pull/96171/commits/1515c2cd16911e1297c57fb69d4bb4921a40b8ab switches to `check_compiler_flag` are actually testing a linker flag, so they need to use `check_linker_flag` instead. There were a few flags that I wasn't familiar with, so maybe they could be `check_compiler_flag`, or maybe we actually need to do both: * Darwin's `-fapplication-extension` * `/SAFESEH` to MSVC in openmp/runtime/cmake/config-ix.cmake * ICC's `-static-intel` * ICC's `-no-intel-extensions` Ignoring those cases, the Android tests pass with this PR after switching `llvm_check_compiler_linker_flag` call sites to `check_linker_flag`. https://github.com/llvm/llvm-project/pull/96171 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)
rprichard wrote: I rebased the changes so I could review them, https://github.com/llvm/llvm-project/commit/640d2e631a4bc11e3afa030e30d05288ee954cb5. The compiler-rt/cmake/config-ix.cmake file is still removing `include(LLVMCheckCompilerLinkerFlag)`, but it needs to keep it now. https://github.com/llvm/llvm-project/pull/96171 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)
rprichard wrote: > The github UI should show all changes to main? Not sure why a rebase would be > necessary...? Sorry, you're right. (Not sure why I didn't notice that before.) The change looks good to me now. https://github.com/llvm/llvm-project/pull/96171 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)
rprichard wrote: Sorry, I didn't notice the ping until just now. The CMake feature testing seems broken, on Android at least. Here's a representative error from `build/android-ndk-21-def-x86/CMakeFiles/CMakeError.log`: ``` Performing C++ SOURCE FILE Test CXX_SUPPORTS_NOSTDLIBXX_FLAG failed with the following output: Change Dir: /llvm/build/android-ndk-21-def-x86/CMakeFiles/CMakeTmp Run Build Command(s):/usr/local/bin/ninja cmTC_80129 && [1/2] Building CXX object CMakeFiles/cmTC_80129.dir/src.cxx.o [2/2] Linking CXX executable cmTC_80129 FAILED: cmTC_80129 : && /opt/android/clang/clang-current/bin/clang++ --target=i686-linux-android21 --sysroot=/opt/android/ndk/sysroot --start-no-unused-arguments --unwindlib=none --end-no-unused-arguments CMakeFiles/cmTC_80129.dir/src.cxx.o -o cmTC_80129 && : ld.lld: error: unable to find library -lc++ clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed. Source file was: int main() { return 0; } ``` It's trying to see if `-nostdlib++` is supported, but I don't see that flag being passed in the `clang++` command line that CMake uses. In any case, CMake tries to build a C++ program, which fails because libc++ doesn't exist yet. It seems that the Android support in the Dockerfile is broken after a refactor last year. I have some changes that get it working again. BuildKite is still successfully running Android tests as of today, so I think it's using an old image. https://github.com/llvm/llvm-project/pull/96171 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] c82deed - [libunwind] Unwind through aarch64/Linux sigreturn frame
Author: Ryan Prichard Date: 2021-01-13T16:38:36-08:00 New Revision: c82deed6764cbc63966374baf9721331901ca958 URL: https://github.com/llvm/llvm-project/commit/c82deed6764cbc63966374baf9721331901ca958 DIFF: https://github.com/llvm/llvm-project/commit/c82deed6764cbc63966374baf9721331901ca958.diff LOG: [libunwind] Unwind through aarch64/Linux sigreturn frame An AArch64 sigreturn trampoline frame can't currently be described in a DWARF .eh_frame section, because the AArch64 DWARF spec currently doesn't define a constant for the PC register. (PC and LR may need to be restored to different values.) Instead, use the same technique as libgcc or github.com/libunwind and detect the sigreturn frame by looking for the sigreturn instructions: mov x8, #0x8b svc #0x0 If a sigreturn frame is detected, libunwind restores all the GPRs by assuming that sp points at an rt_sigframe Linux kernel struct. This behavior is a fallback mode that is only used if there is no ordinary unwind info for sigreturn. If libunwind can't find unwind info for a PC, it assumes that the PC is readable, and would crash if it isn't. This could happen if: - The PC points at a function compiled without unwind info, and which is part of an execute-only mapping (e.g. using -Wl,--execute-only). - The PC is invalid and happens to point to unreadable or unmapped memory. In the tests, ignore a failed dladdr call so that the tests can run on user-mode qemu for AArch64, which uses a stack-allocated trampoline instead of a vDSO. Reviewed By: danielkiss, compnerd, #libunwind Differential Revision: https://reviews.llvm.org/D90898 Added: Modified: libunwind/include/__libunwind_config.h libunwind/src/UnwindCursor.hpp libunwind/test/signal_unwind.pass.cpp libunwind/test/unwind_leaffunction.pass.cpp Removed: diff --git a/libunwind/include/__libunwind_config.h b/libunwind/include/__libunwind_config.h index 71d77ca65118..80be357496c4 100644 --- a/libunwind/include/__libunwind_config.h +++ b/libunwind/include/__libunwind_config.h @@ -27,6 +27,9 @@ #define _LIBUNWIND_HIGHEST_DWARF_REGISTER_RISCV 64 #if defined(_LIBUNWIND_IS_NATIVE_ONLY) +# if defined(__linux__) +# define _LIBUNWIND_TARGET_LINUX 1 +# endif # if defined(__i386__) # define _LIBUNWIND_TARGET_I386 # define _LIBUNWIND_CONTEXT_SIZE 8 diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp index 9f8fa65107b4..e537ed84dd93 100644 --- a/libunwind/src/UnwindCursor.hpp +++ b/libunwind/src/UnwindCursor.hpp @@ -925,6 +925,25 @@ class UnwindCursor : public AbstractUnwindCursor{ } #endif +#if defined(_LIBUNWIND_TARGET_LINUX) && defined(_LIBUNWIND_TARGET_AARCH64) + bool setInfoForSigReturn() { +R dummy; +return setInfoForSigReturn(dummy); + } + int stepThroughSigReturn() { +R dummy; +return stepThroughSigReturn(dummy); + } + bool setInfoForSigReturn(Registers_arm64 &); + int stepThroughSigReturn(Registers_arm64 &); + template bool setInfoForSigReturn(Registers &) { +return false; + } + template int stepThroughSigReturn(Registers &) { +return UNW_STEP_END; + } +#endif + #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) bool getInfoFromFdeCie(const typename CFI_Parser::FDE_Info &fdeInfo, const typename CFI_Parser::CIE_Info &cieInfo, @@ -1179,6 +1198,9 @@ class UnwindCursor : public AbstractUnwindCursor{ unw_proc_info_t _info; bool _unwindInfoMissing; bool _isSignalFrame; +#if defined(_LIBUNWIND_TARGET_LINUX) && defined(_LIBUNWIND_TARGET_AARCH64) + bool _isSigReturn = false; +#endif }; @@ -1873,7 +1895,11 @@ bool UnwindCursor::getInfoFromSEH(pint_t pc) { template void UnwindCursor::setInfoBasedOnIPRegister(bool isReturnAddress) { - pint_t pc = (pint_t)this->getReg(UNW_REG_IP); +#if defined(_LIBUNWIND_TARGET_LINUX) && defined(_LIBUNWIND_TARGET_AARCH64) + _isSigReturn = false; +#endif + + pint_t pc = static_cast(this->getReg(UNW_REG_IP)); #if defined(_LIBUNWIND_ARM_EHABI) // Remove the thumb bit so the IP represents the actual instruction address. // This matches the behaviour of _Unwind_GetIP on arm. @@ -1971,10 +1997,77 @@ void UnwindCursor::setInfoBasedOnIPRegister(bool isReturnAddress) { } #endif // #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) +#if defined(_LIBUNWIND_TARGET_LINUX) && defined(_LIBUNWIND_TARGET_AARCH64) + if (setInfoForSigReturn()) +return; +#endif + // no unwind info, flag that we can't reliably unwind _unwindInfoMissing = true; } +#if defined(_LIBUNWIND_TARGET_LINUX) && defined(_LIBUNWIND_TARGET_AARCH64) +template +bool UnwindCursor::setInfoForSigReturn(Registers_arm64 &) { + // Look for the sigreturn trampoline. The trampoline's body is two + // specific instructions (see below). Typically the trampoline comes from the + // vDSO[1] (i.e. the __kernel_rt_sigreturn func
[clang] [libc++] Remove unused HAVE_LIBCXXABI variable from Android cache (PR #111007)
https://github.com/rprichard approved this pull request. https://github.com/llvm/llvm-project/pull/111007 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits