[lld] [AArch64][GCS][LLD] Introduce -zgcs-report-dynamic Command Line Option (PR #127787)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 19 03:47:02 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 41be5bbbdba2939a5fdb82c968c102f993edc4d8 178eaf7e956ea699e70aebb7b7035ffc763d62cb --extensions cpp,h -- lld/ELF/Config.h lld/ELF/Driver.cpp lld/ELF/InputFiles.cpp lld/ELF/InputFiles.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index e9098ff94f..91ce31a4dd 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -60,13 +60,13 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Remarks/HotnessThresholdParser.h"
 #include "llvm/Support/CommandLine.h"
-#include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/GlobPattern.h"
 #include "llvm/Support/LEB128.h"
 #include "llvm/Support/Parallel.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/TarWriter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
@@ -407,7 +407,7 @@ static void checkOptions(Ctx &ctx) {
       ErrAlways(ctx) << "-z pauth-report only supported on AArch64";
     if (ctx.arg.zGcsReport != GcsReportPolicy::None)
       ErrAlways(ctx) << "-z gcs-report only supported on AArch64";
-    if(ctx.arg.zGcsReportDynamic != GcsReportPolicy::None)
+    if (ctx.arg.zGcsReportDynamic != GcsReportPolicy::None)
       ErrAlways(ctx) << "-z gcs-report-dynamic only supported on AArch64";
     if (ctx.arg.zGcs != GcsPolicy::Implicit)
       ErrAlways(ctx) << "-z gcs only supported on AArch64";
@@ -618,9 +618,10 @@ static GcsReportPolicy getZGcsReportDynamic(Ctx &ctx, opt::InputArgList &args) {
     }
     // If the user has not defined a value for gcs-report-dynamic, but has for
     // gcs-report, we want to inherit that value for gcs-report-dynamic. This is
-    // capped at a warning to ensure a users module can still build, while providing
-    // information relating to if a dynamic object supports GCS.
-    if (kv.first == "gcs-report" && (kv.second == "warning" || kv.second == "error"))
+    // capped at a warning to ensure a users module can still build, while
+    // providing information relating to if a dynamic object supports GCS.
+    if (kv.first == "gcs-report" &&
+        (kv.second == "warning" || kv.second == "error"))
       ret = GcsReportPolicy::Warning;
   }
 
@@ -2884,11 +2885,12 @@ static void readSecurityNotes(Ctx &ctx) {
       return {ctx, DiagLevel::None};
     return report(config);
   };
-  auto reportGcsPolicy = [&](GcsReportPolicy config, bool cond) -> ELFSyncStream {
+  auto reportGcsPolicy = [&](GcsReportPolicy config,
+                             bool cond) -> ELFSyncStream {
     if (cond)
       return {ctx, DiagLevel::None};
     StringRef configString = "none";
-    if(config == GcsReportPolicy::Warning)
+    if (config == GcsReportPolicy::Warning)
       configString = "warning";
     else if (config == GcsReportPolicy::Error)
       configString = "error";
@@ -2904,7 +2906,7 @@ static void readSecurityNotes(Ctx &ctx) {
            "GNU_PROPERTY_AARCH64_FEATURE_1_BTI property";
 
     reportGcsPolicy(ctx.arg.zGcsReport,
-                 features & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
+                    features & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
         << f
         << ": -z gcs-report: file does not have "
            "GNU_PROPERTY_AARCH64_FEATURE_1_GCS property";
@@ -2974,15 +2976,21 @@ static void readSecurityNotes(Ctx &ctx) {
   else if (ctx.arg.zGcs == GcsPolicy::Never)
     ctx.arg.andFeatures &= ~GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
 
-  // If we are utilising GCS at any stage, the sharedFiles should be checked to ensure they also support this feature.
-  // The gcs-report-dynamic option is used to indicate if the user wants information relating to this, and will be set
-  // depending on the user's input, or warning if gcs-report is set to either `warning` or `error`.
-  if(ctx.arg.andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
+  // If we are utilising GCS at any stage, the sharedFiles should be checked to
+  // ensure they also support this feature. The gcs-report-dynamic option is
+  // used to indicate if the user wants information relating to this, and will
+  // be set depending on the user's input, or warning if gcs-report is set to
+  // either `warning` or `error`.
+  if (ctx.arg.andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
     for (SharedFile *f : ctx.sharedFiles)
-      reportGcsPolicy(ctx.arg.zGcsReportDynamic, f->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_GCS) << f
-        << ": GCS is required by -z gcs, but this shared library lacks the necessary property note. The "
-        << "dynamic loader might not enable GCS or refuse to load the program unless all shared library "
-        << "dependancies have the GCS marking.";
+      reportGcsPolicy(ctx.arg.zGcsReportDynamic,
+                      f->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
+          << f
+          << ": GCS is required by -z gcs, but this shared library lacks the "
+             "necessary property note. The "
+          << "dynamic loader might not enable GCS or refuse to load the "
+             "program unless all shared library "
+          << "dependancies have the GCS marking.";
 }
 
 static void initSectionsAndLocalSyms(ELFFileBase *file, bool ignoreComdats) {
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 055dd5ae0a..71fa5d6cfd 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1425,16 +1425,19 @@ std::vector<uint32_t> SharedFile::parseVerneed(const ELFFile<ELFT> &obj,
   return verneeds;
 }
 
-// To determine if a shared file can support the AArch64 GCS extension, the program headers for the object
-// need to be read. This ensures when input options are read, appropriate warning/error messages can be
-// emitted depending on the user's command line options.
+// To determine if a shared file can support the AArch64 GCS extension, the
+// program headers for the object need to be read. This ensures when input
+// options are read, appropriate warning/error messages can be emitted depending
+// on the user's command line options.
 template <typename ELFT>
-uint64_t SharedFile::parseGnuAttributes(const typename ELFT::PhdrRange headers) {
-  if(numElfPhdrs == 0)
+uint64_t
+SharedFile::parseGnuAttributes(const typename ELFT::PhdrRange headers) {
+  if (numElfPhdrs == 0)
     return 0;
   uint64_t attributes = 0;
   for (unsigned i = 0; i < numElfPhdrs; i++)
-    if(headers[i].p_type == PT_GNU_PROPERTY && headers[i].p_flags & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
+    if (headers[i].p_type == PT_GNU_PROPERTY &&
+        headers[i].p_flags & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
       attributes |= GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
 
   return attributes;
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index 99b1842326..604aa84429 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -208,7 +208,7 @@ public:
   }
   template <typename ELFT> typename ELFT::PhdrRange getELFPhdrs() const {
     return typename ELFT::PhdrRange(
-      reinterpret_cast<const typename ELFT::Phdr *>(elfPhdrs), numElfPhdrs);
+        reinterpret_cast<const typename ELFT::Phdr *>(elfPhdrs), numElfPhdrs);
   }
   template <typename ELFT> typename ELFT::SymRange getELFSyms() const {
     return typename ELFT::SymRange(

``````````

</details>


https://github.com/llvm/llvm-project/pull/127787


More information about the llvm-commits mailing list