[llvm-branch-commits] [llvm] 80698d5 - Revert "[AArch64][PAC] Support BLRA* instructions in SLS Hardening pass (#97605)"

2024-07-06 Thread via llvm-branch-commits

Author: Anatoly Trosinenko
Date: 2024-07-06T13:51:00+03:00
New Revision: 80698d58e1b3bfa2c5eae11b589436a7b35327c3

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

LOG: Revert "[AArch64][PAC] Support BLRA* instructions in SLS Hardening pass 
(#97605)"

This reverts commit 88b26293a24bdd85fce2b2f7191cc0a5bc0cecfe.

Added: 


Modified: 
llvm/lib/Target/AArch64/AArch64SLSHardening.cpp

Removed: 
llvm/test/CodeGen/AArch64/speculation-hardening-sls-blra.mir



diff  --git a/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp 
b/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
index 5e83015d72f42..00ba31b3e500d 100644
--- a/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
+++ b/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
@@ -13,7 +13,6 @@
 
 #include "AArch64InstrInfo.h"
 #include "AArch64Subtarget.h"
-#include "llvm/ADT/StringSwitch.h"
 #include "llvm/CodeGen/IndirectThunks.h"
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/CodeGen/MachineFunction.h"
@@ -24,11 +23,8 @@
 #include "llvm/IR/DebugLoc.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Target/TargetMachine.h"
 #include 
-#include 
-#include 
 
 using namespace llvm;
 
@@ -36,107 +32,17 @@ using namespace llvm;
 
 #define AARCH64_SLS_HARDENING_NAME "AArch64 sls hardening pass"
 
-// Common name prefix of all thunks generated by this pass.
-//
-// The generic form is
-// __llvm_slsblr_thunk_xNfor BLR thunks
-// __llvm_slsblr_thunk_(aaz|abz)_xN  for BLRAAZ and BLRABZ thunks
-// __llvm_slsblr_thunk_(aa|ab)_xN_xM for BLRAA and BLRAB thunks
-static constexpr StringRef CommonNamePrefix = "__llvm_slsblr_thunk_";
+static const char SLSBLRNamePrefix[] = "__llvm_slsblr_thunk_";
 
 namespace {
 
-struct ThunkKind {
-  enum ThunkKindId {
-ThunkBR,
-ThunkBRAA,
-ThunkBRAB,
-ThunkBRAAZ,
-ThunkBRABZ,
-  };
-
-  ThunkKindId Id;
-  StringRef NameInfix;
-  bool HasXmOperand;
-  bool NeedsPAuth;
-
-  // Opcode to perform indirect jump from inside the thunk.
-  unsigned BROpcode;
-
-  static const ThunkKind BR;
-  static const ThunkKind BRAA;
-  static const ThunkKind BRAB;
-  static const ThunkKind BRAAZ;
-  static const ThunkKind BRABZ;
-};
-
-// Set of inserted thunks.
-class ThunksSet {
-public:
-  static constexpr unsigned NumXRegisters = 32;
-
-  // Given Xn register, returns n.
-  static unsigned indexOfXReg(Register Xn);
-  // Given n, returns Xn register.
-  static Register xRegByIndex(unsigned N);
-
-  ThunksSet &operator|=(const ThunksSet &Other) {
-BLRThunks |= Other.BLRThunks;
-BLRAAZThunks |= Other.BLRAAZThunks;
-BLRABZThunks |= Other.BLRABZThunks;
-for (unsigned I = 0; I < NumXRegisters; ++I)
-  BLRAAThunks[I] |= Other.BLRAAThunks[I];
-for (unsigned I = 0; I < NumXRegisters; ++I)
-  BLRABThunks[I] |= Other.BLRABThunks[I];
-
-return *this;
-  }
-
-  bool get(ThunkKind::ThunkKindId Kind, Register Xn, Register Xm) {
-reg_bitmask_t XnBit = reg_bitmask_t(1) << indexOfXReg(Xn);
-return getBitmask(Kind, Xm) & XnBit;
-  }
-
-  void set(ThunkKind::ThunkKindId Kind, Register Xn, Register Xm) {
-reg_bitmask_t XnBit = reg_bitmask_t(1) << indexOfXReg(Xn);
-getBitmask(Kind, Xm) |= XnBit;
-  }
-
-private:
-  typedef uint32_t reg_bitmask_t;
-  static_assert(NumXRegisters <= sizeof(reg_bitmask_t) * CHAR_BIT,
-"Bitmask is not wide enough to hold all Xn registers");
-
-  // Bitmasks representing operands used, with n-th bit corresponding to Xn
-  // register operand. If the instruction has a second operand (Xm), an array
-  // of bitmasks is used, indexed by m.
-  // Indexes corresponding to the forbidden x16, x17 and x30 registers are
-  // always unset, for simplicity there are no holes.
-  reg_bitmask_t BLRThunks = 0;
-  reg_bitmask_t BLRAAZThunks = 0;
-  reg_bitmask_t BLRABZThunks = 0;
-  reg_bitmask_t BLRAAThunks[NumXRegisters] = {};
-  reg_bitmask_t BLRABThunks[NumXRegisters] = {};
-
-  reg_bitmask_t &getBitmask(ThunkKind::ThunkKindId Kind, Register Xm) {
-switch (Kind) {
-case ThunkKind::ThunkBR:
-  return BLRThunks;
-case ThunkKind::ThunkBRAAZ:
-  return BLRAAZThunks;
-case ThunkKind::ThunkBRABZ:
-  return BLRABZThunks;
-case ThunkKind::ThunkBRAA:
-  return BLRAAThunks[indexOfXReg(Xm)];
-case ThunkKind::ThunkBRAB:
-  return BLRABThunks[indexOfXReg(Xm)];
-}
-  }
-};
+// Set of inserted thunks: bitmask with bits corresponding to
+// indexes in SLSBLRThunks array.
+typedef uint32_t ThunksSet;
 
 struct SLSHardeningInserter : ThunkInserter {
 public:
-  const char *getThunkPrefix() { return CommonNamePrefix.data(); }
+  const char *getThunkPrefix() { return SLSBLRNamePrefix; }
   bool mayUseThunk(const MachineFunction

[llvm-branch-commits] [libcxx] [libc++][TZDB] Finishes zoned_time constructors. (PR #95010)

2024-07-06 Thread via llvm-branch-commits

h-vetinari wrote:

Peanut gallery comment: it would be very cool if `zoned_time` could make it for 
libcxx 19; 🤞 
It's IMO one of the most useful classes in ``.

https://github.com/llvm/llvm-project/pull/95010
___
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] [libc] b734450 - Revert "[libc] Add `link.h` and `elf.h` headers (#97924)"

2024-07-06 Thread via llvm-branch-commits

Author: Schrodinger ZHU Yifan
Date: 2024-07-06T18:32:00-07:00
New Revision: b734450e815feb02354c2e76c91228465eeefa72

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

LOG: Revert "[libc] Add `link.h` and `elf.h` headers (#97924)"

This reverts commit ba255076a0efce1e2e7ecf5572a794912e23370b.

Added: 


Modified: 
libc/config/linux/aarch64/headers.txt
libc/config/linux/x86_64/headers.txt
libc/include/CMakeLists.txt
libc/include/llvm-libc-macros/CMakeLists.txt
libc/include/llvm-libc-macros/link-macros.h
libc/include/llvm-libc-types/CMakeLists.txt

Removed: 
libc/include/llvm-libc-macros/elf-macros.h
libc/include/llvm-libc-types/Dl_info.h
libc/include/llvm-libc-types/__dl_iterate_phdr_callback_t.h
libc/include/llvm-libc-types/struct_dl_phdr_info.h



diff  --git a/libc/config/linux/aarch64/headers.txt 
b/libc/config/linux/aarch64/headers.txt
index ebe053af99d80..8f898f0150905 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -2,7 +2,6 @@ set(TARGET_PUBLIC_HEADERS
 libc.include.assert
 libc.include.ctype
 libc.include.dlfcn
-libc.include.elf
 libc.include.errno
 libc.include.features
 libc.include.fenv
@@ -10,7 +9,6 @@ set(TARGET_PUBLIC_HEADERS
 libc.include.stdint
 libc.include.inttypes
 libc.include.limits
-libc.include.link
 libc.include.math
 libc.include.pthread
 libc.include.signal

diff  --git a/libc/config/linux/x86_64/headers.txt 
b/libc/config/linux/x86_64/headers.txt
index 903771c5f96a6..df276894246c4 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -3,7 +3,6 @@ set(TARGET_PUBLIC_HEADERS
 libc.include.ctype
 libc.include.dirent
 libc.include.dlfcn
-libc.include.elf
 libc.include.errno
 libc.include.fcntl
 libc.include.features
@@ -12,7 +11,6 @@ set(TARGET_PUBLIC_HEADERS
 libc.include.stdint
 libc.include.inttypes
 libc.include.limits
-libc.include.link
 libc.include.math
 libc.include.pthread
 libc.include.sched

diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index a39c1c118165f..f8ef35078a8c4 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -56,7 +56,6 @@ add_gen_header(
   DEF_FILE dlfcn.h.def
   GEN_HDR dlfcn.h
   DEPENDS
-.llvm-libc-types.Dl_info
 .llvm-libc-macros.dlfcn_macros
 .llvm_libc_common_h
 )
@@ -368,25 +367,6 @@ add_gen_header(
 .llvm-libc-types.posix_spawn_file_actions_t
 )
 
-add_gen_header(
-  link
-  DEF_FILE link.h.def
-  GEN_HDR link.h
-  DEPENDS
-.llvm_libc_common_h
-.llvm-libc-types.struct_dl_phdr_info
-.llvm-libc-types.__dl_iterate_phdr_callback_t
-.llvm-libc-macros.link_macros
-)
-
-add_gen_header(
-  elf
-  DEF_FILE elf.h.def
-  GEN_HDR elf.h
-  DEPENDS
-.llvm-libc-macros.elf_macros
-)
-
 # TODO: Not all platforms will have a include/sys directory. Add the sys
 # directory and the targets for sys/*.h files conditional to the OS requiring
 # them.

diff  --git a/libc/include/llvm-libc-macros/CMakeLists.txt 
b/libc/include/llvm-libc-macros/CMakeLists.txt
index 60c8f5a9cd3de..86d6271ff88ac 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -283,9 +283,3 @@ add_macro_header(
   HDR
 dlfcn-macros.h
 )
-
-add_macro_header(
-  elf_macros
-  HDR
-elf-macros.h
-)

diff  --git a/libc/include/llvm-libc-macros/elf-macros.h 
b/libc/include/llvm-libc-macros/elf-macros.h
deleted file mode 100644
index fa4442abf0f5c..0
--- a/libc/include/llvm-libc-macros/elf-macros.h
+++ /dev/null
@@ -1,18 +0,0 @@
-//===-- Definition of macros from elf.h 
---===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_LIBC_MACROS_ELF_MACROS_H
-#define LLVM_LIBC_MACROS_ELF_MACROS_H
-
-#if __has_include()
-#include 
-#else
-#error "cannot use  without proper system headers."
-#endif
-
-#endif // LLVM_LIBC_MACROS_ELF_MACROS_H

diff  --git a/libc/include/llvm-libc-macros/link-macros.h 
b/libc/include/llvm-libc-macros/link-macros.h
index f7461d9527a47..5c8cadab8e71c 100644
--- a/libc/include/llvm-libc-macros/link-macros.h
+++ b/libc/include/llvm-libc-macros/link-macros.h
@@ -6,30 +6,8 @@
 //
 
//===--===//
 
-#ifndef LLVM_LIBC_MACROS_LINK_MACROS_H
-#define LLVM_LIBC_MACROS_LINK_MACROS_H
-
-#include "elf-macros.h"
-
 #ifdef __LP64__

[llvm-branch-commits] [llvm] [BOLT] Support POSSIBLE_PIC_FIXED_BRANCH (PR #91667)

2024-07-06 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/91667

>From dd4d0de42048c063d5e5095a0c2594c7cc578df5 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 9 May 2024 19:35:26 -0700
Subject: [PATCH 1/3] Fix RISCVMCPlusBuilder

Created using spr 1.3.4
---
 bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp 
b/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
index 74f2f0aae91e66..020e62463ee2f4 100644
--- a/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
+++ b/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
@@ -177,13 +177,14 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
   MCInst &Instruction, InstructionIterator Begin, InstructionIterator End,
   const unsigned PtrSize, MCInst *&MemLocInstr, unsigned &BaseRegNum,
   unsigned &IndexRegNum, int64_t &DispValue, const MCExpr *&DispExpr,
-  MCInst *&PCRelBaseOut) const override {
+  MCInst *&PCRelBaseOut, MCInst *&FixedEntryLoadInst) const override {
 MemLocInstr = nullptr;
 BaseRegNum = 0;
 IndexRegNum = 0;
 DispValue = 0;
 DispExpr = nullptr;
 PCRelBaseOut = nullptr;
+FixedEntryLoadInst = nullptr;
 
 // Check for the following long tail call sequence:
 // 1: auipc xi, %pcrel_hi(sym)

>From 62391bb5aa01f2b77d4315d1e72a9924eec9ecc0 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Fri, 5 Jul 2024 14:54:51 -0700
Subject: [PATCH 2/3] Drop deregisterJumpTable

Created using spr 1.3.4
---
 bolt/lib/Core/BinaryFunction.cpp | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 09a6ca1d68730c..f587d5a2cadd49 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -899,17 +899,9 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, 
unsigned Size,
 
 TargetAddress = ArrayStart + *Value;
 
-// Remove spurious JumpTable at EntryAddress caused by PIC reference from
-// the load instruction.
-JumpTable *JT = BC.getJumpTableContainingAddress(EntryAddress);
-assert(JT && "Must have a jump table at fixed entry address");
-BC.deregisterJumpTable(EntryAddress);
-JumpTables.erase(EntryAddress);
-delete JT;
-
 // Replace FixedEntryDispExpr used in target address calculation with outer
 // jump table reference.
-JT = BC.getJumpTableContainingAddress(ArrayStart);
+JumpTable *JT = BC.getJumpTableContainingAddress(ArrayStart);
 assert(JT && "Must have a containing jump table for PIC fixed branch");
 BC.MIB->replaceMemOperandDisp(*FixedEntryLoadInstr, JT->getFirstLabel(),
   EntryAddress - ArrayStart, &*BC.Ctx);

>From 5336879ab68aedb1217e2c6c139d171f31e89e03 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Sat, 6 Jul 2024 22:26:14 -0700
Subject: [PATCH 3/3] Surgically drop spurious jump table

Created using spr 1.3.4
---
 bolt/include/bolt/Core/BinaryContext.h  |  5 +
 bolt/lib/Core/BinaryFunction.cpp| 12 ++--
 bolt/test/X86/jump-table-fixed-ref-pic.test | 11 ---
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/bolt/include/bolt/Core/BinaryContext.h 
b/bolt/include/bolt/Core/BinaryContext.h
index 73932c4ca2fb33..c5e2c6cd02179e 100644
--- a/bolt/include/bolt/Core/BinaryContext.h
+++ b/bolt/include/bolt/Core/BinaryContext.h
@@ -431,6 +431,11 @@ class BinaryContext {
 return nullptr;
   }
 
+  /// Deregister JumpTable registered at a given \p Address.
+  bool deregisterJumpTable(uint64_t Address) {
+return JumpTables.erase(Address);
+  }
+
   unsigned getDWARFEncodingSize(unsigned Encoding) {
 if (Encoding == dwarf::DW_EH_PE_omit)
   return 0;
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index f587d5a2cadd49..2ecca32a5985c0 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -899,9 +899,17 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, 
unsigned Size,
 
 TargetAddress = ArrayStart + *Value;
 
+// Remove spurious JumpTable at EntryAddress caused by PIC reference from
+// the load instruction.
+JumpTable *JT = BC.getJumpTableContainingAddress(EntryAddress);
+assert(JT && "Must have a jump table at fixed entry address");
+BC.deregisterJumpTable(EntryAddress);
+JumpTables.erase(EntryAddress);
+delete JT;
+
 // Replace FixedEntryDispExpr used in target address calculation with outer
 // jump table reference.
-JumpTable *JT = BC.getJumpTableContainingAddress(ArrayStart);
+JT = BC.getJumpTableContainingAddress(ArrayStart);
 assert(JT && "Must have a containing jump table for PIC fixed branch");
 BC.MIB->replaceMemOperandDisp(*FixedEntryLoadInstr, JT->getFirstLabel(),
   EntryAddress - ArrayStart, &*BC.Ctx);
@@ -1158,10 +1166,10 @@ void BinaryF