[llvm] [llvm][ELF][build attributes] Change StringRef to std::string for BuildAttributeSubSection::Name (PR #135625)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 14 06:51:27 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: SivanShani-Arm (sivan-shani)

<details>
<summary>Changes</summary>

BuildAttributeSubSection::Name must be a std::string instead of StringRef because it may be assigned from non-persistent memory. StringRef is non-owning and unsafe in this context. This change ensures the subsection name owns its memory, preventing use-after-free or dangling references.

Context: Work in progress in PR #<!-- -->131990.

---
Full diff: https://github.com/llvm/llvm-project/pull/135625.diff


1 Files Affected:

- (modified) llvm/include/llvm/Support/ELFAttributes.h (+1-1) 


``````````diff
diff --git a/llvm/include/llvm/Support/ELFAttributes.h b/llvm/include/llvm/Support/ELFAttributes.h
index 6782aec6050ad..d652e2586e9e5 100644
--- a/llvm/include/llvm/Support/ELFAttributes.h
+++ b/llvm/include/llvm/Support/ELFAttributes.h
@@ -36,7 +36,7 @@ struct BuildAttributeItem {
       : Type(Ty), Tag(Tg), IntValue(IV), StringValue(std::move(SV)) {}
 };
 struct BuildAttributeSubSection {
-  StringRef Name;
+  std::string Name;
   unsigned IsOptional;
   unsigned ParameterType;
   SmallVector<BuildAttributeItem, 64> Content;

``````````

</details>


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


More information about the llvm-commits mailing list