[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-29 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH 1/2] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

>From 4c914a219001c7fa5f4507173108ab648fc61ad7 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Fri, 17 Apr 2026 11:13:39 -0700
Subject: [PATCH 2/2] Add test for explicit sections

Created using spr 1.3.6-beta.1
---
 llvm/test/CodeGen/X86/elf-section-properties.ll | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/llvm/test/CodeGen/X86/elf-section-properties.ll 
b/llvm/test/CodeGen/X86/elf-section-properties.ll
index fe5a5940dfd5b..071fdffd2ed6c 100644
--- a/llvm/test/CodeGen/X86/elf-section-properties.ll
+++ b/llvm/test/CodeGen/X86/elf-section-properties.ll
@@ -12,8 +12,14 @@ define void @implicit_section_func() !elf_section_properties 
!{i32 1879002126, i
 define void @explicit_section_func() section "foo" !elf_section_properties 
!{i32 1879002126, i32 4} {
   ret void
 }
+; CHECK: .section foo,"ax",@llvm_cfi_jump_table,8,unique,1
+define void @explicit_section_func2() section "foo" !elf_section_properties 
!{i32 1879002126, i32 8} {
+  ret void
+}
 
 ; CHECK: .section .data.implicit_section_global,"aw",@llvm_cfi_jump_table,8
 @implicit_section_global = global i32 1, !elf_section_properties !{i32 
1879002126, i32 8}
 ; CHECK: .section bar,"aw",@llvm_cfi_jump_table,16
 @explicit_section_global = global i32 1, !elf_section_properties !{i32 
1879002126, i32 16}, section "bar"
+; CHECK: .section bar,"aw",@llvm_cfi_jump_table,32,unique,2
+@explicit_section_global2 = global i32 1, !elf_section_properties !{i32 
1879002126, i32 32}, section "bar"

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-29 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH 1/2] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

>From 4c914a219001c7fa5f4507173108ab648fc61ad7 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Fri, 17 Apr 2026 11:13:39 -0700
Subject: [PATCH 2/2] Add test for explicit sections

Created using spr 1.3.6-beta.1
---
 llvm/test/CodeGen/X86/elf-section-properties.ll | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/llvm/test/CodeGen/X86/elf-section-properties.ll 
b/llvm/test/CodeGen/X86/elf-section-properties.ll
index fe5a5940dfd5b..071fdffd2ed6c 100644
--- a/llvm/test/CodeGen/X86/elf-section-properties.ll
+++ b/llvm/test/CodeGen/X86/elf-section-properties.ll
@@ -12,8 +12,14 @@ define void @implicit_section_func() !elf_section_properties 
!{i32 1879002126, i
 define void @explicit_section_func() section "foo" !elf_section_properties 
!{i32 1879002126, i32 4} {
   ret void
 }
+; CHECK: .section foo,"ax",@llvm_cfi_jump_table,8,unique,1
+define void @explicit_section_func2() section "foo" !elf_section_properties 
!{i32 1879002126, i32 8} {
+  ret void
+}
 
 ; CHECK: .section .data.implicit_section_global,"aw",@llvm_cfi_jump_table,8
 @implicit_section_global = global i32 1, !elf_section_properties !{i32 
1879002126, i32 8}
 ; CHECK: .section bar,"aw",@llvm_cfi_jump_table,16
 @explicit_section_global = global i32 1, !elf_section_properties !{i32 
1879002126, i32 16}, section "bar"
+; CHECK: .section bar,"aw",@llvm_cfi_jump_table,32,unique,2
+@explicit_section_global2 = global i32 1, !elf_section_properties !{i32 
1879002126, i32 32}, section "bar"

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-29 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

I'll go ahead and land this, as the test I added shows that the behavior with 
explicit sections matches @MaskRay 's (and my) expectations.

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-29 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

Nikita pointed me here from #194855. I think I'd need sh_flags included for my 
purposes, which I'm happy to add once this has landed, but I just wanted to 
check whether the idea sounds reasonable to you?

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-20 Thread Peter Collingbourne via llvm-branch-commits


@@ -771,8 +772,8 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, 
StringRef SectionName,
   // implicitly for this symbol e.g. .rodata.str1.1, then we don't need
   // to unique the section as the entry size for this symbol will be
   // compatible with implicitly created sections.
-  SmallString<128> ImplicitSectionNameStem = getELFSectionNameForGlobal(
-  GO, Kind, Mang, TM, EntrySize, false, /*MJTE=*/nullptr);
+  SmallString<128> ImplicitSectionNameStem =

pcc wrote:

That's orthogonal to this patch. There are several instances of 
`SmallString<128>` in this file already and changing this one would make it 
inconsistent. If we want to change it, we should do it in a separate patch.

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-19 Thread Vitaly Buka via llvm-branch-commits


@@ -771,8 +772,8 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, 
StringRef SectionName,
   // implicitly for this symbol e.g. .rodata.str1.1, then we don't need
   // to unique the section as the entry size for this symbol will be
   // compatible with implicitly created sections.
-  SmallString<128> ImplicitSectionNameStem = getELFSectionNameForGlobal(
-  GO, Kind, Mang, TM, EntrySize, false, /*MJTE=*/nullptr);
+  SmallString<128> ImplicitSectionNameStem =

vitalybuka wrote:

SmallString<128> -> auto to avoid hardcoding size in two places

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-17 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

> Note: The base branch is not main.

Correct. There are no more dependencies for this change, but I think spr 
doesn't set the base branch to main after dependencies have landed.

> When two globals specify the same explicit section but with different sectin 
> properties, what's the suggested behavior?

I would expect two sections like in your example. I added a test for that.

> @efriedma-quic raised optimizer-interaction concerns that have been partly 
> addressed (ConstantMerge was already safe, GlobalMerge was fixed in the 
> follow-up #175875).

I think they have been addressed. Optimization passes that merge globals 
without checking for metadata, like GlobalMerge used to do, are buggy, as they 
violate the existing metadata rules, and should be fixed (in a followup if 
necessary). I'm not aware of any remaining buggy passes.

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-17 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH 1/2] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

>From 4c914a219001c7fa5f4507173108ab648fc61ad7 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Fri, 17 Apr 2026 11:13:39 -0700
Subject: [PATCH 2/2] Add test for explicit sections

Created using spr 1.3.6-beta.1
---
 llvm/test/CodeGen/X86/elf-section-properties.ll | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/llvm/test/CodeGen/X86/elf-section-properties.ll 
b/llvm/test/CodeGen/X86/elf-section-properties.ll
index fe5a5940dfd5b..071fdffd2ed6c 100644
--- a/llvm/test/CodeGen/X86/elf-section-properties.ll
+++ b/llvm/test/CodeGen/X86/elf-section-properties.ll
@@ -12,8 +12,14 @@ define void @implicit_section_func() !elf_section_properties 
!{i32 1879002126, i
 define void @explicit_section_func() section "foo" !elf_section_properties 
!{i32 1879002126, i32 4} {
   ret void
 }
+; CHECK: .section foo,"ax",@llvm_cfi_jump_table,8,unique,1
+define void @explicit_section_func2() section "foo" !elf_section_properties 
!{i32 1879002126, i32 8} {
+  ret void
+}
 
 ; CHECK: .section .data.implicit_section_global,"aw",@llvm_cfi_jump_table,8
 @implicit_section_global = global i32 1, !elf_section_properties !{i32 
1879002126, i32 8}
 ; CHECK: .section bar,"aw",@llvm_cfi_jump_table,16
 @explicit_section_global = global i32 1, !elf_section_properties !{i32 
1879002126, i32 16}, section "bar"
+; CHECK: .section bar,"aw",@llvm_cfi_jump_table,32,unique,2
+@explicit_section_global2 = global i32 1, !elf_section_properties !{i32 
1879002126, i32 32}, section "bar"

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-17 Thread Fangrui Song via llvm-branch-commits

MaskRay wrote:

When two globals specify the same explicit section but with different sectin 
properties, what's the suggested behavior?

```
; entsize differs -> calcUniqueIDUpdateFlagsAndSize bumps the ID, two foo 
sections, fine
@a = global i32 1, section "foo", !elf_section_properties !{i32 1879002126, i32 
4}
@b = global i32 2, section "foo", !elf_section_properties !{i32 1879002126, i32 
8}

; implicit sections -> the new `if (hasMetadata(...)) EmitUniqueSection = true;`
; forces unique IDs, so these get .text.a / .text.b and never collide
define void @a() !elf_section_properties !{i32 1879002126, i32 4} { ret void }
define void @b() !elf_section_properties !{i32 5,  i32 4} { ret void }
```

@efriedma-quic raised optimizer-interaction concerns that have been partly 
addressed (ConstantMerge was already safe, GlobalMerge was fixed in the 
follow-up #175875).

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-17 Thread Florian Mayer via llvm-branch-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-16 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-04-16 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-02-27 Thread Peter Collingbourne via llvm-branch-commits


@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s

pcc wrote:

Done

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-02-27 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-02-27 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-02-27 Thread Matt Arsenault via llvm-branch-commits


@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s

arsenm wrote:

```suggestion
; RUN: not llvm-as -disable-output < %s 2>&1 | FileCheck %s
```

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-02-27 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

Ping

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-01-13 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

> > Indeed, looking at ConstantMerge it does refuse to merge globals with 
> > non-debug metadata:
> 
> GlobalMerge doesn't have a similar check, though, as far as I can tell.

Thanks, sent #175875 to add it.

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-01-13 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-01-13 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-01-13 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2026-01-13 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-09-17 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-09-12 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-08-29 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-08-29 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-08-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-08-28 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-08-27 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-08-27 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-08-27 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

I would expect 

> > For example, it could be dropped from CFI jump tables and the resulting 
> > binary would still be correct, it would just be less optimized because jump 
> > table relaxation could not be applied.
> 
> Is the opposite also true, that you can add it to non-cfi-jump-table globals 
> and the resulting binary is still correct? (Unless there's some check, 
> constant merging can merge either way, I think.)

I would expect passes to refuse to merge constants with inconsistent metadata, 
as that is effectively the same as adding metadata to one of the sides, which 
is not guaranteed to result in correct behavior. I seem to recall a discussion 
about this a few years ago in the context of merging instructions, the outcome 
being that passes should not do this. Indeed, looking at ConstantMerge it does 
refuse to merge globals with non-debug metadata:

https://github.com/llvm/llvm-project/blob/e7c9f2db41900c8991f6d3172e9bf74e57c39736/llvm/lib/Transforms/IPO/ConstantMerge.cpp#L108

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-08-27 Thread Eli Friedman via llvm-branch-commits

efriedma-quic wrote:

> For example, it could be dropped from CFI jump tables and the resulting 
> binary would still be correct, it would just be less optimized because jump 
> table relaxation could not be applied.

Is the opposite also true, that you can add it to non-cfi-jump-table globals 
and the resulting binary is still correct?  (Unless there's some check, 
constant merging can merge either way, I think.)

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-08-27 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

> > Missing Verifier checks for the new metadata.
> 
> Will add.

Done

https://github.com/llvm/llvm-project/pull/149260
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)

2025-08-27 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260

>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 27 Aug 2025 14:51:58 -0700
Subject: [PATCH] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst|  2 +-
 llvm/lib/IR/Verifier.cpp | 16 
 llvm/test/Verifier/elf-section-properties.ll | 12 
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/elf-section-properties.ll

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 0664f3bf48f37..de1b5180e1956 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -8381,7 +8381,7 @@ Example:
 
 @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8}
 
-This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
+This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry
 size 8.
 
 
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4eb4b58d022e8..537b6dfcbdbee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
   DL.getIntPtrType(GO->getType()),
   RangeLikeMetadataKind::AbsoluteSymbol);
 }
+
+if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) 
{
+  Check(Props->getNumOperands() == 2,
+"elf_section_properties metadata must have two operands", GO, 
Props);
+  if (Props->getNumOperands() == 2) {
+auto *Type = dyn_cast(Props->getOperand(0));
+Check(Type, "type field must be ConstantAsMetadata", GO, Props);
+auto *TypeInt = dyn_cast(Type->getValue());
+Check(TypeInt, "type field must be ConstantInt", GO, Props);
+
+auto *Entsize = dyn_cast(Props->getOperand(1));
+Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props);
+auto *EntsizeInt = dyn_cast(Entsize->getValue());
+Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props);
+  }
+}
   }
 
   Check(!GV.hasAppendingLinkage() || isa(GV),
diff --git a/llvm/test/Verifier/elf-section-properties.ll 
b/llvm/test/Verifier/elf-section-properties.ll
new file mode 100644
index 0..3ec4a8f5d7d66
--- /dev/null
+++ b/llvm/test/Verifier/elf-section-properties.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: elf_section_properties metadata must have two operands
+@g1 = global i32 0, !elf_section_properties !{i32 0}
+; CHECK: type field must be ConstantAsMetadata
+@g2 = global i32 0, !elf_section_properties !{!{}, i32 0}
+; CHECK: entsize field must be ConstantAsMetadata
+@g3 = global i32 0, !elf_section_properties !{i32 0, !{}}
+; CHECK: type field must be ConstantInt
+@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0}
+; CHECK: entsize field must be ConstantInt
+@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0}

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits