Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devel/llvm16: merge backports from FreeBSD src
These upstream LLVM commits have been merged to FreeBSD's source tree post the 17.0.6 release: 7440e4ed85aa [sanitizer] Add re-execution on FreeBSD when ASLR is detected (#73439) 989879f8fded [Clang] Allow C++11 style initialisation of SVE types. 9ca395b5ade1 [clang][AST] Propagate the contains-errors bit to DeclRefExpr from VarDecl's initializer. While here, be consistant about using 12 digits of commit hash.
- Loading branch information
1 parent
283f8c3
commit 3db2bfa
Showing
6 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
commit 7440e4ed85aa992718d4b5ccd1c97724bc3bdd2c | ||
Author: Dimitry Andric <dimitry@andric.com> | ||
Date: Mon Nov 27 22:43:33 2023 +0100 | ||
|
||
[sanitizer] Add re-execution on FreeBSD when ASLR is detected (#73439) | ||
|
||
In the FreeBSD base system, re-executing the main binary when ASLR is | ||
detected was implemented in the following commits: | ||
|
||
* freebsd/freebsd-src@7cafe89f9ce33 | ||
* freebsd/freebsd-src@96fe7c8ab0f65 | ||
* freebsd/freebsd-src@930a7c2ac67e1 | ||
* freebsd/freebsd-src@0a736f0a6aeb0 | ||
* freebsd/freebsd-src@4c9a0adad1826 | ||
|
||
Squash all these to bring them into upstream compiler-rt. | ||
|
||
When ASLR is detected to be enabled, this first force-disables ASLR for | ||
the current process, then calls ReExec(). The ReExec() function gets a | ||
FreeBSD specific implementation for finding the path of the executed | ||
program, via the ELF auxiliary vector. This is done without calling into | ||
the regular elf_aux_info(3) function, as that makes use of several | ||
already-intercepted functions. | ||
|
||
diff --git compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | ||
index d2b3b63f3a7a..8759d96609e5 100644 | ||
--- compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | ||
+++ compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | ||
@@ -2323,9 +2323,12 @@ void CheckASLR() { | ||
return; | ||
} | ||
if ((aslr_status & PROC_ASLR_ACTIVE) != 0) { | ||
- Printf("This sanitizer is not compatible with enabled ASLR " | ||
- "and binaries compiled with PIE\n"); | ||
- Die(); | ||
+ VReport(1, "This sanitizer is not compatible with enabled ASLR " | ||
+ "and binaries compiled with PIE\n" | ||
+ "ASLR will be disabled and the program re-executed.\n"); | ||
+ int aslr_ctl = PROC_ASLR_FORCE_DISABLE; | ||
+ CHECK_NE(internal_procctl(P_PID, 0, PROC_ASLR_CTL, &aslr_ctl), -1); | ||
+ ReExec(); | ||
} | ||
# elif SANITIZER_PPC64V2 | ||
// Disable ASLR for Linux PPC64LE. | ||
diff --git compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp | ||
index fcfaa0c36c22..b41f778ea94b 100644 | ||
--- compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp | ||
+++ compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp | ||
@@ -48,12 +48,14 @@ | ||
#if SANITIZER_FREEBSD | ||
#include <pthread_np.h> | ||
#include <osreldate.h> | ||
+#include <sys/auxv.h> | ||
#include <sys/sysctl.h> | ||
#define pthread_getattr_np pthread_attr_get_np | ||
// The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before | ||
// that, it was never implemented. So just define it to zero. | ||
#undef MAP_NORESERVE | ||
#define MAP_NORESERVE 0 | ||
+extern const Elf_Auxinfo *__elf_aux_vector; | ||
#endif | ||
|
||
#if SANITIZER_NETBSD | ||
@@ -941,7 +943,14 @@ u64 MonotonicNanoTime() { | ||
void ReExec() { | ||
const char *pathname = "/proc/self/exe"; | ||
|
||
-#if SANITIZER_NETBSD | ||
+#if SANITIZER_FREEBSD | ||
+ for (const auto *aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) { | ||
+ if (aux->a_type == AT_EXECPATH) { | ||
+ pathname = static_cast<const char *>(aux->a_un.a_ptr); | ||
+ break; | ||
+ } | ||
+ } | ||
+#elif SANITIZER_NETBSD | ||
static const int name[] = { | ||
CTL_KERN, | ||
KERN_PROC_ARGS, |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
commit 989879f8fded41c732db93864461b3a67b9f1501 | ||
Author: Paul Walker <paul.walker@arm.com> | ||
Date: Thu Jun 22 14:03:28 2023 +0000 | ||
|
||
[Clang] Allow C++11 style initialisation of SVE types. | ||
|
||
Fixes https://github.com/llvm/llvm-project/issues/63223 | ||
|
||
Differential Revision: https://reviews.llvm.org/D153560 | ||
|
||
diff --git clang/lib/CodeGen/CGExprScalar.cpp clang/lib/CodeGen/CGExprScalar.cpp | ||
index 02b80f3aba21..dbba8cc96f81 100644 | ||
--- clang/lib/CodeGen/CGExprScalar.cpp | ||
+++ clang/lib/CodeGen/CGExprScalar.cpp | ||
@@ -1869,6 +1869,23 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) { | ||
return Visit(E->getInit(0)); | ||
} | ||
|
||
+ if (isa<llvm::ScalableVectorType>(VType)) { | ||
+ if (NumInitElements == 0) { | ||
+ // C++11 value-initialization for the vector. | ||
+ return EmitNullValue(E->getType()); | ||
+ } | ||
+ | ||
+ if (NumInitElements == 1) { | ||
+ Expr *InitVector = E->getInit(0); | ||
+ | ||
+ // Initialize from another scalable vector of the same type. | ||
+ if (InitVector->getType() == E->getType()) | ||
+ return Visit(InitVector); | ||
+ } | ||
+ | ||
+ llvm_unreachable("Unexpected initialization of a scalable vector!"); | ||
+ } | ||
+ | ||
unsigned ResElts = cast<llvm::FixedVectorType>(VType)->getNumElements(); | ||
|
||
// Loop over initializers collecting the Value for each, and remembering |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
commit 9ca395b5ade105aee63db20534d49a1c58ac76c7 | ||
Author: Haojian Wu <hokein.wu@gmail.com> | ||
Date: Mon Jul 10 18:22:12 2023 +0200 | ||
|
||
[clang][AST] Propagate the contains-errors bit to DeclRefExpr from VarDecl's initializer. | ||
|
||
Similar to the https://reviews.llvm.org/D86048 (it only sets the bit for C++ | ||
code), we propagate the contains-errors bit for C-code path. | ||
|
||
Fixes https://github.com/llvm/llvm-project/issues/50236 | ||
Fixes https://github.com/llvm/llvm-project/issues/50243 | ||
Fixes https://github.com/llvm/llvm-project/issues/48636 | ||
Fixes https://github.com/llvm/llvm-project/issues/50320 | ||
|
||
Differential Revision: https://reviews.llvm.org/D154861 | ||
|
||
diff --git clang/lib/AST/ComputeDependence.cpp clang/lib/AST/ComputeDependence.cpp | ||
index 632f38f711fb..09df5401d669 100644 | ||
--- clang/lib/AST/ComputeDependence.cpp | ||
+++ clang/lib/AST/ComputeDependence.cpp | ||
@@ -489,7 +489,7 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) { | ||
// more bullets here that we handle by treating the declaration as having a | ||
// dependent type if they involve a placeholder type that can't be deduced.] | ||
if (Type->isDependentType()) | ||
- return Deps | ExprDependence::TypeValueInstantiation; | ||
+ Deps |= ExprDependence::TypeValueInstantiation; | ||
else if (Type->isInstantiationDependentType()) | ||
Deps |= ExprDependence::Instantiation; | ||
|
||
@@ -525,13 +525,13 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) { | ||
// - it names a potentially-constant variable that is initialized with an | ||
// expression that is value-dependent | ||
if (const auto *Var = dyn_cast<VarDecl>(Decl)) { | ||
- if (Var->mightBeUsableInConstantExpressions(Ctx)) { | ||
- if (const Expr *Init = Var->getAnyInitializer()) { | ||
- if (Init->isValueDependent()) | ||
- Deps |= ExprDependence::ValueInstantiation; | ||
- if (Init->containsErrors()) | ||
- Deps |= ExprDependence::Error; | ||
- } | ||
+ if (const Expr *Init = Var->getAnyInitializer()) { | ||
+ if (Init->containsErrors()) | ||
+ Deps |= ExprDependence::Error; | ||
+ | ||
+ if (Var->mightBeUsableInConstantExpressions(Ctx) && | ||
+ Init->isValueDependent()) | ||
+ Deps |= ExprDependence::ValueInstantiation; | ||
} | ||
|
||
// - it names a static data member that is a dependent member of the | ||
diff --git clang/test/SemaCXX/cxx11-crashes.cpp clang/test/SemaCXX/cxx11-crashes.cpp | ||
index a15fea336f8c..11bc42315421 100644 | ||
--- clang/test/SemaCXX/cxx11-crashes.cpp | ||
+++ clang/test/SemaCXX/cxx11-crashes.cpp | ||
@@ -65,7 +65,7 @@ namespace b6981007 { | ||
struct S {}; // expected-note 3{{candidate}} | ||
void f() { | ||
S s(1, 2, 3); // expected-error {{no matching}} | ||
- for (auto x : s) { // expected-error {{invalid range expression of}} | ||
+ for (auto x : s) { | ||
// We used to attempt to evaluate the initializer of this variable, | ||
// and crash because it has an undeduced type. | ||
const int &n(x); |