Author: Fangrui Song
Date: 2022-08-08T12:53:26-07:00
New Revision: bf271375cc086c1d0a382d6a4ffc0dd3976c964d

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

LOG: [ELF][AArch64] Fix potentially corrupted section content for PAC

D74537 introduced a bug: if `(config->andFeatures & 
GNU_PROPERTY_AARCH64_FEATURE_1_PAC) != 0`
with -z pac-plt unspecified, we incorrectly use AArch64BtiPac, whose writePlt 
will make
out-of-bounds write after the .plt section. This is often benign because the
output section after .plt will usually overwrite the content.

This is very difficult to test without D131247 (Parallelize writes of different 
OutputSections).

(cherry picked from commit d7cbfcf36ace575ec90434624279dd3ebce78c47)

Added: 
    

Modified: 
    lld/ELF/Arch/AArch64.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index 1949169d6447b..b23684819a239 100644
--- a/lld/ELF/Arch/AArch64.cpp
+++ b/lld/ELF/Arch/AArch64.cpp
@@ -873,8 +873,8 @@ void AArch64BtiPac::writePlt(uint8_t *buf, const Symbol 
&sym,
 }
 
 static TargetInfo *getTargetInfo() {
-  if (config->andFeatures & (GNU_PROPERTY_AARCH64_FEATURE_1_BTI |
-                             GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
+  if ((config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) ||
+      config->zPacPlt) {
     static AArch64BtiPac t;
     return &t;
   }


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

Reply via email to