[llvm-branch-commits] [cfe-branch] r245094 - Mention CFI in release notes.

2015-08-14 Thread Peter Collingbourne via llvm-branch-commits
Author: pcc
Date: Fri Aug 14 15:30:05 2015
New Revision: 245094

URL: http://llvm.org/viewvc/llvm-project?rev=245094&view=rev
Log:
Mention CFI in release notes.

Modified:
cfe/branches/release_37/docs/ReleaseNotes.rst

Modified: cfe/branches/release_37/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/docs/ReleaseNotes.rst?rev=245094&r1=245093&r2=245094&view=diff
==
--- cfe/branches/release_37/docs/ReleaseNotes.rst (original)
+++ cfe/branches/release_37/docs/ReleaseNotes.rst Fri Aug 14 15:30:05 2015
@@ -56,6 +56,9 @@ Major New Features
   including x86, x86-64 and Power. Also, pragma ``omp simd`` from OpenMP 4.0 is
   supported as well. See below for details.
 
+- Clang 3.7 includes an implementation of :doc:`control flow integrity
+  `, a security hardening mechanism.
+
 
 Improvements to Clang's diagnostics
 ^^^


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm-branch] r260702 - ARM: Mention r251322 in release notes.

2016-02-12 Thread Peter Collingbourne via llvm-branch-commits
Author: pcc
Date: Fri Feb 12 12:46:48 2016
New Revision: 260702

URL: http://llvm.org/viewvc/llvm-project?rev=260702&view=rev
Log:
ARM: Mention r251322 in release notes.

Modified:
llvm/branches/release_38/docs/ReleaseNotes.rst

Modified: llvm/branches/release_38/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/llvm/branches/release_38/docs/ReleaseNotes.rst?rev=260702&r1=260701&r2=260702&view=diff
==
--- llvm/branches/release_38/docs/ReleaseNotes.rst (original)
+++ llvm/branches/release_38/docs/ReleaseNotes.rst Fri Feb 12 12:46:48 2016
@@ -131,8 +131,10 @@ During this release the ARM target has:
 * Expanded LLDB support, including watchpoints, unwind tables
 * Extended the Load/Store optimiser and cleaned up some of the bad decisions
   made earlier.
-* Gained some code size improvements, though there's still a long road ahead,
-  especially for older cores.
+* Simplified code generation for global variable addresses in ELF, resulting in
+  a significant (4% in Chromium) reduction in code size.
+* Gained some additional code size improvements, though there's still a long 
road
+  ahead, especially for older cores.
 * Added some EABI floating point comparison functions to Compiler-RT
 * Added support for Windows+GNU triple, +features in -mcpu/-march options.
 


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] d302398 - hwasan: Update register-dump-read.c test to reserve x23 instead of x20.

2021-01-15 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2021-01-15T16:14:36-08:00
New Revision: d302398ff05f6d2bfbcb5c4fdafccf8a0e3b9875

URL: 
https://github.com/llvm/llvm-project/commit/d302398ff05f6d2bfbcb5c4fdafccf8a0e3b9875
DIFF: 
https://github.com/llvm/llvm-project/commit/d302398ff05f6d2bfbcb5c4fdafccf8a0e3b9875.diff

LOG: hwasan: Update register-dump-read.c test to reserve x23 instead of x20.

D90422 changed this test to write a fixed value into register x23
instead of x20, but it did not update the list of reserved registers.
This meant that x23 may have been live across the register write,
although this happens to not be the case with the current compiler.
Fix the problem by updating the reserved register list.

Added: 


Modified: 
compiler-rt/test/hwasan/TestCases/register-dump-read.c

Removed: 




diff  --git a/compiler-rt/test/hwasan/TestCases/register-dump-read.c 
b/compiler-rt/test/hwasan/TestCases/register-dump-read.c
index 8325857fa916..002c5dd5e1f9 100644
--- a/compiler-rt/test/hwasan/TestCases/register-dump-read.c
+++ b/compiler-rt/test/hwasan/TestCases/register-dump-read.c
@@ -1,11 +1,11 @@
-// RUN: %clang_hwasan -ffixed-x10 -ffixed-x20 -ffixed-x27 -O0 %s -o %t && not 
%run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
-// RUN: %clang_hwasan -ffixed-x10 -ffixed-x20 -ffixed-x27 -O1 %s -o %t && not 
%run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
-// RUN: %clang_hwasan -ffixed-x10 -ffixed-x20 -ffixed-x27 -O2 %s -o %t && not 
%run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
-// RUN: %clang_hwasan -ffixed-x10 -ffixed-x20 -ffixed-x27 -O3 %s -o %t && not 
%run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_hwasan -ffixed-x10 -ffixed-x23 -ffixed-x27 -O0 %s -o %t && not 
%run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_hwasan -ffixed-x10 -ffixed-x23 -ffixed-x27 -O1 %s -o %t && not 
%run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_hwasan -ffixed-x10 -ffixed-x23 -ffixed-x27 -O2 %s -o %t && not 
%run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_hwasan -ffixed-x10 -ffixed-x23 -ffixed-x27 -O3 %s -o %t && not 
%run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
 // REQUIRES: aarch64-target-arch
 
-// RUN: %clang_hwasan -ffixed-x10 -ffixed-x20 -ffixed-x27 -O2 %s -o %t && not 
%env_hwasan_opts=fast_unwind_on_fatal=true %run %t 2>&1 | FileCheck %s 
--check-prefixes=CHECK
-// RUN: %clang_hwasan -ffixed-x10 -ffixed-x20 -ffixed-x27 -O2 %s -o %t && not 
%env_hwasan_opts=fast_unwind_on_fatal=false %run %t 2>&1 | FileCheck %s 
--check-prefixes=CHECK
+// RUN: %clang_hwasan -ffixed-x10 -ffixed-x23 -ffixed-x27 -O2 %s -o %t && not 
%env_hwasan_opts=fast_unwind_on_fatal=true %run %t 2>&1 | FileCheck %s 
--check-prefixes=CHECK
+// RUN: %clang_hwasan -ffixed-x10 -ffixed-x23 -ffixed-x27 -O2 %s -o %t && not 
%env_hwasan_opts=fast_unwind_on_fatal=false %run %t 2>&1 | FileCheck %s 
--check-prefixes=CHECK
 
 #include 
 #include 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lldb] 7e5a187 - CrashReason: Add MTE tag check faults to the list of crash reasons.

2020-12-29 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2020-12-29T14:36:50-08:00
New Revision: 7e5a187de31358741f9868cdee7b0c63c1343d8d

URL: 
https://github.com/llvm/llvm-project/commit/7e5a187de31358741f9868cdee7b0c63c1343d8d
DIFF: 
https://github.com/llvm/llvm-project/commit/7e5a187de31358741f9868cdee7b0c63c1343d8d.diff

LOG: CrashReason: Add MTE tag check faults to the list of crash reasons.

As of Linux 5.10, the kernel may report either of the two following
crash reasons:
- SEGV_MTEAERR: async MTE tag check fault
- SEGV_MTESERR: sync MTE tag check fault

Teach LLDB about them.

Differential Revision: https://reviews.llvm.org/D93495

Added: 


Modified: 
lldb/source/Plugins/Process/POSIX/CrashReason.cpp
lldb/source/Plugins/Process/POSIX/CrashReason.h

Removed: 




diff  --git a/lldb/source/Plugins/Process/POSIX/CrashReason.cpp 
b/lldb/source/Plugins/Process/POSIX/CrashReason.cpp
index 579077b45bf9..c6ede61cfe1b 100644
--- a/lldb/source/Plugins/Process/POSIX/CrashReason.cpp
+++ b/lldb/source/Plugins/Process/POSIX/CrashReason.cpp
@@ -58,6 +58,18 @@ CrashReason GetCrashReasonForSIGSEGV(const siginfo_t &info) {
 #endif
   case SEGV_BNDERR:
 return CrashReason::eBoundViolation;
+#ifdef __linux__
+#ifndef SEGV_MTEAERR
+#define SEGV_MTEAERR 8
+#endif
+  case SEGV_MTEAERR:
+return CrashReason::eAsyncTagCheckFault;
+#ifndef SEGV_MTESERR
+#define SEGV_MTESERR 9
+#endif
+  case SEGV_MTESERR:
+return CrashReason::eSyncTagCheckFault;
+#endif // __linux__
   }
 
   return CrashReason::eInvalidCrashReason;
@@ -166,6 +178,13 @@ std::string GetCrashReasonString(CrashReason reason, 
lldb::addr_t fault_addr) {
   case CrashReason::eBoundViolation:
 str = "signal SIGSEGV: bound violation";
 break;
+  case CrashReason::eAsyncTagCheckFault:
+str = "signal SIGSEGV: async tag check fault";
+break;
+  case CrashReason::eSyncTagCheckFault:
+str = "signal SIGSEGV: sync tag check fault";
+AppendFaultAddr(str, fault_addr);
+break;
   case CrashReason::eIllegalOpcode:
 str = "signal SIGILL: illegal instruction";
 break;
@@ -246,6 +265,12 @@ const char *CrashReasonAsString(CrashReason reason) {
   case CrashReason::eBoundViolation:
 str = "eBoundViolation";
 break;
+  case CrashReason::eAsyncTagCheckFault:
+str = "eAsyncTagCheckFault";
+break;
+  case CrashReason::eSyncTagCheckFault:
+str = "eSyncTagCheckFault";
+break;
 
   // SIGILL crash reasons.
   case CrashReason::eIllegalOpcode:

diff  --git a/lldb/source/Plugins/Process/POSIX/CrashReason.h 
b/lldb/source/Plugins/Process/POSIX/CrashReason.h
index 9b4784a1e68e..f5213891d976 100644
--- a/lldb/source/Plugins/Process/POSIX/CrashReason.h
+++ b/lldb/source/Plugins/Process/POSIX/CrashReason.h
@@ -22,6 +22,8 @@ enum class CrashReason {
   eInvalidAddress,
   ePrivilegedAddress,
   eBoundViolation,
+  eAsyncTagCheckFault,
+  eSyncTagCheckFault,
 
   // SIGILL crash reasons.
   eIllegalOpcode,



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] aed8454 - ELF: Teach the linker about the 'B' augmentation string character.

2021-01-05 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2021-01-05T19:51:11-08:00
New Revision: aed84542d5a05b415a9a7f54494107aea8bd7e89

URL: 
https://github.com/llvm/llvm-project/commit/aed84542d5a05b415a9a7f54494107aea8bd7e89
DIFF: 
https://github.com/llvm/llvm-project/commit/aed84542d5a05b415a9a7f54494107aea8bd7e89.diff

LOG: ELF: Teach the linker about the 'B' augmentation string character.

This character indicates that when return pointer authentication is
being used, the function signs the return address using the B key.

Differential Revision: https://reviews.llvm.org/D93954

Added: 
lld/test/ELF/eh-frame-cfi-b-key.s

Modified: 
lld/ELF/EhFrame.cpp

Removed: 




diff  --git a/lld/ELF/EhFrame.cpp b/lld/ELF/EhFrame.cpp
index 13f0484ff9e4..578c640f0214 100644
--- a/lld/ELF/EhFrame.cpp
+++ b/lld/ELF/EhFrame.cpp
@@ -194,7 +194,7 @@ uint8_t EhReader::getFdeEncoding() {
   readByte();
 else if (c == 'P')
   skipAugP();
-else if (c != 'S')
+else if (c != 'B' && c != 'S')
   failOn(aug.data(), "unknown .eh_frame augmentation string: " + aug);
   }
   return DW_EH_PE_absptr;
@@ -211,7 +211,7 @@ bool EhReader::hasLSDA() {
   skipAugP();
 else if (c == 'R')
   readByte();
-else if (c != 'S')
+else if (c != 'B' && c != 'S')
   failOn(aug.data(), "unknown .eh_frame augmentation string: " + aug);
   }
   return false;

diff  --git a/lld/test/ELF/eh-frame-cfi-b-key.s 
b/lld/test/ELF/eh-frame-cfi-b-key.s
new file mode 100644
index ..406674e8b5c8
--- /dev/null
+++ b/lld/test/ELF/eh-frame-cfi-b-key.s
@@ -0,0 +1,9 @@
+// REQUIRES: aarch64
+// RUN: llvm-mc -filetype=obj -triple aarch64-arm-none-eabi %s -o %t.o
+// RUN: ld.lld %t.o -o %t --icf=all --eh-frame-hdr
+
+.globl _start
+_start:
+.cfi_startproc
+.cfi_b_key_frame
+.cfi_endproc



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] 6dc3c11 - scudo: Update a comment to match the Linux kernel behavior. NFCI.

2021-01-05 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2021-01-05T19:51:47-08:00
New Revision: 6dc3c117a30744f3fcff5297ef702c1773d9328e

URL: 
https://github.com/llvm/llvm-project/commit/6dc3c117a30744f3fcff5297ef702c1773d9328e
DIFF: 
https://github.com/llvm/llvm-project/commit/6dc3c117a30744f3fcff5297ef702c1773d9328e.diff

LOG: scudo: Update a comment to match the Linux kernel behavior. NFCI.

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/include/scudo/interface.h

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/include/scudo/interface.h 
b/compiler-rt/lib/scudo/standalone/include/scudo/interface.h
index 0736af1f2dc2..68029e4857a3 100644
--- a/compiler-rt/lib/scudo/standalone/include/scudo/interface.h
+++ b/compiler-rt/lib/scudo/standalone/include/scudo/interface.h
@@ -40,10 +40,11 @@ typedef void (*iterate_callback)(uintptr_t base, size_t 
size, void *arg);
 // the version in the process that analyzes the crash.
 //
 // fault_addr is the fault address. On aarch64 this is available in the system
-// register FAR_ELx, or far_context.far in an upcoming release of the Linux
-// kernel. This address must include the pointer tag; note that the kernel
-// strips the tag from the fields siginfo.si_addr and sigcontext.fault_address,
-// so these addresses are not suitable to be passed as fault_addr.
+// register FAR_ELx, or siginfo.si_addr in Linux 5.11 or above. This address
+// must include the pointer tag; this is available if SA_EXPOSE_TAGBITS was set
+// in sigaction.sa_flags when the signal handler was registered. Note that the
+// kernel strips the tag from the field sigcontext.fault_address, so this
+// address is not suitable to be passed as fault_addr.
 //
 // stack_depot is a pointer to the stack depot data structure, which may be
 // obtained by calling the function __scudo_get_stack_depot_addr() in the



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] f21f333 - scudo: Remove positional template arguments for secondary cache. NFCI.

2020-12-14 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2020-12-14T15:40:07-08:00
New Revision: f21f3339ba315f181e195f368f2a7ecff1cee597

URL: 
https://github.com/llvm/llvm-project/commit/f21f3339ba315f181e195f368f2a7ecff1cee597
DIFF: 
https://github.com/llvm/llvm-project/commit/f21f3339ba315f181e195f368f2a7ecff1cee597.diff

LOG: scudo: Remove positional template arguments for secondary cache. NFCI.

Make these arguments named constants in the Config class instead
of being positional arguments to MapAllocatorCache. This makes the
configuration easier to follow.

Eventually we should follow suit with the other classes but this is
a start.

Differential Revision: https://reviews.llvm.org/D93251

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/allocator_config.h
compiler-rt/lib/scudo/standalone/combined.h
compiler-rt/lib/scudo/standalone/secondary.h
compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/allocator_config.h 
b/compiler-rt/lib/scudo/standalone/allocator_config.h
index cf362da4e5be..8f1757dab322 100644
--- a/compiler-rt/lib/scudo/standalone/allocator_config.h
+++ b/compiler-rt/lib/scudo/standalone/allocator_config.h
@@ -32,7 +32,13 @@ struct DefaultConfig {
   // 512KB regions
   typedef SizeClassAllocator32 Primary;
 #endif
-  typedef MapAllocator> Secondary;
+  typedef MapAllocatorCache SecondaryCache;
+  static const u32 SecondaryCacheEntriesArraySize = 32U;
+  static const u32 SecondaryCacheDefaultMaxEntriesCount = 32U;
+  static const uptr SecondaryCacheDefaultMaxEntrySize = 1UL << 19;
+  static const s32 SecondaryCacheMinReleaseToOsIntervalMs = INT32_MIN;
+  static const s32 SecondaryCacheMaxReleaseToOsIntervalMs = INT32_MAX;
+
   template  using TSDRegistryT = TSDRegistryExT; // Exclusive
 };
 
@@ -47,9 +53,13 @@ struct AndroidConfig {
   // 256KB regions
   typedef SizeClassAllocator32 Primary;
 #endif
-  // Cache blocks up to 2MB
-  typedef MapAllocator>
-  Secondary;
+  typedef MapAllocatorCache SecondaryCache;
+  static const u32 SecondaryCacheEntriesArraySize = 256U;
+  static const u32 SecondaryCacheDefaultMaxEntriesCount = 32U;
+  static const uptr SecondaryCacheDefaultMaxEntrySize = 2UL << 20;
+  static const s32 SecondaryCacheMinReleaseToOsIntervalMs = 0;
+  static const s32 SecondaryCacheMaxReleaseToOsIntervalMs = 1000;
+
   template 
   using TSDRegistryT = TSDRegistrySharedT; // Shared, max 8 TSDs.
 };
@@ -63,7 +73,13 @@ struct AndroidSvelteConfig {
   // 64KB regions
   typedef SizeClassAllocator32 Primary;
 #endif
-  typedef MapAllocator> Secondary;
+  typedef MapAllocatorCache SecondaryCache;
+  static const u32 SecondaryCacheEntriesArraySize = 16U;
+  static const u32 SecondaryCacheDefaultMaxEntriesCount = 4U;
+  static const uptr SecondaryCacheDefaultMaxEntrySize = 1UL << 18;
+  static const s32 SecondaryCacheMinReleaseToOsIntervalMs = 0;
+  static const s32 SecondaryCacheMaxReleaseToOsIntervalMs = 0;
+
   template 
   using TSDRegistryT = TSDRegistrySharedT; // Shared, max 2 TSDs.
 };
@@ -72,7 +88,7 @@ struct AndroidSvelteConfig {
 struct FuchsiaConfig {
   // 1GB Regions
   typedef SizeClassAllocator64 Primary;
-  typedef MapAllocator Secondary;
+  typedef MapAllocatorNoCache SecondaryCache;
   template 
   using TSDRegistryT = TSDRegistrySharedT; // Shared, max 8 TSDs.
 };

diff  --git a/compiler-rt/lib/scudo/standalone/combined.h 
b/compiler-rt/lib/scudo/standalone/combined.h
index e214b0158bf4..7bf108e0b5e0 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -930,7 +930,7 @@ class Allocator {
   }
 
 private:
-  using SecondaryT = typename Params::Secondary;
+  using SecondaryT = MapAllocator;
   typedef typename PrimaryT::SizeClassMap SizeClassMap;
 
   static const uptr MinAlignmentLog = SCUDO_MIN_ALIGNMENT_LOG;

diff  --git a/compiler-rt/lib/scudo/standalone/secondary.h 
b/compiler-rt/lib/scudo/standalone/secondary.h
index ff41bd3e0722..cccbeb239dae 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -70,20 +70,18 @@ class MapAllocatorNoCache {
   }
 };
 
-template 
-class MapAllocatorCache {
+template  class MapAllocatorCache {
 public:
   // Ensure the default maximum specified fits the array.
-  static_assert(DefaultMaxEntriesCount <= EntriesArraySize, "");
+  static_assert(Config::SecondaryCacheDefaultMaxEntriesCount <=
+Config::SecondaryCacheEntriesArraySize,
+"");
 
   void initLinkerInitialized(s32 ReleaseToOsInterval) {
 setOption(Option::MaxCacheEntriesCount,
-  static_cast(DefaultMaxEntriesCount));
+  static_cast(Config::SecondaryCacheDefaultMaxEntriesCount));
 setOption(Option::MaxCacheEntrySize,
-  static_cast(DefaultMaxEntrySize));
+  

[llvm-branch-commits] [compiler-rt] e22d802 - scudo: Adjust test to use correct check for primary allocations.

2020-12-17 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2020-12-17T10:42:17-08:00
New Revision: e22d802e587b8954748e2b2193195a946ba105e8

URL: 
https://github.com/llvm/llvm-project/commit/e22d802e587b8954748e2b2193195a946ba105e8
DIFF: 
https://github.com/llvm/llvm-project/commit/e22d802e587b8954748e2b2193195a946ba105e8.diff

LOG: scudo: Adjust test to use correct check for primary allocations.

canAllocate() does not take into account the header size so it does
not return the right answer in borderline cases. There was already
code handling this correctly in isTaggedAllocation() so split it out
into a separate function and call it from the test.

Furthermore the test was incorrect when MTE is enabled because MTE
does not pattern fill primary allocations. Fix it.

Differential Revision: https://reviews.llvm.org/D93437

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/tests/combined_test.cpp

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp 
b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
index 7df4594246a6..b0ab0244e877 100644
--- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
@@ -34,12 +34,7 @@ UNUSED static void disableDebuggerdMaybe() {
 }
 
 template 
-bool isTaggedAllocation(AllocatorT *Allocator, scudo::uptr Size,
-scudo::uptr Alignment) {
-  if (!Allocator->useMemoryTagging() ||
-  !scudo::systemDetectsMemoryTagFaultsTestOnly())
-return false;
-
+bool isPrimaryAllocation(scudo::uptr Size, scudo::uptr Alignment) {
   const scudo::uptr MinAlignment = 1UL << SCUDO_MIN_ALIGNMENT_LOG;
   if (Alignment < MinAlignment)
 Alignment = MinAlignment;
@@ -49,6 +44,14 @@ bool isTaggedAllocation(AllocatorT *Allocator, scudo::uptr 
Size,
   return AllocatorT::PrimaryT::canAllocate(NeededSize);
 }
 
+template 
+bool isTaggedAllocation(AllocatorT *Allocator, scudo::uptr Size,
+scudo::uptr Alignment) {
+  return Allocator->useMemoryTagging() &&
+ scudo::systemDetectsMemoryTagFaultsTestOnly() &&
+ isPrimaryAllocation(Size, Alignment);
+}
+
 template 
 void checkMemoryTaggingMaybe(AllocatorT *Allocator, void *P, scudo::uptr Size,
  scudo::uptr Alignment) {
@@ -147,9 +150,9 @@ template  static void testAllocator() {
   }
   Allocator->releaseToOS();
 
-  // Ensure that specifying PatternOrZeroFill returns a pattern-filled block in
-  // the primary allocator, and either pattern or zero filled block in the
-  // secondary.
+  // Ensure that specifying PatternOrZeroFill returns a pattern or zero filled
+  // block. The primary allocator only produces pattern filled blocks if MTE
+  // is disabled, so we only require pattern filled blocks in that case.
   Allocator->setFillContents(scudo::PatternOrZeroFill);
   for (scudo::uptr SizeLog = 0U; SizeLog <= 20U; SizeLog++) {
 for (scudo::uptr Delta = 0U; Delta <= 4U; Delta++) {
@@ -158,7 +161,8 @@ template  static void testAllocator() {
   EXPECT_NE(P, nullptr);
   for (scudo::uptr I = 0; I < Size; I++) {
 unsigned char V = (reinterpret_cast(P))[I];
-if (AllocatorT::PrimaryT::canAllocate(Size))
+if (isPrimaryAllocation(Size, 1U << MinAlignLog) &&
+!Allocator->useMemoryTagging())
   ASSERT_EQ(V, scudo::PatternFillByte);
 else
   ASSERT_TRUE(V == scudo::PatternFillByte || V == 0);



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] dfa4084 - scudo: Remove ANDROID_EXPERIMENTAL_MTE macro.

2020-12-21 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2020-12-21T10:53:24-08:00
New Revision: dfa40840e0e2fa094c5d3f441affe0785cdc8d09

URL: 
https://github.com/llvm/llvm-project/commit/dfa40840e0e2fa094c5d3f441affe0785cdc8d09
DIFF: 
https://github.com/llvm/llvm-project/commit/dfa40840e0e2fa094c5d3f441affe0785cdc8d09.diff

LOG: scudo: Remove ANDROID_EXPERIMENTAL_MTE macro.

Kernel support for MTE has been released in Linux 5.10. This means
that it is a stable API and we no longer need to make the support
conditional on a macro. We do need to provide conditional definitions
of the new macros though in order to avoid a dependency on new
kernel headers.

Differential Revision: https://reviews.llvm.org/D93513

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/linux.cpp
compiler-rt/lib/scudo/standalone/memtag.h

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/linux.cpp 
b/compiler-rt/lib/scudo/standalone/linux.cpp
index 12f3da620e12..d2464677b279 100644
--- a/compiler-rt/lib/scudo/standalone/linux.cpp
+++ b/compiler-rt/lib/scudo/standalone/linux.cpp
@@ -35,10 +35,6 @@
 #define ANDROID_PR_SET_VMA_ANON_NAME 0
 #endif
 
-#ifdef ANDROID_EXPERIMENTAL_MTE
-#include 
-#endif
-
 namespace scudo {
 
 uptr getPageSize() { return static_cast(sysconf(_SC_PAGESIZE)); }
@@ -54,7 +50,10 @@ void *map(void *Addr, uptr Size, UNUSED const char *Name, 
uptr Flags,
 MmapProt = PROT_NONE;
   } else {
 MmapProt = PROT_READ | PROT_WRITE;
-#if defined(__aarch64__) && defined(ANDROID_EXPERIMENTAL_MTE)
+#if defined(__aarch64__)
+#ifndef PROT_MTE
+#define PROT_MTE 0x20
+#endif
 if (Flags & MAP_MEMTAG)
   MmapProt |= PROT_MTE;
 #endif

diff  --git a/compiler-rt/lib/scudo/standalone/memtag.h 
b/compiler-rt/lib/scudo/standalone/memtag.h
index 4b22c727849d..c3c4f574b4fc 100644
--- a/compiler-rt/lib/scudo/standalone/memtag.h
+++ b/compiler-rt/lib/scudo/standalone/memtag.h
@@ -14,9 +14,6 @@
 #if SCUDO_LINUX
 #include 
 #include 
-#if defined(ANDROID_EXPERIMENTAL_MTE)
-#include 
-#endif
 #endif
 
 namespace scudo {
@@ -56,20 +53,28 @@ inline uint8_t extractTag(uptr Ptr) {
 #if defined(__aarch64__)
 
 inline bool systemSupportsMemoryTagging() {
-#if defined(ANDROID_EXPERIMENTAL_MTE)
-  return getauxval(AT_HWCAP2) & HWCAP2_MTE;
-#else
-  return false;
+#ifndef HWCAP2_MTE
+#define HWCAP2_MTE (1 << 18)
 #endif
+  return getauxval(AT_HWCAP2) & HWCAP2_MTE;
 }
 
 inline bool systemDetectsMemoryTagFaultsTestOnly() {
-#if defined(ANDROID_EXPERIMENTAL_MTE)
-  return (prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) & PR_MTE_TCF_MASK) !=
- PR_MTE_TCF_NONE;
-#else
-  return false;
+#ifndef PR_GET_TAGGED_ADDR_CTRL
+#define PR_GET_TAGGED_ADDR_CTRL 56
+#endif
+#ifndef PR_MTE_TCF_SHIFT
+#define PR_MTE_TCF_SHIFT 1
+#endif
+#ifndef PR_MTE_TCF_NONE
+#define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT)
+#endif
+#ifndef PR_MTE_TCF_MASK
+#define PR_MTE_TCF_MASK (3UL << PR_MTE_TCF_SHIFT)
 #endif
+  return (static_cast(
+  prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)) &
+  PR_MTE_TCF_MASK) != PR_MTE_TCF_NONE;
 }
 
 inline void disableMemoryTagChecksTestOnly() {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] 6dfe580 - scudo: Move the configuration for the primary allocator to Config. NFCI.

2020-12-22 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2020-12-22T14:54:40-08:00
New Revision: 6dfe5801e01d259d00198147b27438ffea39e59f

URL: 
https://github.com/llvm/llvm-project/commit/6dfe5801e01d259d00198147b27438ffea39e59f
DIFF: 
https://github.com/llvm/llvm-project/commit/6dfe5801e01d259d00198147b27438ffea39e59f.diff

LOG: scudo: Move the configuration for the primary allocator to Config. NFCI.

This will allow the primary and secondary allocators to share
the MaySupportMemoryTagging bool.

Differential Revision: https://reviews.llvm.org/D93728

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/allocator_config.h
compiler-rt/lib/scudo/standalone/memtag.h
compiler-rt/lib/scudo/standalone/primary32.h
compiler-rt/lib/scudo/standalone/primary64.h
compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
compiler-rt/lib/scudo/standalone/tests/primary_test.cpp

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/allocator_config.h 
b/compiler-rt/lib/scudo/standalone/allocator_config.h
index 8f1757dab322..12daaa2f6b44 100644
--- a/compiler-rt/lib/scudo/standalone/allocator_config.h
+++ b/compiler-rt/lib/scudo/standalone/allocator_config.h
@@ -25,13 +25,18 @@ namespace scudo {
 
 struct DefaultConfig {
   using SizeClassMap = DefaultSizeClassMap;
+  static const bool MaySupportMemoryTagging = false;
+
 #if SCUDO_CAN_USE_PRIMARY64
-  // 1GB Regions
-  typedef SizeClassAllocator64 Primary;
+  typedef SizeClassAllocator64 Primary;
+  static const uptr PrimaryRegionSizeLog = 30U;
 #else
-  // 512KB regions
-  typedef SizeClassAllocator32 Primary;
+  typedef SizeClassAllocator32 Primary;
+  static const uptr PrimaryRegionSizeLog = 19U;
 #endif
+  static const s32 PrimaryMinReleaseToOsIntervalMs = INT32_MIN;
+  static const s32 PrimaryMaxReleaseToOsIntervalMs = INT32_MAX;
+
   typedef MapAllocatorCache SecondaryCache;
   static const u32 SecondaryCacheEntriesArraySize = 32U;
   static const u32 SecondaryCacheDefaultMaxEntriesCount = 32U;
@@ -44,15 +49,18 @@ struct DefaultConfig {
 
 struct AndroidConfig {
   using SizeClassMap = AndroidSizeClassMap;
+  static const bool MaySupportMemoryTagging = true;
+
 #if SCUDO_CAN_USE_PRIMARY64
-  // 256MB regions
-  typedef SizeClassAllocator64
-  Primary;
+  typedef SizeClassAllocator64 Primary;
+  static const uptr PrimaryRegionSizeLog = 28U;
 #else
-  // 256KB regions
-  typedef SizeClassAllocator32 Primary;
+  typedef SizeClassAllocator32 Primary;
+  static const uptr PrimaryRegionSizeLog = 18U;
 #endif
+  static const s32 PrimaryMinReleaseToOsIntervalMs = 1000;
+  static const s32 PrimaryMaxReleaseToOsIntervalMs = 1000;
+
   typedef MapAllocatorCache SecondaryCache;
   static const u32 SecondaryCacheEntriesArraySize = 256U;
   static const u32 SecondaryCacheDefaultMaxEntriesCount = 32U;
@@ -66,13 +74,18 @@ struct AndroidConfig {
 
 struct AndroidSvelteConfig {
   using SizeClassMap = SvelteSizeClassMap;
+  static const bool MaySupportMemoryTagging = false;
+
 #if SCUDO_CAN_USE_PRIMARY64
-  // 128MB regions
-  typedef SizeClassAllocator64 Primary;
+  typedef SizeClassAllocator64 Primary;
+  static const uptr PrimaryRegionSizeLog = 27U;
 #else
-  // 64KB regions
-  typedef SizeClassAllocator32 Primary;
+  typedef SizeClassAllocator32 Primary;
+  static const uptr PrimaryRegionSizeLog = 16U;
 #endif
+  static const s32 PrimaryMinReleaseToOsIntervalMs = 1000;
+  static const s32 PrimaryMaxReleaseToOsIntervalMs = 1000;
+
   typedef MapAllocatorCache SecondaryCache;
   static const u32 SecondaryCacheEntriesArraySize = 16U;
   static const u32 SecondaryCacheDefaultMaxEntriesCount = 4U;
@@ -86,8 +99,14 @@ struct AndroidSvelteConfig {
 
 #if SCUDO_CAN_USE_PRIMARY64
 struct FuchsiaConfig {
-  // 1GB Regions
-  typedef SizeClassAllocator64 Primary;
+  using SizeClassMap = DefaultSizeClassMap;
+  static const bool MaySupportMemoryTagging = false;
+
+  typedef SizeClassAllocator64 Primary;
+  static const uptr PrimaryRegionSizeLog = 30U;
+  static const s32 PrimaryMinReleaseToOsIntervalMs = INT32_MIN;
+  static const s32 PrimaryMaxReleaseToOsIntervalMs = INT32_MAX;
+
   typedef MapAllocatorNoCache SecondaryCache;
   template 
   using TSDRegistryT = TSDRegistrySharedT; // Shared, max 8 TSDs.

diff  --git a/compiler-rt/lib/scudo/standalone/memtag.h 
b/compiler-rt/lib/scudo/standalone/memtag.h
index c3c4f574b4fc..d848e3a0b6c9 100644
--- a/compiler-rt/lib/scudo/standalone/memtag.h
+++ b/compiler-rt/lib/scudo/standalone/memtag.h
@@ -268,6 +268,11 @@ inline void setRandomTag(void *Ptr, uptr Size, uptr 
ExcludeMask,
   *TaggedEnd = storeTags(*TaggedBegin, *TaggedBegin + Size);
 }
 
+template 
+inline constexpr bool allocatorSupportsMemoryTagging() {
+  return archSupportsMemoryTagging() && Config::MaySupportMemoryTagging;
+}
+
 } // namespace scudo
 
 #endif

diff  --git a/compiler-rt/lib/scudo/standalone/primary32.h 
b/compiler-rt/lib/scudo/standalone/primary32.h
index 0db95d2e1f11.

[llvm-branch-commits] [compiler-rt] e6b3db6 - scudo: Replace the Cache argument on MapAllocator with a Config argument. NFCI.

2020-12-22 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2020-12-22T16:52:48-08:00
New Revision: e6b3db6309f201075dd97fdfb89297f481bcee6e

URL: 
https://github.com/llvm/llvm-project/commit/e6b3db6309f201075dd97fdfb89297f481bcee6e
DIFF: 
https://github.com/llvm/llvm-project/commit/e6b3db6309f201075dd97fdfb89297f481bcee6e.diff

LOG: scudo: Replace the Cache argument on MapAllocator with a Config argument. 
NFCI.

This will allow the secondary allocator to access the
MaySupportMemoryTagging bool.

Differential Revision: https://reviews.llvm.org/D93729

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/combined.h
compiler-rt/lib/scudo/standalone/secondary.h
compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/combined.h 
b/compiler-rt/lib/scudo/standalone/combined.h
index 7bf108e0b5e0..fae71ba1b84f 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -930,7 +930,7 @@ class Allocator {
   }
 
 private:
-  using SecondaryT = MapAllocator;
+  using SecondaryT = MapAllocator;
   typedef typename PrimaryT::SizeClassMap SizeClassMap;
 
   static const uptr MinAlignmentLog = SCUDO_MIN_ALIGNMENT_LOG;

diff  --git a/compiler-rt/lib/scudo/standalone/secondary.h 
b/compiler-rt/lib/scudo/standalone/secondary.h
index cccbeb239dae..063640106abb 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -245,7 +245,7 @@ template  class MapAllocatorCache {
   atomic_s32 ReleaseToOsIntervalMs;
 };
 
-template  class MapAllocator {
+template  class MapAllocator {
 public:
   void initLinkerInitialized(GlobalStats *S, s32 ReleaseToOsInterval = -1) {
 Cache.initLinkerInitialized(ReleaseToOsInterval);
@@ -295,7 +295,7 @@ template  class MapAllocator {
   void releaseToOS() { Cache.releaseToOS(); }
 
 private:
-  CacheT Cache;
+  typename Config::SecondaryCache Cache;
 
   HybridMutex Mutex;
   DoublyLinkedList InUseBlocks;
@@ -318,8 +318,8 @@ template  class MapAllocator {
 // For allocations requested with an alignment greater than or equal to a page,
 // the committed memory will amount to something close to Size - AlignmentHint
 // (pending rounding and headers).
-template 
-void *MapAllocator::allocate(uptr Size, uptr AlignmentHint,
+template 
+void *MapAllocator::allocate(uptr Size, uptr AlignmentHint,
  uptr *BlockEnd,
  FillContentsMode FillContents) {
   DCHECK_GE(Size, AlignmentHint);
@@ -410,7 +410,7 @@ void *MapAllocator::allocate(uptr Size, uptr 
AlignmentHint,
   return reinterpret_cast(Ptr + LargeBlock::getHeaderSize());
 }
 
-template  void MapAllocator::deallocate(void *Ptr) {
+template  void MapAllocator::deallocate(void *Ptr) {
   LargeBlock::Header *H = LargeBlock::getHeader(Ptr);
   const uptr Block = reinterpret_cast(H);
   const uptr CommitSize = H->BlockEnd - Block;
@@ -430,8 +430,8 @@ template  void 
MapAllocator::deallocate(void *Ptr) {
   unmap(Addr, Size, UNMAP_ALL, &Data);
 }
 
-template 
-void MapAllocator::getStats(ScopedString *Str) const {
+template 
+void MapAllocator::getStats(ScopedString *Str) const {
   Str->append(
   "Stats: MapAllocator: allocated %zu times (%zuK), freed %zu times "
   "(%zuK), remains %zu (%zuK) max %zuM\n",

diff  --git a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp 
b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
index 3c1e77987ec4..846ec8f6d6fa 100644
--- a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
@@ -19,7 +19,9 @@
 #include 
 #include 
 
-template  static void testSecondaryBasic(void) {
+template  static void testSecondaryBasic(void) {
+  using SecondaryT = scudo::MapAllocator;
+
   scudo::GlobalStats S;
   S.init();
   std::unique_ptr L(new SecondaryT);
@@ -55,7 +57,12 @@ template  static void 
testSecondaryBasic(void) {
   Str.output();
 }
 
+struct NoCacheConfig {
+  typedef scudo::MapAllocatorNoCache SecondaryCache;
+};
+
 struct TestConfig {
+  typedef scudo::MapAllocatorCache SecondaryCache;
   static const scudo::u32 SecondaryCacheEntriesArraySize = 128U;
   static const scudo::u32 SecondaryCacheDefaultMaxEntriesCount = 64U;
   static const scudo::uptr SecondaryCacheDefaultMaxEntrySize = 1UL << 20;
@@ -64,15 +71,12 @@ struct TestConfig {
 };
 
 TEST(ScudoSecondaryTest, SecondaryBasic) {
-  testSecondaryBasic>();
-  testSecondaryBasic<
-  scudo::MapAllocator>>();
-  testSecondaryBasic<
-  scudo::MapAllocator>>();
+  testSecondaryBasic();
+  testSecondaryBasic();
+  testSecondaryBasic();
 }
 
-using LargeAllocator =
-scudo::MapAllocator>;
+using LargeAllocator = scudo::MapAllocator;
 
 // This exercises a variety of combinations of size and alignment for the
 // MapAllocator. The size computation done here mimic 

[llvm-branch-commits] [compiler-rt] faac1c0 - scudo: Move the management of the UseMemoryTagging bit out of the Primary. NFCI.

2020-12-22 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2020-12-22T16:52:54-08:00
New Revision: faac1c02c802048efa17f8f6cda8f39b5584f0c6

URL: 
https://github.com/llvm/llvm-project/commit/faac1c02c802048efa17f8f6cda8f39b5584f0c6
DIFF: 
https://github.com/llvm/llvm-project/commit/faac1c02c802048efa17f8f6cda8f39b5584f0c6.diff

LOG: scudo: Move the management of the UseMemoryTagging bit out of the Primary. 
NFCI.

The primary and secondary allocators will need to share this bit,
so move the management of the bit to the combined allocator and
make useMemoryTagging() a free function.

Differential Revision: https://reviews.llvm.org/D93730

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/combined.h
compiler-rt/lib/scudo/standalone/options.h
compiler-rt/lib/scudo/standalone/primary32.h
compiler-rt/lib/scudo/standalone/primary64.h
compiler-rt/lib/scudo/standalone/tests/combined_test.cpp

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/combined.h 
b/compiler-rt/lib/scudo/standalone/combined.h
index fae71ba1b84f..911c49dcc3fd 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -100,7 +100,7 @@ class Allocator {
 
   // Reset tag to 0 as this chunk may have been previously used for a 
tagged
   // user allocation.
-  if (UNLIKELY(Allocator.useMemoryTagging()))
+  if (UNLIKELY(useMemoryTagging(Allocator.Primary.Options.load(
 storeTags(reinterpret_cast(Ptr),
   reinterpret_cast(Ptr) + sizeof(QuarantineBatch));
 
@@ -161,6 +161,9 @@ class Allocator {
   Primary.Options.set(OptionBit::DeallocTypeMismatch);
 if (getFlags()->delete_size_mismatch)
   Primary.Options.set(OptionBit::DeleteSizeMismatch);
+if (allocatorSupportsMemoryTagging() &&
+systemSupportsMemoryTagging())
+  Primary.Options.set(OptionBit::UseMemoryTagging);
 Primary.Options.set(OptionBit::UseOddEvenTags);
 
 QuarantineMaxChunkSize =
@@ -240,7 +243,7 @@ class Allocator {
   }
 
   ALWAYS_INLINE void *untagPointerMaybe(void *Ptr) {
-if (Primary.SupportsMemoryTagging)
+if (allocatorSupportsMemoryTagging())
   return reinterpret_cast(
   untagPointer(reinterpret_cast(Ptr)));
 return Ptr;
@@ -367,7 +370,7 @@ class Allocator {
   //
   // When memory tagging is enabled, zeroing the contents is done as part 
of
   // setting the tag.
-  if (UNLIKELY(useMemoryTagging(Options))) {
+  if (UNLIKELY(useMemoryTagging(Options))) {
 uptr PrevUserPtr;
 Chunk::UnpackedHeader Header;
 const uptr BlockSize = PrimaryT::getSizeByClassId(ClassId);
@@ -594,7 +597,7 @@ class Allocator {
  : BlockEnd - (reinterpret_cast(OldPtr) + NewSize)) &
 Chunk::SizeOrUnusedBytesMask;
 Chunk::compareExchangeHeader(Cookie, OldPtr, &NewHeader, &OldHeader);
-if (UNLIKELY(ClassId && useMemoryTagging(Options))) {
+if (UNLIKELY(ClassId && useMemoryTagging(Options))) {
   resizeTaggedChunk(reinterpret_cast(OldTaggedPtr) + OldSize,
 reinterpret_cast(OldTaggedPtr) + NewSize,
 BlockEnd);
@@ -692,7 +695,7 @@ class Allocator {
   if (getChunkFromBlock(Block, &Chunk, &Header) &&
   Header.State == Chunk::State::Allocated) {
 uptr TaggedChunk = Chunk;
-if (useMemoryTagging(Primary.Options.load()))
+if (useMemoryTagging(Primary.Options.load()))
   TaggedChunk = loadTag(Chunk);
 Callback(TaggedChunk, getSize(reinterpret_cast(Chunk), 
&Header),
  Arg);
@@ -783,15 +786,14 @@ class Allocator {
Header.State == Chunk::State::Allocated;
   }
 
-  bool useMemoryTagging() const {
-return useMemoryTagging(Primary.Options.load());
+  bool useMemoryTaggingTestOnly() const {
+return useMemoryTagging(Primary.Options.load());
   }
-  static bool useMemoryTagging(Options Options) {
-return PrimaryT::useMemoryTagging(Options);
+  void disableMemoryTagging() {
+if (allocatorSupportsMemoryTagging())
+  Primary.Options.clear(OptionBit::UseMemoryTagging);
   }
 
-  void disableMemoryTagging() { Primary.disableMemoryTagging(); }
-
   void setTrackAllocationStacks(bool Track) {
 initThreadMaybe();
 if (Track)
@@ -823,7 +825,7 @@ class Allocator {
const char *MemoryTags, uintptr_t MemoryAddr,
size_t MemorySize) {
 *ErrorInfo = {};
-if (!PrimaryT::SupportsMemoryTagging ||
+if (!allocatorSupportsMemoryTagging() ||
 MemoryAddr + MemorySize < MemoryAddr)
   return;
 
@@ -942,7 +944,7 @@ class Allocator {
 
   static_assert(MinAlignment >= sizeof(Chunk::PackedHeader),
 "Minimal alignment must at least cover a chunk header.");
-  static_assert(!PrimaryT::SupportsMemoryTagging ||
+  static_assert(!allocatorSupport

[llvm-branch-commits] [compiler-rt] 9f8aeb0 - scudo: Split setRandomTag in two. NFCI.

2020-12-09 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2020-12-09T11:48:41-08:00
New Revision: 9f8aeb0602935f7bb49fb093fedaad5ec4e87497

URL: 
https://github.com/llvm/llvm-project/commit/9f8aeb0602935f7bb49fb093fedaad5ec4e87497
DIFF: 
https://github.com/llvm/llvm-project/commit/9f8aeb0602935f7bb49fb093fedaad5ec4e87497.diff

LOG: scudo: Split setRandomTag in two. NFCI.

Separate the IRG part from the STZG part since we will need to use
the latter on its own for some upcoming changes.

Differential Revision: https://reviews.llvm.org/D92880

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/memtag.h

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/memtag.h 
b/compiler-rt/lib/scudo/standalone/memtag.h
index b9f8ccd41627..4b22c727849d 100644
--- a/compiler-rt/lib/scudo/standalone/memtag.h
+++ b/compiler-rt/lib/scudo/standalone/memtag.h
@@ -21,6 +21,9 @@
 
 namespace scudo {
 
+void setRandomTag(void *Ptr, uptr Size, uptr ExcludeMask, uptr *TaggedBegin,
+  uptr *TaggedEnd);
+
 #if defined(__aarch64__) || defined(SCUDO_FUZZ)
 
 inline constexpr bool archSupportsMemoryTagging() { return true; }
@@ -91,37 +94,32 @@ class ScopedDisableMemoryTagChecks {
   }
 };
 
-inline void setRandomTag(void *Ptr, uptr Size, uptr ExcludeMask,
- uptr *TaggedBegin, uptr *TaggedEnd) {
-  void *End;
+inline uptr selectRandomTag(uptr Ptr, uptr ExcludeMask) {
+  uptr TaggedPtr;
   __asm__ __volatile__(
-  R"(
-.arch_extension mte
-
-// Set a random tag for Ptr in TaggedPtr. This needs to happen even if
-// Size = 0 so that TaggedPtr ends up pointing at a valid address.
-irg %[TaggedPtr], %[Ptr], %[ExcludeMask]
-mov %[Cur], %[TaggedPtr]
-
-// Skip the loop if Size = 0. We don't want to do any tagging in this case.
-cbz %[Size], 2f
-
-// Set the memory tag of the region
-// [TaggedPtr, TaggedPtr + roundUpTo(Size, 16))
-// to the pointer tag stored in TaggedPtr.
-add %[End], %[TaggedPtr], %[Size]
-
-  1:
-stzg %[Cur], [%[Cur]], #16
-cmp %[Cur], %[End]
-b.lt 1b
+  ".arch_extension mte; irg %[TaggedPtr], %[Ptr], %[ExcludeMask]"
+  : [TaggedPtr] "=r"(TaggedPtr)
+  : [Ptr] "r"(Ptr), [ExcludeMask] "r"(ExcludeMask));
+  return TaggedPtr;
+}
 
-  2:
-  )"
-  :
-  [TaggedPtr] "=&r"(*TaggedBegin), [Cur] "=&r"(*TaggedEnd), [End] 
"=&r"(End)
-  : [Ptr] "r"(Ptr), [Size] "r"(Size), [ExcludeMask] "r"(ExcludeMask)
-  : "memory");
+inline uptr storeTags(uptr Begin, uptr End) {
+  DCHECK(Begin % 16 == 0);
+  if (Begin != End) {
+__asm__ __volatile__(
+R"(
+  .arch_extension mte
+
+1:
+  stzg %[Cur], [%[Cur]], #16
+  cmp %[Cur], %[End]
+  b.lt 1b
+)"
+: [Cur] "+&r"(Begin)
+: [End] "r"(End)
+: "memory");
+  }
+  return Begin;
 }
 
 inline void *prepareTaggedChunk(void *Ptr, uptr Size, uptr ExcludeMask,
@@ -224,13 +222,15 @@ struct ScopedDisableMemoryTagChecks {
   ScopedDisableMemoryTagChecks() {}
 };
 
-inline void setRandomTag(void *Ptr, uptr Size, uptr ExcludeMask,
- uptr *TaggedBegin, uptr *TaggedEnd) {
+inline uptr selectRandomTag(uptr Ptr, uptr ExcludeMask) {
   (void)Ptr;
-  (void)Size;
   (void)ExcludeMask;
-  (void)TaggedBegin;
-  (void)TaggedEnd;
+  UNREACHABLE("memory tagging not supported");
+}
+
+inline uptr storeTags(uptr Begin, uptr End) {
+  (void)Begin;
+  (void)End;
   UNREACHABLE("memory tagging not supported");
 }
 
@@ -257,6 +257,12 @@ inline uptr loadTag(uptr Ptr) {
 
 #endif
 
+inline void setRandomTag(void *Ptr, uptr Size, uptr ExcludeMask,
+ uptr *TaggedBegin, uptr *TaggedEnd) {
+  *TaggedBegin = selectRandomTag(reinterpret_cast(Ptr), ExcludeMask);
+  *TaggedEnd = storeTags(*TaggedBegin, *TaggedBegin + Size);
+}
+
 } // namespace scudo
 
 #endif



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] e5a28e1 - scudo: Fix quarantine allocation when MTE enabled.

2020-12-09 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2020-12-09T11:48:41-08:00
New Revision: e5a28e1261a0c42821cb3bd4dc40092c458fadfb

URL: 
https://github.com/llvm/llvm-project/commit/e5a28e1261a0c42821cb3bd4dc40092c458fadfb
DIFF: 
https://github.com/llvm/llvm-project/commit/e5a28e1261a0c42821cb3bd4dc40092c458fadfb.diff

LOG: scudo: Fix quarantine allocation when MTE enabled.

Quarantines have always been broken when MTE is enabled because the
quarantine batch allocator fails to reset tags that may have been
left behind by a user allocation.

This was only noticed when running the Scudo unit tests with Scudo
as the system allocator because quarantines are turned off by
default on Android and the test binary turns them on by defining
__scudo_default_options, which affects the system allocator as well.

Differential Revision: https://reviews.llvm.org/D92881

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/combined.h

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/combined.h 
b/compiler-rt/lib/scudo/standalone/combined.h
index 2a891e44579a..95988443d5b3 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -98,6 +98,12 @@ class Allocator {
   Header.State = Chunk::State::Allocated;
   Chunk::storeHeader(Allocator.Cookie, Ptr, &Header);
 
+  // Reset tag to 0 as this chunk may have been previously used for a 
tagged
+  // user allocation.
+  if (UNLIKELY(Allocator.useMemoryTagging()))
+storeTags(reinterpret_cast(Ptr),
+  reinterpret_cast(Ptr) + sizeof(QuarantineBatch));
+
   return Ptr;
 }
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] a779050 - scudo: Shrink secondary header and cache entry size by a word on Linux. NFCI.

2020-12-09 Thread Peter Collingbourne via llvm-branch-commits

Author: Peter Collingbourne
Date: 2020-12-09T14:14:49-08:00
New Revision: a7790508522fc277963df974dc95308e3c11

URL: 
https://github.com/llvm/llvm-project/commit/a7790508522fc277963df974dc95308e3c11
DIFF: 
https://github.com/llvm/llvm-project/commit/a7790508522fc277963df974dc95308e3c11.diff

LOG: scudo: Shrink secondary header and cache entry size by a word on Linux. 
NFCI.

Normally compilers will allocate space for struct fields even if the
field is an empty struct. Use the [[no_unique_address]] attribute to
suppress that behavior. This attribute that was introduced in C++20,
but compilers that do not support [[no_unique_address]] will ignore
it since it uses C++11 attribute syntax.

Differential Revision: https://reviews.llvm.org/D92966

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/secondary.h

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/secondary.h 
b/compiler-rt/lib/scudo/standalone/secondary.h
index eda88862cb07..ff41bd3e0722 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -31,7 +31,7 @@ struct Header {
   uptr BlockEnd;
   uptr MapBase;
   uptr MapSize;
-  MapPlatformData Data;
+  [[no_unique_address]] MapPlatformData Data;
 };
 
 constexpr uptr getHeaderSize() {
@@ -232,7 +232,7 @@ class MapAllocatorCache {
 uptr BlockEnd;
 uptr MapBase;
 uptr MapSize;
-MapPlatformData Data;
+[[no_unique_address]] MapPlatformData Data;
 u64 Time;
   };
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-03-24 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/132857

On most operating systems, the x16 and x17 registers are not special,
so there is no benefit, and only a code size cost, to constraining AUT
to only using them. Therefore, adjust the backend to only use the AUT
pseudo (renamed AUTx16x17 for clarity) on Darwin platforms, or if traps
are requested. All other platforms use the unconstrained variant of the
instruction for selection.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-05 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132291

>From 89ce369ab9b49b8c23a87ad0a888002dd85c094c Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 20 Mar 2025 15:12:39 -0700
Subject: [PATCH] Format

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 630b90c9d77a6..927f8958f4b43 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,8 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = 'execute_mi' in gdb.__dict__
+has_execute_mi = "execute_mi" in gdb.__dict__
+
 
 class CheckResult(gdb.Command):
 def __init__(self):

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-04-05 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132857


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] MachineInstrBuilder: Introduce copyMIMetadata() function. (PR #133535)

2025-04-05 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/133535

This reduces the amount of boilerplate required when adding a new
field to MIMetadata and reduces the chance of bugs like the
one I fixed in TargetInstrInfo::reassociateOps.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] gn build: Add check-builtins target. (PR #134482)

2025-04-04 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/134482

>From bc8dda56bcfadc6d7312b53313159a978d71f4fb Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Fri, 4 Apr 2025 22:10:52 -0700
Subject: [PATCH] Remove unnecessary code

Created using spr 1.3.6-beta.1
---
 .../gn/secondary/compiler-rt/test/builtins/BUILD.gn | 13 -
 1 file changed, 13 deletions(-)

diff --git a/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn 
b/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
index 20618fb8da360..87848075a804e 100644
--- a/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
@@ -6,18 +6,6 @@ import("//llvm/utils/gn/build/toolchain/compiler.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
 import("//llvm/version.gni")
 
-if (current_toolchain == host_toolchain) {
-  write_cmake_config("builtins_cfg") {
-input = "lit.site.cfg.py.in"
-output = "$target_gen_dir/lit.site.cfg.py"
-values = [
-  "BUILTINS_LIT_SOURCE_DIR=" + rebase_path("."),
-  "COMPILER_RT_BINARY_DIR=" + rebase_path("$root_gen_dir/compiler-rt"),
-  "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",
-]
-  }
-}
-
 write_cmake_config("builtins_mode_cfg") {
   input = "Unit/lit.site.cfg.py.in"
   output =
@@ -54,7 +42,6 @@ write_cmake_config("builtins_mode_cfg") {
 if (current_toolchain != host_toolchain) {
   group("builtins_toolchain") {
 deps = [
-  ":builtins_cfg($host_toolchain)",
   ":builtins_mode_cfg",
   "//compiler-rt/include($host_toolchain)",
   "//compiler-rt/lib/builtins",

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] gn build: Add check-builtins target. (PR #134482)

2025-04-04 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/134482

Tested on aarch64 Linux and x86_64 Linux.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-04 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/132291

The existing version check can lead to test failures on some distribution
packages of gdb where not all components of the version number are
integers, such as Fedora where gdb.VERSION can be something like
"15.2-4.fc41". Fix it by replacing the version check with a feature check.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-07 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530

>From b37a44fff650b06eda249060277d0c007226cad2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 3 Apr 2025 21:51:44 -0700
Subject: [PATCH] Fix CMake build

Created using spr 1.3.6-beta.1
---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 8 +++-
 compiler-rt/cmake/builtin-config-ix.cmake | 1 +
 compiler-rt/lib/builtins/CMakeLists.txt   | 8 ++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..2f6fd4ba1e4c9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -172,7 +172,7 @@ function(add_compiler_rt_runtime name type)
   cmake_parse_arguments(LIB
 ""
 "PARENT_TARGET"
-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS;C_STANDARD;CXX_STANDARD"
 ${ARGN})
   set(libnames)
   # Until we support this some other way, build compiler-rt runtime without LTO
@@ -360,6 +360,12 @@ function(add_compiler_rt_runtime name type)
   set_target_link_flags(${libname} ${extra_link_flags_${libname}})
   set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+  if(LIB_C_STANDARD)
+set_property(TARGET ${libname} PROPERTY C_STANDARD ${LIB_C_STANDARD})
+  endif()
+  if(LIB_CXX_STANDARD)
+set_property(TARGET ${libname} PROPERTY CXX_STANDARD 
${LIB_CXX_STANDARD})
+  endif()
   set_target_output_directories(${libname} ${output_dir_${libname}})
   install(TARGETS ${libname}
 ARCHIVE DESTINATION ${install_dir_${libname}}
diff --git a/compiler-rt/cmake/builtin-config-ix.cmake 
b/compiler-rt/cmake/builtin-config-ix.cmake
index 7bd3269bd999d..7bdd30ee67f3d 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -26,6 +26,7 @@ builtin_check_c_compiler_flag("-Xclang 
-mcode-object-version=none" COMPILER_RT_H
 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch 
COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
 builtin_check_c_compiler_flag(-fcf-protection=full 
COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
+builtin_check_c_compiler_flag(-nostdinc++  
COMPILER_RT_HAS_NOSTDINCXX_FLAG)
 
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
 "
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index e6c3273eb2859..ca5cc7d218223 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -6,7 +6,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
   set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  project(CompilerRTBuiltins C ASM)
+  project(CompilerRTBuiltins C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
 
@@ -64,6 +64,8 @@ include(CMakePushCheckState)
 option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
   "Do not export any symbols from the static library." ON)
 
+include_directories(../../../third-party/siphash/include)
+
 # TODO: Need to add a mechanism for logging errors when builtin source files 
are
 # added to a sub-directory and not this CMakeLists file.
 set(GENERIC_SOURCES
@@ -803,7 +805,7 @@ else ()
 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
-  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
+  append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ BUILTIN_CFLAGS)
   append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG 
-Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)
 
   # Don't embed directives for picking any specific CRT
@@ -918,6 +920,8 @@ else ()
   SOURCES ${${arch}_SOURCES}
   DEFS ${BUILTIN_DEFS}
   CFLAGS ${BUILTIN_CFLAGS_${arch}}
+  C_STANDARD 11
+  CXX_STANDARD 17
   PARENT_TARGET builtins)
   cmake_pop_check_state()
 endif ()

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-07 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530

>From b37a44fff650b06eda249060277d0c007226cad2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 3 Apr 2025 21:51:44 -0700
Subject: [PATCH] Fix CMake build

Created using spr 1.3.6-beta.1
---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 8 +++-
 compiler-rt/cmake/builtin-config-ix.cmake | 1 +
 compiler-rt/lib/builtins/CMakeLists.txt   | 8 ++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..2f6fd4ba1e4c9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -172,7 +172,7 @@ function(add_compiler_rt_runtime name type)
   cmake_parse_arguments(LIB
 ""
 "PARENT_TARGET"
-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS;C_STANDARD;CXX_STANDARD"
 ${ARGN})
   set(libnames)
   # Until we support this some other way, build compiler-rt runtime without LTO
@@ -360,6 +360,12 @@ function(add_compiler_rt_runtime name type)
   set_target_link_flags(${libname} ${extra_link_flags_${libname}})
   set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+  if(LIB_C_STANDARD)
+set_property(TARGET ${libname} PROPERTY C_STANDARD ${LIB_C_STANDARD})
+  endif()
+  if(LIB_CXX_STANDARD)
+set_property(TARGET ${libname} PROPERTY CXX_STANDARD 
${LIB_CXX_STANDARD})
+  endif()
   set_target_output_directories(${libname} ${output_dir_${libname}})
   install(TARGETS ${libname}
 ARCHIVE DESTINATION ${install_dir_${libname}}
diff --git a/compiler-rt/cmake/builtin-config-ix.cmake 
b/compiler-rt/cmake/builtin-config-ix.cmake
index 7bd3269bd999d..7bdd30ee67f3d 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -26,6 +26,7 @@ builtin_check_c_compiler_flag("-Xclang 
-mcode-object-version=none" COMPILER_RT_H
 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch 
COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
 builtin_check_c_compiler_flag(-fcf-protection=full 
COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
+builtin_check_c_compiler_flag(-nostdinc++  
COMPILER_RT_HAS_NOSTDINCXX_FLAG)
 
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
 "
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index e6c3273eb2859..ca5cc7d218223 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -6,7 +6,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
   set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  project(CompilerRTBuiltins C ASM)
+  project(CompilerRTBuiltins C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
 
@@ -64,6 +64,8 @@ include(CMakePushCheckState)
 option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
   "Do not export any symbols from the static library." ON)
 
+include_directories(../../../third-party/siphash/include)
+
 # TODO: Need to add a mechanism for logging errors when builtin source files 
are
 # added to a sub-directory and not this CMakeLists file.
 set(GENERIC_SOURCES
@@ -803,7 +805,7 @@ else ()
 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
-  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
+  append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ BUILTIN_CFLAGS)
   append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG 
-Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)
 
   # Don't embed directives for picking any specific CRT
@@ -918,6 +920,8 @@ else ()
   SOURCES ${${arch}_SOURCES}
   DEFS ${BUILTIN_DEFS}
   CFLAGS ${BUILTIN_CFLAGS_${arch}}
+  C_STANDARD 11
+  CXX_STANDARD 17
   PARENT_TARGET builtins)
   cmake_pop_check_state()
 endif ()

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] gn build: Add check-builtins target. (PR #134482)

2025-04-07 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/134482

>From bc8dda56bcfadc6d7312b53313159a978d71f4fb Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Fri, 4 Apr 2025 22:10:52 -0700
Subject: [PATCH] Remove unnecessary code

Created using spr 1.3.6-beta.1
---
 .../gn/secondary/compiler-rt/test/builtins/BUILD.gn | 13 -
 1 file changed, 13 deletions(-)

diff --git a/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn 
b/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
index 20618fb8da360..87848075a804e 100644
--- a/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
@@ -6,18 +6,6 @@ import("//llvm/utils/gn/build/toolchain/compiler.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
 import("//llvm/version.gni")
 
-if (current_toolchain == host_toolchain) {
-  write_cmake_config("builtins_cfg") {
-input = "lit.site.cfg.py.in"
-output = "$target_gen_dir/lit.site.cfg.py"
-values = [
-  "BUILTINS_LIT_SOURCE_DIR=" + rebase_path("."),
-  "COMPILER_RT_BINARY_DIR=" + rebase_path("$root_gen_dir/compiler-rt"),
-  "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",
-]
-  }
-}
-
 write_cmake_config("builtins_mode_cfg") {
   input = "Unit/lit.site.cfg.py.in"
   output =
@@ -54,7 +42,6 @@ write_cmake_config("builtins_mode_cfg") {
 if (current_toolchain != host_toolchain) {
   group("builtins_toolchain") {
 deps = [
-  ":builtins_cfg($host_toolchain)",
   ":builtins_mode_cfg",
   "//compiler-rt/include($host_toolchain)",
   "//compiler-rt/lib/builtins",

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133531


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc edited https://github.com/llvm/llvm-project/pull/133531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] gn build: Add hwasan_preinit.cpp to hwasan static library to match CMake. (PR #134942)

2025-04-08 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/134942

None


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] gn build: Replace ${hwasan_name}-preinit with hwasan-preinit. (PR #134943)

2025-04-08 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/134943

The driver only ever looks for the latter.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] gn build: Enable check-hwasan on aarch64 Linux. (PR #134944)

2025-04-08 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/134944

None


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Change python to python3 in some shebangs. (PR #134945)

2025-04-08 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/134945

None


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Add pointer field protection feature. (PR #133538)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits


@@ -1215,6 +1215,29 @@ typedef __char32_t char32_t;
 #define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0
 #  endif
 
+#  if __has_feature(pointer_field_protection)
+// Force a class to be non-standard layout by giving it two bases with the same
+// type. This is useful when structure protection is enabled because structure
+// protection cannot be applied to standard layout classes. We may use this in
+// cases where the standard does not specify whether a standard library class 
is
+// standard layout. See C++2a [class]p7:
+//   A class S is a standard-layout class if it:
+// -- has at most one base class subobject of any given type
+_LIBCPP_BEGIN_NAMESPACE_STD
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winaccessible-base")
+class __force_nonstandard_layout_base1 {};
+class __force_nonstandard_layout_base2 : __force_nonstandard_layout_base1 {};
+class __force_nonstandard_layout : __force_nonstandard_layout_base1, 
__force_nonstandard_layout_base2 {};
+_LIBCPP_DIAGNOSTIC_POP
+_LIBCPP_END_NAMESPACE_STD

pcc wrote:

Correct, I later found that adding this caused some `check-libcxx` test 
failures with my feature enabled so I ended up splitting this into a separate 
header.

https://github.com/llvm/llvm-project/pull/133538
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Add pointer field protection feature. (PR #133538)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc commented:

> in libc++ we have a pre-commit CI so this feature should be tested in our CI, 
> if you need help with that, best reach out to us on Discord. However I think 
> we first need to look at how we can properly integrate this in libc++.

Sure, I will get in touch once this is closer to landing (everything else in 
https://github.com/orgs/llvm/projects/38 needs to land first). So far I've been 
running the libc++ test suite manually with some hand written cfg files but it 
would be good to get everything hooked up so that the tests can run in CI as 
well.

> I'm not fond of this patch since it mixes LLVM, Clang, and libc++(abi) code. 
> This makes it hard to determine when all reviewer groups are satisfied. Is 
> there a reason why the libc++ and the libc++abi part can't be in two separate 
> patches?

No problem, I'll split up the libc++ and libc++abi parts into separate patches 
the next time I upload.

> (I don't know whether it makes sense to keep the LLVM & Clang part in one 
> patch.)

That would make sense, the changes that add the new LLVM intrinsic can be made 
a prerequisite of the Clang changes.

https://github.com/llvm/llvm-project/pull/133538
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Add pointer field protection feature. (PR #133538)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits


@@ -1215,6 +1215,29 @@ typedef __char32_t char32_t;
 #define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0
 #  endif
 
+#  if __has_feature(pointer_field_protection)

pcc wrote:

Makes sense, will do.

https://github.com/llvm/llvm-project/pull/133538
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Add pointer field protection feature. (PR #133538)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc edited https://github.com/llvm/llvm-project/pull/133538
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Remove lock from MTE global relocation handling code. (PR #135123)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/135123

This lock is unnecessary because we can add the relocations to
shards and let them be sorted later.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132857


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132291

>From 89ce369ab9b49b8c23a87ad0a888002dd85c094c Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 20 Mar 2025 15:12:39 -0700
Subject: [PATCH 1/2] Format

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 630b90c9d77a6..927f8958f4b43 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,8 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = 'execute_mi' in gdb.__dict__
+has_execute_mi = "execute_mi" in gdb.__dict__
+
 
 class CheckResult(gdb.Command):
 def __init__(self):

>From da2f682a8f1a1af58fbe85f760e1844c808b8093 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Tue, 8 Apr 2025 13:21:06 -0700
Subject: [PATCH 2/2] Use getattr instead

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 927f8958f4b43..da09092b690c4 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,7 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = "execute_mi" in gdb.__dict__
+has_execute_mi = getattr(gdb, "execute_mi", None) is not None
 
 
 class CheckResult(gdb.Command):

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

> This patch has a few problems
> 
> * The check in `processAux` was moved to the wrong place (it will never get 
> hit because this is after we deal with all symbols not defined locally). This 
> patch moves it to approximately the right place but will need some logic 
> changes to `isStaticLinkTimeConstant` to recognize ifuncs as not being static 
> link time constants:
> 
> ```
> diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
> index 1439fd859f51..969d71461cb1 100644
> --- a/lld/ELF/Relocations.cpp
> +++ b/lld/ELF/Relocations.cpp
> @@ -1127,6 +1127,8 @@ void RelocationScanner::processAux(RelExpr expr, 
> RelType type, uint64_t offset,
>// handling of GOT-generating relocations.
>if (isStaticLinkTimeConstant(expr, type, sym, offset) ||
>(!ctx.arg.isPic && sym.isUndefWeak())) {
> +if (LLVM_UNLIKELY(isIfunc && !needsGot(expr) && !needsPlt(expr)))
> +  sym.setFlags(HAS_DIRECT_RELOC);
>  sec->addReloc({expr, type, offset, addend, &sym});
>  return;
>}
> @@ -1194,9 +1196,6 @@ void RelocationScanner::processAux(RelExpr expr, 
> RelType type, uint64_t offset,
>  }
>}
>  
> -  if (LLVM_UNLIKELY(isIfunc && !needsGot(expr) && !needsPlt(expr)))
> -sym.setFlags(HAS_DIRECT_RELOC);
> -
>// When producing an executable, we can perform copy relocations (for
>// STT_OBJECT) and canonical PLT (for STT_FUNC) if sym is defined by a DSO.
>// Copy relocations/canonical PLT entries are unsupported for
> ```
> 
> * Need to adjust how IRELATIVE relocations get emitted. Currently we emit 
> relocations with the wrong type (assuming they will be demoted) and fix up 
> the type in `RelocationBaseSection::partitionRels` if they turn out to not be 
> demoted. But this isn't good enough for PDEs which need them to be static 
> relocations. Here's what I think we should do instead:
>   
>   * Always emit ifunc relocations as IRELATIVE during `processAux`
>   * In `handleNonPreemptibleIfunc`, when we demote an ifunc to an iplt entry, 
> loop over all irelatives pointing to the symbol and rewrite them as either 
> relative (for PIE/shared) or static relocations (for PDE). It's fine to loop 
> over the irelatives every time because they are rare.

All of this is done in the latest change (except that I decided to handle the 
demotion in a separate loop instead of `handleNonPreemptibleIfunc`, PTAL

https://github.com/llvm/llvm-project/pull/133531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132857


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530

>From b37a44fff650b06eda249060277d0c007226cad2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 3 Apr 2025 21:51:44 -0700
Subject: [PATCH] Fix CMake build

Created using spr 1.3.6-beta.1
---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 8 +++-
 compiler-rt/cmake/builtin-config-ix.cmake | 1 +
 compiler-rt/lib/builtins/CMakeLists.txt   | 8 ++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..2f6fd4ba1e4c9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -172,7 +172,7 @@ function(add_compiler_rt_runtime name type)
   cmake_parse_arguments(LIB
 ""
 "PARENT_TARGET"
-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS;C_STANDARD;CXX_STANDARD"
 ${ARGN})
   set(libnames)
   # Until we support this some other way, build compiler-rt runtime without LTO
@@ -360,6 +360,12 @@ function(add_compiler_rt_runtime name type)
   set_target_link_flags(${libname} ${extra_link_flags_${libname}})
   set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+  if(LIB_C_STANDARD)
+set_property(TARGET ${libname} PROPERTY C_STANDARD ${LIB_C_STANDARD})
+  endif()
+  if(LIB_CXX_STANDARD)
+set_property(TARGET ${libname} PROPERTY CXX_STANDARD 
${LIB_CXX_STANDARD})
+  endif()
   set_target_output_directories(${libname} ${output_dir_${libname}})
   install(TARGETS ${libname}
 ARCHIVE DESTINATION ${install_dir_${libname}}
diff --git a/compiler-rt/cmake/builtin-config-ix.cmake 
b/compiler-rt/cmake/builtin-config-ix.cmake
index 7bd3269bd999d..7bdd30ee67f3d 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -26,6 +26,7 @@ builtin_check_c_compiler_flag("-Xclang 
-mcode-object-version=none" COMPILER_RT_H
 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch 
COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
 builtin_check_c_compiler_flag(-fcf-protection=full 
COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
+builtin_check_c_compiler_flag(-nostdinc++  
COMPILER_RT_HAS_NOSTDINCXX_FLAG)
 
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
 "
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index e6c3273eb2859..ca5cc7d218223 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -6,7 +6,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
   set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  project(CompilerRTBuiltins C ASM)
+  project(CompilerRTBuiltins C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
 
@@ -64,6 +64,8 @@ include(CMakePushCheckState)
 option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
   "Do not export any symbols from the static library." ON)
 
+include_directories(../../../third-party/siphash/include)
+
 # TODO: Need to add a mechanism for logging errors when builtin source files 
are
 # added to a sub-directory and not this CMakeLists file.
 set(GENERIC_SOURCES
@@ -803,7 +805,7 @@ else ()
 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
-  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
+  append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ BUILTIN_CFLAGS)
   append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG 
-Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)
 
   # Don't embed directives for picking any specific CRT
@@ -918,6 +920,8 @@ else ()
   SOURCES ${${arch}_SOURCES}
   DEFS ${BUILTIN_DEFS}
   CFLAGS ${BUILTIN_CFLAGS_${arch}}
+  C_STANDARD 11
+  CXX_STANDARD 17
   PARENT_TARGET builtins)
   cmake_pop_check_state()
 endif ()

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Extract SipHash implementation into a header. (PR #134197)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/134197


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Extract SipHash implementation into a header. (PR #134197)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/134197


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133531


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133531

>From 96e7da9a083888683c2ba00d97f886fd748ea10b Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 9 Apr 2025 20:30:57 -0700
Subject: [PATCH] Undo unnecessary change

Created using spr 1.3.6-beta.1
---
 lld/ELF/SyntheticSections.cpp | 2 +-
 lld/ELF/SyntheticSections.h   | 2 +-
 lld/ELF/Writer.cpp| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 8cab71c4c8d94..106749e90a82b 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1696,7 +1696,7 @@ void 
RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
  sym, 0, R_ABS, addendRelType);
 }
 
-void RelocationBaseSection::mergeRels(Ctx &ctx) {
+void RelocationBaseSection::mergeRels() {
   size_t newSize = relocs.size();
   for (const auto &v : relocsVec)
 newSize += v.size();
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 7a85906e8601d..2dd4b80eb85bf 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -553,7 +553,7 @@ class RelocationBaseSection : public SyntheticSection {
   }
   size_t getSize() const override { return relocs.size() * this->entsize; }
   size_t getRelativeRelocCount() const { return numRelativeRelocs; }
-  void mergeRels(Ctx &ctx);
+  void mergeRels();
   void partitionRels();
   void finalizeContents() override;
 
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 67004055f1af5..28b24f90716b8 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2076,7 +2076,7 @@ template  void 
Writer::finalizeSections() {
 // symbol table section (dynSymTab) must be the first one.
 for (Partition &part : ctx.partitions) {
   if (part.relaDyn) {
-part.relaDyn->mergeRels(ctx);
+part.relaDyn->mergeRels();
 // Compute DT_RELACOUNT to be used by part.dynamic.
 part.relaDyn->partitionRels();
 finalizeSynthetic(ctx, part.relaDyn.get());

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

> I’m worried about the added complexity of ifunc and the extra parameter in 
> isStaticLinkTimeConstant, a key component of relocation scanning where 
> performance is critical. (Our scanning process is already noticeably slower 
> than mold’s, and these factors are contributing to the gap.)

Fair enough, I will check the performance after this patch.

> If the security hardening efforts rely on ifunc, I’d strongly suggest 
> reconsidering this approach.

It's not so much "rely" but that the alternatives have downsides that IMO end 
up making them worse than the ifunc approach.

> What’s the next PR in line?

Here is the list: https://github.com/orgs/llvm/projects/38

> If the goal of increasing ifunc adoption is to avoid updating rtld/libc, I 
> don’t see that as a practical solution, and I’d strongly push back against 
> linker changes. We should focus on improving rtld/libc instead. See: 
> https://sourceware.org/bugzilla/show_bug.cgi?id=31959";

On the contrary, I see it as more practical than the alternatives.

If avoiding upgrades were the only reason for this change, I agree with you 
that we should be looking at a static-pie based approach instead. We may even 
consider dropping #133532 as it may be possible to develop another solution 
that uses the static-pie approach.

The main reason for supporting this use case for ifuncs is to decouple the 
pointer encoding scheme (which is a compiler implementation detail) from the 
dynamic loader. For pointer field protection we have these requirements:
- Be able to use deactivation symbols to deactivate pointer encoding in other 
object files.
- Be able to use arbitrary pointer encoding schemes as part of the non-arm64 
support.

The following alternatives were considered:
- Have the compiler generate code in .init_array.0 to initialize the fields. 
This has the downside of making parts of .data.rel.ro writable which goes 
against the overall goal of improving security. Doing things this way *might* 
work if we unprotect relro, apply the pseudo-relocations and protect again, but 
this would need to be done once for the whole binary to avoid substantial 
startup overhead, and there may be restrictions such as mseal that prevent this 
from working. This is probably what I'll do if I get too much pushback from 
this approach, it looks like [glibc will support opting out of 
mseal](https://sourceware.org/pipermail/glibc-cvs/2024q3/086012.html).
- Introduce a new relocation format that would allow specifying a deactivation 
symbol (two operands to a relocation). This would introduce a substantial 
burden on linkers due to the new relocation encoding with an additional operand 
and would still not give us a flexible pointer encoding.
- Introduce new relocation types for every new encoding that may be used 
(combined with the new relocation format). This would substantially reduce our 
velocity as the new encodings would need to be agreed on by every supported 
non-arm64 psabi, as well as introducing complexity to linkers as they would 
need to know about every new relocation type used for encodings (this would be 
basically like introducing a new R_AARCH64_AUTH_ABS64/R_AARCH64_AUTH_RELATIVE 
pair every time).

https://github.com/llvm/llvm-project/pull/133531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Add pointer field protection feature. (PR #133538)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits


@@ -84,7 +84,7 @@ _LIBCPP_PUSH_MACROS
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template  */>
-class _LIBCPP_TEMPLATE_VIS vector {
+class _LIBCPP_TEMPLATE_VIS vector _LIBCPP_MAYBE_FORCE_NONSTANDARD_LAYOUT {

pcc wrote:

The intent would be that the user builds libc++.a with 
`pointer_field_protection` and statically links it into their binary. Because 
of the changes to pointer representation there are numerous other ABI 
incompatibilities. This feature is incompatible with dynamic linking so we may 
want to skip building the dynamic library if the feature is enabled.

https://github.com/llvm/llvm-project/pull/133538
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132291

>From 89ce369ab9b49b8c23a87ad0a888002dd85c094c Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 20 Mar 2025 15:12:39 -0700
Subject: [PATCH 1/2] Format

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 630b90c9d77a6..927f8958f4b43 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,8 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = 'execute_mi' in gdb.__dict__
+has_execute_mi = "execute_mi" in gdb.__dict__
+
 
 class CheckResult(gdb.Command):
 def __init__(self):

>From da2f682a8f1a1af58fbe85f760e1844c808b8093 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Tue, 8 Apr 2025 13:21:06 -0700
Subject: [PATCH 2/2] Use getattr instead

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 927f8958f4b43..da09092b690c4 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,7 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = "execute_mi" in gdb.__dict__
+has_execute_mi = getattr(gdb, "execute_mi", None) is not None
 
 
 class CheckResult(gdb.Command):

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132291

>From 89ce369ab9b49b8c23a87ad0a888002dd85c094c Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 20 Mar 2025 15:12:39 -0700
Subject: [PATCH 1/2] Format

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 630b90c9d77a6..927f8958f4b43 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,8 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = 'execute_mi' in gdb.__dict__
+has_execute_mi = "execute_mi" in gdb.__dict__
+
 
 class CheckResult(gdb.Command):
 def __init__(self):

>From da2f682a8f1a1af58fbe85f760e1844c808b8093 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Tue, 8 Apr 2025 13:21:06 -0700
Subject: [PATCH 2/2] Use getattr instead

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 927f8958f4b43..da09092b690c4 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,7 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = "execute_mi" in gdb.__dict__
+has_execute_mi = getattr(gdb, "execute_mi", None) is not None
 
 
 class CheckResult(gdb.Command):

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Remove lock from MTE global relocation handling code. (PR #135123)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/135123


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Remove lock from MTE global relocation handling code. (PR #135123)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/135123


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132291

>From 89ce369ab9b49b8c23a87ad0a888002dd85c094c Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 20 Mar 2025 15:12:39 -0700
Subject: [PATCH 1/2] Format

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 630b90c9d77a6..927f8958f4b43 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,8 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = 'execute_mi' in gdb.__dict__
+has_execute_mi = "execute_mi" in gdb.__dict__
+
 
 class CheckResult(gdb.Command):
 def __init__(self):

>From da2f682a8f1a1af58fbe85f760e1844c808b8093 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Tue, 8 Apr 2025 13:21:06 -0700
Subject: [PATCH 2/2] Use getattr instead

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 927f8958f4b43..da09092b690c4 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,7 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = "execute_mi" in gdb.__dict__
+has_execute_mi = getattr(gdb, "execute_mi", None) is not None
 
 
 class CheckResult(gdb.Command):

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc edited https://github.com/llvm/llvm-project/pull/133530
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-03-31 Thread Peter Collingbourne via llvm-branch-commits


@@ -0,0 +1,115 @@
+#include 

pcc wrote:

Correct, I forgot to add one. Will add.

https://github.com/llvm/llvm-project/pull/133530
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Add support for R_AARCH64_INST32 relocation. (PR #133534)

2025-03-31 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

> Apologies for the delay in responding, just come back from vacation. Not had 
> a chance to look through the Discourse posts yet, will do so this week.
> 
> While it may seem a bit premature, would you be able to open an issue in the 
> AArch64 ABI (https://github.com/ARM-software/abi-aa/issues) with a request to 
> add a new relocation directive, citing the Discourse posts and PRs?

Sure, created https://github.com/ARM-software/abi-aa/issues/317

https://github.com/llvm/llvm-project/pull/133534
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-01 Thread Peter Collingbourne via llvm-branch-commits


@@ -0,0 +1,7343 @@
+/*
+ * xxHash - Extremely Fast Hash algorithm
+ * Header File
+ * Copyright (C) 2012-2023 Yann Collet
+ *
+ * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)

pcc wrote:

Okay, I will contact bo...@llvm.org about this new usage.

I don't have a strong opinion about the hash algorithm. XXH3_64 was chosen for 
these reasons:
1. It was the easiest to incorporate into compiler-rt as it was already 
available as a header-only library without dependencies.
2. It was already being used in LLVM, so I imagined that licensing wouldn't be 
as much of a concern.
3. It was faster than the other algorithms according to the [xxhash 
homepage](https://xxhash.com/). BLAKE3 isn't listed there but we can 
extrapolate from [BLAKE3's claim](https://github.com/BLAKE3-team/BLAKE3) of 
being ~7x faster than BLAKE2. (I know I said elsewhere that performance is less 
of a concern for these functions, but all other things being equal, we may as 
well go with the algorithm with the best performance.)

If the board decides not to allow use in compiler-rt it should be possible to 
switch to one of the other algorithms after changing its code as needed to 
remove dependencies.

https://github.com/llvm/llvm-project/pull/133530
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-08 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132291

>From 89ce369ab9b49b8c23a87ad0a888002dd85c094c Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 20 Mar 2025 15:12:39 -0700
Subject: [PATCH 1/2] Format

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 630b90c9d77a6..927f8958f4b43 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,8 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = 'execute_mi' in gdb.__dict__
+has_execute_mi = "execute_mi" in gdb.__dict__
+
 
 class CheckResult(gdb.Command):
 def __init__(self):

>From da2f682a8f1a1af58fbe85f760e1844c808b8093 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Tue, 8 Apr 2025 13:21:06 -0700
Subject: [PATCH 2/2] Use getattr instead

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 927f8958f4b43..da09092b690c4 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,7 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = "execute_mi" in gdb.__dict__
+has_execute_mi = getattr(gdb, "execute_mi", None) is not None
 
 
 class CheckResult(gdb.Command):

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-08 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

That's just what spr does, it will be applied onto main when it lands.

On Tue, Apr 8, 2025, 23:52 Nikolas Klauser ***@***.***> wrote:

> It looks like your merge base is wrong.
>
> —
> Reply to this email directly, view it on GitHub
> ,
> or unsubscribe
> 
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
> *philnik777* left a comment (llvm/llvm-project#132291)
> 
>
> It looks like your merge base is wrong.
>
> —
> Reply to this email directly, view it on GitHub
> ,
> or unsubscribe
> 
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>


https://github.com/llvm/llvm-project/pull/132291
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-09 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

Odd, if I go to https://github.com/llvm/llvm-project/pull/132291/files in
an incognito tab it just looks like this to me and that's what would be
applied.

On Wed, Apr 9, 2025, 00:03 Nikolas Klauser ***@***.***> wrote:

> Could you not use spr in that case? I can't see the diff as it would be
> merged AFAICT.
>
> —
> Reply to this email directly, view it on GitHub
> ,
> or unsubscribe
> 
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
> *philnik777* left a comment (llvm/llvm-project#132291)
> 
>
> Could you not use spr in that case? I can't see the diff as it would be
> merged AFAICT.
>
> —
> Reply to this email directly, view it on GitHub
> ,
> or unsubscribe
> 
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>


https://github.com/llvm/llvm-project/pull/132291
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-08 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

I guess `gdb.__dict__` may not correspond to the actual attributes on the 
object because GDB could start using a custom `tp_getattro` for that object, 
although that seems unlikely. I switched to checking the result of `getattr` 
which should be equivalent to checking whether `gdb.execute_mi` would result in 
an AttributeError.

https://github.com/llvm/llvm-project/pull/132291
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Do not rewrite IFUNC relocations to point to PLT if no GOT/PLT needed. (PR #133531)

2025-04-08 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

This patch has a few problems
- The check in `processAux` was moved to the wrong place (it will never get hit 
because this is after we deal with all symbols not defined locally). This patch 
moves it to approximately the right place but will need some logic changes to 
`isStaticLinkTimeConstant` to recognize ifuncs as not being static link time 
constants:
```
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 1439fd859f51..969d71461cb1 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1127,6 +1127,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType 
type, uint64_t offset,
   // handling of GOT-generating relocations.
   if (isStaticLinkTimeConstant(expr, type, sym, offset) ||
   (!ctx.arg.isPic && sym.isUndefWeak())) {
+if (LLVM_UNLIKELY(isIfunc && !needsGot(expr) && !needsPlt(expr)))
+  sym.setFlags(HAS_DIRECT_RELOC);
 sec->addReloc({expr, type, offset, addend, &sym});
 return;
   }
@@ -1194,9 +1196,6 @@ void RelocationScanner::processAux(RelExpr expr, RelType 
type, uint64_t offset,
 }
   }
 
-  if (LLVM_UNLIKELY(isIfunc && !needsGot(expr) && !needsPlt(expr)))
-sym.setFlags(HAS_DIRECT_RELOC);
-
   // When producing an executable, we can perform copy relocations (for
   // STT_OBJECT) and canonical PLT (for STT_FUNC) if sym is defined by a DSO.
   // Copy relocations/canonical PLT entries are unsupported for
```
- Need to adjust how IRELATIVE relocations get emitted. Currently we emit 
relocations with the wrong type (assuming they will be demoted) and fix up the 
type in `RelocationBaseSection::partitionRels` if they turn out to not be 
demoted. But this isn't good enough for PDEs which need them to be static 
relocations. Here's what I think we should do instead:
  - Always emit ifunc relocations as IRELATIVE during `processAux`
  - In `handleNonPreemptibleIfunc`, when we demote an ifunc to an iplt entry, 
loop over all irelatives pointing to the symbol and rewrite them as either 
relative (for PIE/shared) or static relocations (for PDE). It's fine to loop 
over the irelatives every time because they are rare.

https://github.com/llvm/llvm-project/pull/133531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] gn build: Add check-builtins target. (PR #134482)

2025-04-07 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/134482

>From bc8dda56bcfadc6d7312b53313159a978d71f4fb Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Fri, 4 Apr 2025 22:10:52 -0700
Subject: [PATCH] Remove unnecessary code

Created using spr 1.3.6-beta.1
---
 .../gn/secondary/compiler-rt/test/builtins/BUILD.gn | 13 -
 1 file changed, 13 deletions(-)

diff --git a/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn 
b/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
index 20618fb8da360..87848075a804e 100644
--- a/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
@@ -6,18 +6,6 @@ import("//llvm/utils/gn/build/toolchain/compiler.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
 import("//llvm/version.gni")
 
-if (current_toolchain == host_toolchain) {
-  write_cmake_config("builtins_cfg") {
-input = "lit.site.cfg.py.in"
-output = "$target_gen_dir/lit.site.cfg.py"
-values = [
-  "BUILTINS_LIT_SOURCE_DIR=" + rebase_path("."),
-  "COMPILER_RT_BINARY_DIR=" + rebase_path("$root_gen_dir/compiler-rt"),
-  "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",
-]
-  }
-}
-
 write_cmake_config("builtins_mode_cfg") {
   input = "Unit/lit.site.cfg.py.in"
   output =
@@ -54,7 +42,6 @@ write_cmake_config("builtins_mode_cfg") {
 if (current_toolchain != host_toolchain) {
   group("builtins_toolchain") {
 deps = [
-  ":builtins_cfg($host_toolchain)",
   ":builtins_mode_cfg",
   "//compiler-rt/include($host_toolchain)",
   "//compiler-rt/lib/builtins",

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [MTE] do not tag zero sized globals (PR #136020)

2025-04-16 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc approved this pull request.


https://github.com/llvm/llvm-project/pull/136020
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] LiveRangeShrink: Early exit when encountering a code motion barrier. (PR #136806)

2025-04-22 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/136806

Without this, we end up with quadratic behavior affecting functions with
large numbers of code motion barriers, such as CFI jump tables.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] LiveRangeShrink: Early exit when encountering a code motion barrier. (PR #136806)

2025-04-23 Thread Peter Collingbourne via llvm-branch-commits


@@ -95,14 +95,24 @@ static MachineInstr *FindDominatedInstruction(MachineInstr 
&New,
   return Old;
 }
 
+static bool isCodeMotionBarrier(MachineInstr &MI) {
+  return MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe();
+}
+
 /// Builds Instruction to its dominating order number map \p M by traversing
 /// from instruction \p Start.
 static void BuildInstOrderMap(MachineBasicBlock::iterator Start,
   InstOrderMap &M) {
   M.clear();
   unsigned i = 0;
-  for (MachineInstr &I : make_range(Start, Start->getParent()->end()))
+  bool SawStore = false;
+  for (MachineInstr &I : make_range(Start, Start->getParent()->end())) {
+if (I.mayStore())
+  SawStore = true;
+if (!I.isSafeToMove(SawStore) && isCodeMotionBarrier(I))

pcc wrote:

Correct, updated this code to only call one.

While reading the code I observed that the code to update SawStore in this pass 
is redundant with what isSafeToMove is doing, so I removed it.

https://github.com/llvm/llvm-project/pull/136806
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

> How does this work in the non-PIE (PDE) case when we take the address of an 
> ifunc and pass it to a function in a shared library, which then compares the 
> argument with its own global address take of the ifunc?
> 
> For example: shared lib
> 
> ```
> typedef void Fptr(void);
> extern void ifn(void);
> 
> // take address of ifunc ifn defined in application
> Fptr* ifp = &ifn;
> 
> // compare address of ifn we have calculated in ifp vs
> // address calculated by application, passed in fp1.
> int compare(Fptr* fp1) {
>   return fp1 == ifp;
> }
> ```
> 
> App
> 
> ```
> typedef void Fptr(void);
> extern int compare(Fptr* fp1);
> int val = 0;
> static void impl(void) { val = 42; }
> static void *resolver(void) { return impl; }
> __attribute__((ifunc("resolver"))) void *ifn();
> 
> extern Fptr* fp;
> 
> int main(void) {
>   return compare(fp);
> }
> // separate file so compiler is unaware ifn is an ifunc.
> typedef void Fptr(void);
> extern void ifn(void);
> Fptr* fp = &ifn;
> ```
> 
> Right now in the application lld produces an iPLT entry for `ifn`, with `fp` 
> pointing to the iPLT entry. The dynamic symbol table contains the address of 
> the iPLT entry with type STT_FUNC . The shared library and the argument 
> compare equal.
> 
> As I understand it, this patch will change `fp` to point directly to the 
> result of the ifunc resolver. So unless we also change the value put into the 
> dynamic symbol table we'll stop comparing equal.
> 
> I don't think there's a STT_FUNC symbol we can put in the dynamic symbol 
> table that holds the result of the ifunc resolver. GNU ld, puts the address 
> of the resolver function with a STT_GNU_IFUNC symbol type in the dynamic 
> symbol table. If that causes the dynamic loader to call the resolver and 
> replace the value with the result then that would work. I haven't had time to 
> check what glibc does though.

If a dynamic loader sees a symbol with type `STT_GNU_IFUNC` it will indeed call 
the resolver and use the return value when resolving relocations involving that 
symbol. You can see this behavior in glibc e.g. `elf_machine_rela` function in 
`sysdeps/aarch64/dl-machine.h` and bionic in the `resolve_symbol_address` 
function in `bionic/linker/linker_soinfo.h`. So in your example we will end up 
with `resolver` being called twice: once for the `R_AARCH64_ABS64` in the `ifp` 
initializer and once for the `R_AARCH64_IRELATIVE` in the `fp` initializer. So 
the comparison should still succeed.

https://github.com/llvm/llvm-project/pull/133531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

> I have some small reservations about using ifunc resolvers like this. Mostly 
> in that we are using a mechanism invented for a different purpose, and 
> relying on some specific linker behaviour to make this case work.
>
> This is similar to comments made in the Discourse post 
> https://discourse.llvm.org/t/rfc-structure-protection-a-family-of-uaf-mitigation-techniques/8/9
>  but repeating them here as this is closest to the implementation.
>
> As I understand it, this has a more limited and more specific use case than 
> ifuncs. Traditional ifuncs which can be address taken or called, possibly in 
> multiple ways, so it makes sense to use a symbol type STT_GNU_IFUNC rather 
> than special relocation directives. The initializers for structure field 
> protection are compiler generated, can not be legally called or address taken 
> from user code, and only have one relocation type R_ABS64 (or 32 on a 32-bit 
> platform). With an addition of a single relocation, something like 
> R_ADDRINIT64 which would target a STT_FUNC resolver symbol. We can isolate 
> the structure field initialization use case from an actual ifunc.

I see, so the idea would be that an ADDRINIT64 pointing to an STT_FUNC would 
generate an IRELATIVE pointing to the symbol address if the symbol is 
non-preemptible and result in a linker error otherwise.

> I guess it all comes down to whether structure field initialization needs, or 
> benefits from being distinguished from an ifunc. Ifuncs seem to be quite easy 
> to get wrong so being able to isolate this case has some attraction to me at 
> least. It also handles the structure field that points to an ifunc relatively 
> gracefully.

I don't necessarily see usage errors as a convincing argument for ADDRINIT64. 
Because the relocations and resolvers are compiler generated (and the resolvers 
cannot be named by the user due to the use of local symbols) it is hard to 
commit a usage error if you are not a compiler developer who is expected to 
know what they are doing.

I do think that there are two convincing arguments for ADDRINIT64:
- We want linkers that do not support the new behavior to loudly error out 
instead of silently generating incorrect code. You'll note that this is the 
same argument that justifies INST32 (or whatever we end up calling it) when 
ABS32 already exists and could be made to retrofit the semantics that we want.
- It reduces linker complexity because the IRELATIVE relocations can be added 
in a single pass.

> As you pointed out in your response, this does mean adding 2 relocations to 
> every psABI that supports structure field protection rather than just one. 
> Although I'd expect the alternative of having relocations that alternatively 
> write "directly call" ifunc resolver or take address of function might 
> require new relocations too?

Yes, we'd still the relocation to select between calling the resolver and 
taking the address unless we decide to not support other use cases for the 
inner ifuncs (in which case we'd just generate code to take the address and the 
IPLT would be used as the address of affected ifuncs). This may be fine as it's 
the status quo for ifuncs referred to by an ABS64.

https://github.com/llvm/llvm-project/pull/133531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

Ping @ldionne 

https://github.com/llvm/llvm-project/pull/132291
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] LiveRangeShrink: Early exit when encountering a code motion barrier. (PR #136806)

2025-04-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc edited https://github.com/llvm/llvm-project/pull/136806
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] LiveRangeShrink: Early exit when encountering a code motion barrier. (PR #136806)

2025-04-23 Thread Peter Collingbourne via llvm-branch-commits


@@ -95,14 +95,24 @@ static MachineInstr *FindDominatedInstruction(MachineInstr 
&New,
   return Old;
 }
 
+static bool isCodeMotionBarrier(MachineInstr &MI) {
+  return MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe();
+}

pcc wrote:

Added a comment that describes the situation to the best of my understanding. I 
don't think the existing ones can be used because the condition is specific to 
what this pass is doing.

https://github.com/llvm/llvm-project/pull/136806
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] LiveRangeShrink: Early exit when encountering a code motion barrier. (PR #136806)

2025-04-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/136806


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] LiveRangeShrink: Early exit when encountering a code motion barrier. (PR #136806)

2025-04-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/136806


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-04-24 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

@asl Ping

https://github.com/llvm/llvm-project/pull/132857
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] gn build: Add check-builtins target. (PR #134482)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

> wow this is very messy, feels like there should be a better way to do this on 
> the CMake side

Yeah, or maybe even in the tests themselves, maybe they should be using weak 
symbols for the builtins and return unsupported if the symbol is undefined at 
runtime.

https://github.com/llvm/llvm-project/pull/134482
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Extract SipHash implementation into a header. (PR #134197)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/134197


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133531

>From 96e7da9a083888683c2ba00d97f886fd748ea10b Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 9 Apr 2025 20:30:57 -0700
Subject: [PATCH] Undo unnecessary change

Created using spr 1.3.6-beta.1
---
 lld/ELF/SyntheticSections.cpp | 2 +-
 lld/ELF/SyntheticSections.h   | 2 +-
 lld/ELF/Writer.cpp| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 8cab71c4c8d94..106749e90a82b 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1696,7 +1696,7 @@ void 
RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
  sym, 0, R_ABS, addendRelType);
 }
 
-void RelocationBaseSection::mergeRels(Ctx &ctx) {
+void RelocationBaseSection::mergeRels() {
   size_t newSize = relocs.size();
   for (const auto &v : relocsVec)
 newSize += v.size();
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 7a85906e8601d..2dd4b80eb85bf 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -553,7 +553,7 @@ class RelocationBaseSection : public SyntheticSection {
   }
   size_t getSize() const override { return relocs.size() * this->entsize; }
   size_t getRelativeRelocCount() const { return numRelativeRelocs; }
-  void mergeRels(Ctx &ctx);
+  void mergeRels();
   void partitionRels();
   void finalizeContents() override;
 
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 67004055f1af5..28b24f90716b8 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2076,7 +2076,7 @@ template  void 
Writer::finalizeSections() {
 // symbol table section (dynSymTab) must be the first one.
 for (Partition &part : ctx.partitions) {
   if (part.relaDyn) {
-part.relaDyn->mergeRels(ctx);
+part.relaDyn->mergeRels();
 // Compute DT_RELACOUNT to be used by part.dynamic.
 part.relaDyn->partitionRels();
 finalizeSynthetic(ctx, part.relaDyn.get());

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits


@@ -1964,6 +1979,26 @@ void elf::postScanRelocations(Ctx &ctx) {
   for (ELFFileBase *file : ctx.objectFiles)
 for (Symbol *sym : file->getLocalSymbols())
   fn(*sym);
+
+  // Now that we have checked all ifunc symbols for demotion to regular 
function
+  // symbols, move IRELATIVE relocations to the right place:
+  // - Relocations for non-demoted ifuncs are added to .rela.dyn
+  // - Relocations for demoted ifuncs are turned into RELATIVE relocations
+  //   or static relocations in PDEs

pcc wrote:

Done

https://github.com/llvm/llvm-project/pull/133531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits


@@ -42,6 +42,8 @@ void printTraceSymbol(const Symbol &sym, StringRef name);
 enum {
   NEEDS_GOT = 1 << 0,
   NEEDS_PLT = 1 << 1,
+  // True if this is an ifunc with a direct relocation that cannot be

pcc wrote:

Done

https://github.com/llvm/llvm-project/pull/133531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits


@@ -1761,6 +1761,9 @@ void RelocationBaseSection::computeRels() {
 llvm::sort(nonRelative, irelative, [&](auto &a, auto &b) {
   return std::tie(a.r_sym, a.r_offset) < std::tie(b.r_sym, b.r_offset);
 });
+llvm::sort(irelative, relocs.end(), [&](auto &a, auto &b) {

pcc wrote:

For the irelative relocations it's also needed for output determinism. Added a 
comment explaining that.

https://github.com/llvm/llvm-project/pull/133531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530

>From b37a44fff650b06eda249060277d0c007226cad2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 3 Apr 2025 21:51:44 -0700
Subject: [PATCH] Fix CMake build

Created using spr 1.3.6-beta.1
---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 8 +++-
 compiler-rt/cmake/builtin-config-ix.cmake | 1 +
 compiler-rt/lib/builtins/CMakeLists.txt   | 8 ++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..2f6fd4ba1e4c9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -172,7 +172,7 @@ function(add_compiler_rt_runtime name type)
   cmake_parse_arguments(LIB
 ""
 "PARENT_TARGET"
-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS;C_STANDARD;CXX_STANDARD"
 ${ARGN})
   set(libnames)
   # Until we support this some other way, build compiler-rt runtime without LTO
@@ -360,6 +360,12 @@ function(add_compiler_rt_runtime name type)
   set_target_link_flags(${libname} ${extra_link_flags_${libname}})
   set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+  if(LIB_C_STANDARD)
+set_property(TARGET ${libname} PROPERTY C_STANDARD ${LIB_C_STANDARD})
+  endif()
+  if(LIB_CXX_STANDARD)
+set_property(TARGET ${libname} PROPERTY CXX_STANDARD 
${LIB_CXX_STANDARD})
+  endif()
   set_target_output_directories(${libname} ${output_dir_${libname}})
   install(TARGETS ${libname}
 ARCHIVE DESTINATION ${install_dir_${libname}}
diff --git a/compiler-rt/cmake/builtin-config-ix.cmake 
b/compiler-rt/cmake/builtin-config-ix.cmake
index 7bd3269bd999d..7bdd30ee67f3d 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -26,6 +26,7 @@ builtin_check_c_compiler_flag("-Xclang 
-mcode-object-version=none" COMPILER_RT_H
 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch 
COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
 builtin_check_c_compiler_flag(-fcf-protection=full 
COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
+builtin_check_c_compiler_flag(-nostdinc++  
COMPILER_RT_HAS_NOSTDINCXX_FLAG)
 
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
 "
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index e6c3273eb2859..ca5cc7d218223 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -6,7 +6,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
   set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  project(CompilerRTBuiltins C ASM)
+  project(CompilerRTBuiltins C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
 
@@ -64,6 +64,8 @@ include(CMakePushCheckState)
 option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
   "Do not export any symbols from the static library." ON)
 
+include_directories(../../../third-party/siphash/include)
+
 # TODO: Need to add a mechanism for logging errors when builtin source files 
are
 # added to a sub-directory and not this CMakeLists file.
 set(GENERIC_SOURCES
@@ -803,7 +805,7 @@ else ()
 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
-  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
+  append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ BUILTIN_CFLAGS)
   append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG 
-Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)
 
   # Don't embed directives for picking any specific CRT
@@ -918,6 +920,8 @@ else ()
   SOURCES ${${arch}_SOURCES}
   DEFS ${BUILTIN_DEFS}
   CFLAGS ${BUILTIN_CFLAGS_${arch}}
+  C_STANDARD 11
+  CXX_STANDARD 17
   PARENT_TARGET builtins)
   cmake_pop_check_state()
 endif ()

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133531

>From 96e7da9a083888683c2ba00d97f886fd748ea10b Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 9 Apr 2025 20:30:57 -0700
Subject: [PATCH] Undo unnecessary change

Created using spr 1.3.6-beta.1
---
 lld/ELF/SyntheticSections.cpp | 2 +-
 lld/ELF/SyntheticSections.h   | 2 +-
 lld/ELF/Writer.cpp| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 8cab71c4c8d94..106749e90a82b 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1696,7 +1696,7 @@ void 
RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
  sym, 0, R_ABS, addendRelType);
 }
 
-void RelocationBaseSection::mergeRels(Ctx &ctx) {
+void RelocationBaseSection::mergeRels() {
   size_t newSize = relocs.size();
   for (const auto &v : relocsVec)
 newSize += v.size();
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 7a85906e8601d..2dd4b80eb85bf 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -553,7 +553,7 @@ class RelocationBaseSection : public SyntheticSection {
   }
   size_t getSize() const override { return relocs.size() * this->entsize; }
   size_t getRelativeRelocCount() const { return numRelativeRelocs; }
-  void mergeRels(Ctx &ctx);
+  void mergeRels();
   void partitionRels();
   void finalizeContents() override;
 
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 67004055f1af5..28b24f90716b8 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2076,7 +2076,7 @@ template  void 
Writer::finalizeSections() {
 // symbol table section (dynSymTab) must be the first one.
 for (Partition &part : ctx.partitions) {
   if (part.relaDyn) {
-part.relaDyn->mergeRels(ctx);
+part.relaDyn->mergeRels();
 // Compute DT_RELACOUNT to be used by part.dynamic.
 part.relaDyn->partitionRels();
 finalizeSynthetic(ctx, part.relaDyn.get());

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530

>From b37a44fff650b06eda249060277d0c007226cad2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 3 Apr 2025 21:51:44 -0700
Subject: [PATCH] Fix CMake build

Created using spr 1.3.6-beta.1
---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 8 +++-
 compiler-rt/cmake/builtin-config-ix.cmake | 1 +
 compiler-rt/lib/builtins/CMakeLists.txt   | 8 ++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..2f6fd4ba1e4c9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -172,7 +172,7 @@ function(add_compiler_rt_runtime name type)
   cmake_parse_arguments(LIB
 ""
 "PARENT_TARGET"
-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS;C_STANDARD;CXX_STANDARD"
 ${ARGN})
   set(libnames)
   # Until we support this some other way, build compiler-rt runtime without LTO
@@ -360,6 +360,12 @@ function(add_compiler_rt_runtime name type)
   set_target_link_flags(${libname} ${extra_link_flags_${libname}})
   set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+  if(LIB_C_STANDARD)
+set_property(TARGET ${libname} PROPERTY C_STANDARD ${LIB_C_STANDARD})
+  endif()
+  if(LIB_CXX_STANDARD)
+set_property(TARGET ${libname} PROPERTY CXX_STANDARD 
${LIB_CXX_STANDARD})
+  endif()
   set_target_output_directories(${libname} ${output_dir_${libname}})
   install(TARGETS ${libname}
 ARCHIVE DESTINATION ${install_dir_${libname}}
diff --git a/compiler-rt/cmake/builtin-config-ix.cmake 
b/compiler-rt/cmake/builtin-config-ix.cmake
index 7bd3269bd999d..7bdd30ee67f3d 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -26,6 +26,7 @@ builtin_check_c_compiler_flag("-Xclang 
-mcode-object-version=none" COMPILER_RT_H
 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch 
COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
 builtin_check_c_compiler_flag(-fcf-protection=full 
COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
+builtin_check_c_compiler_flag(-nostdinc++  
COMPILER_RT_HAS_NOSTDINCXX_FLAG)
 
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
 "
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index e6c3273eb2859..ca5cc7d218223 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -6,7 +6,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
   set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  project(CompilerRTBuiltins C ASM)
+  project(CompilerRTBuiltins C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
 
@@ -64,6 +64,8 @@ include(CMakePushCheckState)
 option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
   "Do not export any symbols from the static library." ON)
 
+include_directories(../../../third-party/siphash/include)
+
 # TODO: Need to add a mechanism for logging errors when builtin source files 
are
 # added to a sub-directory and not this CMakeLists file.
 set(GENERIC_SOURCES
@@ -803,7 +805,7 @@ else ()
 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
-  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
+  append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ BUILTIN_CFLAGS)
   append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG 
-Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)
 
   # Don't embed directives for picking any specific CRT
@@ -918,6 +920,8 @@ else ()
   SOURCES ${${arch}_SOURCES}
   DEFS ${BUILTIN_DEFS}
   CFLAGS ${BUILTIN_CFLAGS_${arch}}
+  C_STANDARD 11
+  CXX_STANDARD 17
   PARENT_TARGET builtins)
   cmake_pop_check_state()
 endif ()

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530

>From b37a44fff650b06eda249060277d0c007226cad2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 3 Apr 2025 21:51:44 -0700
Subject: [PATCH] Fix CMake build

Created using spr 1.3.6-beta.1
---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 8 +++-
 compiler-rt/cmake/builtin-config-ix.cmake | 1 +
 compiler-rt/lib/builtins/CMakeLists.txt   | 8 ++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..2f6fd4ba1e4c9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -172,7 +172,7 @@ function(add_compiler_rt_runtime name type)
   cmake_parse_arguments(LIB
 ""
 "PARENT_TARGET"
-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS;C_STANDARD;CXX_STANDARD"
 ${ARGN})
   set(libnames)
   # Until we support this some other way, build compiler-rt runtime without LTO
@@ -360,6 +360,12 @@ function(add_compiler_rt_runtime name type)
   set_target_link_flags(${libname} ${extra_link_flags_${libname}})
   set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+  if(LIB_C_STANDARD)
+set_property(TARGET ${libname} PROPERTY C_STANDARD ${LIB_C_STANDARD})
+  endif()
+  if(LIB_CXX_STANDARD)
+set_property(TARGET ${libname} PROPERTY CXX_STANDARD 
${LIB_CXX_STANDARD})
+  endif()
   set_target_output_directories(${libname} ${output_dir_${libname}})
   install(TARGETS ${libname}
 ARCHIVE DESTINATION ${install_dir_${libname}}
diff --git a/compiler-rt/cmake/builtin-config-ix.cmake 
b/compiler-rt/cmake/builtin-config-ix.cmake
index 7bd3269bd999d..7bdd30ee67f3d 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -26,6 +26,7 @@ builtin_check_c_compiler_flag("-Xclang 
-mcode-object-version=none" COMPILER_RT_H
 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch 
COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
 builtin_check_c_compiler_flag(-fcf-protection=full 
COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
+builtin_check_c_compiler_flag(-nostdinc++  
COMPILER_RT_HAS_NOSTDINCXX_FLAG)
 
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
 "
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index e6c3273eb2859..ca5cc7d218223 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -6,7 +6,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
   set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  project(CompilerRTBuiltins C ASM)
+  project(CompilerRTBuiltins C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
 
@@ -64,6 +64,8 @@ include(CMakePushCheckState)
 option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
   "Do not export any symbols from the static library." ON)
 
+include_directories(../../../third-party/siphash/include)
+
 # TODO: Need to add a mechanism for logging errors when builtin source files 
are
 # added to a sub-directory and not this CMakeLists file.
 set(GENERIC_SOURCES
@@ -803,7 +805,7 @@ else ()
 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
-  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
+  append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ BUILTIN_CFLAGS)
   append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG 
-Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)
 
   # Don't embed directives for picking any specific CRT
@@ -918,6 +920,8 @@ else ()
   SOURCES ${${arch}_SOURCES}
   DEFS ${BUILTIN_DEFS}
   CFLAGS ${BUILTIN_CFLAGS_${arch}}
+  C_STANDARD 11
+  CXX_STANDARD 17
   PARENT_TARGET builtins)
   cmake_pop_check_state()
 endif ()

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Extract SipHash implementation into a header. (PR #134197)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/134197


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132857


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-04-10 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132857


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] LowerTypeTests: Fix quadratic complexity. (PR #135875)

2025-04-15 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/135875

Currently we have quadratic complexity in LowerTypeTests because
ScopedSaveAliaseesAndUsed loops over all aliases for each disjoint
set, and the number of aliases and number of disjoint sets is
roughly proportional to the program size. Fix that by moving
ScopedSaveAliaseesAndUsed to LowerTypeTestsModule::lower() so that
we do this only once.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] LowerTypeTests: Fix quadratic complexity. (PR #135875)

2025-04-15 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/135875


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] LowerTypeTests: Fix quadratic complexity. (PR #135875)

2025-04-15 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/135875


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] ELF: Only rewrite non-preemptible IFUNCs to IPLT functions if a non-IRELATIVE relocation is needed. (PR #133531)

2025-05-02 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

The performance impact of this change on firefox-x64 on an M2 Ultra was
```
N   Min   MaxMedian   AvgStddev
x 2801 1.2972602 1.4316316 1.3621663 1.3620049   0.019557658
+ 2801 1.2877738 1.4305345 1.3634474 1.3630622   0.019953389
Difference at 95.0% confidence
0.00105723 +/- 0.00103472
0.077623% +/- 0.0759707%
(Student's t, pooled s = 0.0197565)
```
The delta is fairly small so I don't think that performance is a strong reason 
not to make this change. That being said, after having given this more thought 
I do feel that the compatibility reason given in 
https://github.com/llvm/llvm-project/pull/133531#issuecomment-2795136942 has 
some merit so I intend to rework this with a new relocation type for directly 
producing IRELATIVE in the output.

https://github.com/llvm/llvm-project/pull/133531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Add a -z glibc-228-compat flag for working around an old glibc bug. (PR #133532)

2025-03-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/133532

The -z glibc-228-compat flag is intended to be used for
binaries utilizing IFUNCs which need to be compatible with
glibc versions containing a bug that was fixed in commit
b5c45e83753b27dc538dff2d55d4410c385cf3a4 which was released in
version 2.29. The bug causes glibc to mprotect the .text section as
RW while calling ifunc resolvers in binaries linked with -z notext,
leading to a SIGSEGV at startup time. By setting the W flag on the
executable section we work around the bug by avoiding the code path
that does the mprotect. It is recommended that binaries linked with
this flag contain startup code (e.g. in .init_array) that remaps the
executable section as non-writable.

TODO:
- Add tests.
- Possibly decide on another mechanism for enabling this besides the -z flag
  (e.g. examine symbol version data on libc.so.6).



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-03-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/133530

The emulated PAC runtime functions emulate the ARMv8.3a pointer
authentication instructions and are intended for use in heterogeneous
testing environments. For more information, see the associated RFC:
https://discourse.llvm.org/t/rfc-emulated-pac/85557

TODO:
- Add tests.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] CodeGen: Optionally emit PAuth relocations as IRELATIVE relocations. (PR #133533)

2025-03-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/133533

This supports the following use cases:
- ConstantPtrAuth expressions that are unrepresentable using standard PAuth
  relocations such as expressions involving an integer operand or
  deactivation symbols.
- libc implementations that do not support PAuth relocations.

For more information see the RFC:
https://discourse.llvm.org/t/rfc-structure-protection-a-family-of-uaf-mitigation-techniques/8

TODO:
- Add tests.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-04 Thread Peter Collingbourne via llvm-branch-commits


@@ -0,0 +1,115 @@
+#include 
+
+#define XXH_INLINE_ALL
+#define XXH_NO_STDLIB
+#define XXH_memcpy __builtin_memcpy
+#define XXH_memset __builtin_memset
+#define XXH_memcmp __builtin_memcmp
+#include "../xxhash.h"
+
+// EmuPAC implements runtime emulation of PAC instructions. If the current
+// CPU supports PAC, EmuPAC uses real PAC instructions. Otherwise, it uses the
+// emulation, which is effectively an implementation of PAC with an IMPDEF
+// hashing scheme based on XXH128.
+//
+// The purpose of the emulation is to allow programs to be built to be portable
+// to machines without PAC support, with some performance loss and increased
+// probability of false positives (due to not being able to portably determine
+// the VA size), while being functionally almost equivalent to running on a
+// machine with PAC support. One example of a use case is if PAC is used in
+// production as a security mitigation, but the testing environment is
+// heterogeneous (i.e. some machines lack PAC support). In this case we would
+// like the testing machines to be able to detect issues resulting
+// from the use of PAC instructions that would affect production by running
+// tests. This can be achieved by building test binaries with EmuPAC and
+// production binaries with real PAC.
+//
+// The emulation assumes that the VA size is at most 48 bits. The architecture
+// as of ARMv8.2, which was the last architecture version in which PAC was not
+// mandatory, permitted VA size up to 52 bits via ARMv8.2-LVA, but we are
+// unaware of an ARMv8.2 CPU that implemented ARMv8.2-LVA.
+
+const uint64_t kMaxVASize = 48;
+const uint64_t kPACMask = ((1ULL << 55) - 1) & ~((1ULL << kMaxVASize) - 1);
+const uint64_t kTTBR1Mask = 1ULL << 55;
+
+// Determine whether PAC is supported without accessing memory. This utilizes
+// the XPACLRI instruction which will copy bit 55 of x30 into at least bit 54 
if
+// PAC is supported and acts as a NOP if PAC is not supported.
+static _Bool pac_supported() {
+  register uintptr_t x30 __asm__("x30") = 1ULL << 55;
+  __asm__ __volatile__("xpaclri" : "+r"(x30));
+  return x30 & (1ULL << 54);
+}
+
+// This asm snippet is used to force the creation of a frame record when
+// calling the EmuPAC functions. This is important because the EmuPAC functions
+// may crash if an auth failure is detected and may be unwound past using a
+// frame pointer based unwinder.
+#ifdef __GCC_HAVE_DWARF2_CFI_ASM
+#define frame_pointer_wrap(sym) \
+  "stp x29, x30, [sp, #-16]!\n" \
+  ".cfi_def_cfa_offset 16\n" \
+  "mov x29, sp\n" \
+  ".cfi_def_cfa w29, 16\n" \
+  ".cfi_offset w30, -8\n" \
+  ".cfi_offset w29, -16\n" \
+  "bl " #sym "\n" \
+  ".cfi_def_cfa wsp, 16\n" \
+  "ldp x29, x30, [sp], #16\n" \
+  ".cfi_def_cfa_offset 0\n" \
+  ".cfi_restore w30\n" \
+  ".cfi_restore w29\n" \
+  "ret"
+#else
+#define frame_pointer_wrap(sym) \
+  "stp x29, x30, [sp, #-16]!\n" \
+  "mov x29, sp\n" \
+  "bl " #sym "\n" \
+  "ldp x29, x30, [sp], #16\n" \
+  "ret"
+#endif
+
+uint64_t __emupac_pacda_impl(uint64_t ptr, uint64_t disc) {
+  if (pac_supported()) {
+__asm__ __volatile__(".arch_extension pauth\npacda %0, %1"
+ : "+r"(ptr)
+ : "r"(disc));
+return ptr;
+  }
+  if (ptr & kTTBR1Mask) {
+if ((ptr & kPACMask) != kPACMask) {
+  return ptr | kPACMask;
+}
+  } else {
+if (ptr & kPACMask) {
+  return ptr & ~kPACMask;
+}
+  }
+  uint64_t hash = XXH3_64bits_withSeed(&ptr, 8, disc);
+  return (ptr & ~kPACMask) | (hash & kPACMask);
+}
+
+__attribute__((naked)) uint64_t __emupac_pacda(uint64_t ptr, uint64_t disc) {
+  __asm__(frame_pointer_wrap(__emupac_pacda_impl));
+}
+
+uint64_t __emupac_autda_impl(uint64_t ptr, uint64_t disc) {
+  if (pac_supported()) {

pcc wrote:

The problem with using ifuncs here is that this function will itself be called 
from ifunc resolvers (see 
[this](https://discourse.llvm.org/t/rfc-structure-protection-a-family-of-uaf-mitigation-techniques/8#:~:text=support%20for%20using-,Emulated%20PAC,-to%20relocate%20ptrauth)),
 so that could lead to order of initialization issues.

Since performance is not that important for this function's use case I didn't 
try to avoid checking every time or experiment with other calling conventions. 
Also, if compiler-rt needs to be buildable with non-Clang compilers, I'm not 
sure that we can use the other calling conventions anyway.

https://github.com/llvm/llvm-project/pull/133530
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Add pointer field protection feature. (PR #133538)

2025-03-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/133538

Pointer field protection is a use-after-free vulnerability
mitigation that works by changing how data structures' pointer
fields are stored in memory. For more information, see the RFC:
https://discourse.llvm.org/t/rfc-structure-protection-a-family-of-uaf-mitigation-techniques/8

TODO:
- Fix test failure.
- Add more tests.
- Add documentation.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-03-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132857


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-03-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132291

>From 89ce369ab9b49b8c23a87ad0a888002dd85c094c Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 20 Mar 2025 15:12:39 -0700
Subject: [PATCH] Format

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 630b90c9d77a6..927f8958f4b43 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,8 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = 'execute_mi' in gdb.__dict__
+has_execute_mi = "execute_mi" in gdb.__dict__
+
 
 class CheckResult(gdb.Command):
 def __init__(self):

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] libcxx: In gdb test detect execute_mi with feature check instead of version check. (PR #132291)

2025-03-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132291

>From 89ce369ab9b49b8c23a87ad0a888002dd85c094c Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 20 Mar 2025 15:12:39 -0700
Subject: [PATCH] Format

Created using spr 1.3.6-beta.1
---
 libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py 
b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
index 630b90c9d77a6..927f8958f4b43 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -30,7 +30,8 @@
 # we exit.
 has_run_tests = False
 
-has_execute_mi = 'execute_mi' in gdb.__dict__
+has_execute_mi = "execute_mi" in gdb.__dict__
+
 
 class CheckResult(gdb.Command):
 def __init__(self):

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Do not rewrite IFUNC relocations to point to PLT if no GOT/PLT needed. (PR #133531)

2025-03-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/133531

This enables the use of IFUNC to implement custom relocation types,
such as the PAuth relocation types that will be introduced in a
subsequent pull request.

TODO:
- Add tests.
- Fix broken tests.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] ELF: Add support for R_AARCH64_INST32 relocation. (PR #133534)

2025-03-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/133534

The R_AARCH64_INST32 relocation type is to support deactivation
symbols. For more information, see the RFC:
https://discourse.llvm.org/t/rfc-deactivation-symbols/85556

TODO:
- Agree on semantics and relocation type number.
- Add tests.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


  1   2   3   >