Skip to content

[Verifier] Allow too big unused sectioned global variables with local linkage - #212733

Open
steffenlarsen wants to merge 3 commits into
llvm:mainfrom
steffenlarsen:steffen/allow_too_big_global_internal_var
Open

[Verifier] Allow too big unused sectioned global variables with local linkage#212733
steffenlarsen wants to merge 3 commits into
llvm:mainfrom
steffenlarsen:steffen/allow_too_big_global_internal_var

Conversation

@steffenlarsen

Copy link
Copy Markdown
Contributor

This commit adjusts the check added in #179625 to allow global variables that are too big for their address space if they are unused, have local linkage, and have a section. This allows metadata embedded in global variables, like __clang_ast, to exceed the limits.

… linkage

This commit adjusts the check added in
llvm#179625 to allow global
variables that are too big for their address space if they are unused,
have local linkage, and have a section. This allows metadata embedded in
global variables, like __clang_ast, to exceed the limits.

Signed-off-by: Steffen Holst Larsen <sholstla@amd.com>
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-llvm-ir

Author: Steffen Larsen (steffenlarsen)

Changes

This commit adjusts the check added in #179625 to allow global variables that are too big for their address space if they are unused, have local linkage, and have a section. This allows metadata embedded in global variables, like __clang_ast, to exceed the limits.


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

2 Files Affected:

  • (modified) llvm/lib/IR/Verifier.cpp (+4-1)
  • (modified) llvm/test/Verifier/global-var-too-big.ll (+17)
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 90ad2e5bc8f68..f523fa869a27e 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -812,10 +812,13 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
         "Global @" + GV.getName() + " has illegal target extension type",
         GVType);
 
-  // Check that the the address space can hold all bits of the type, recognized
+  // Check that the address space can hold all bits of the type, recognized
   // by an access in the address space being able to reach all bytes of the
   // type.
+  // An exemption to this is sectioned global variables with local linkage
+  // and no uses. These are usually used for metadata.
   Check(!GVType->isSized() ||
+            (GV.use_empty() && GV.hasLocalLinkage() && GV.hasSection()) ||
             isUIntN(DL.getAddressSizeInBits(GV.getAddressSpace()),
                     GV.getGlobalSize(DL)),
         "Global variable is too large to fit into the address space", &GV,
diff --git a/llvm/test/Verifier/global-var-too-big.ll b/llvm/test/Verifier/global-var-too-big.ll
index fecb021145ae1..cd5c4bba7f78c 100644
--- a/llvm/test/Verifier/global-var-too-big.ll
+++ b/llvm/test/Verifier/global-var-too-big.ll
@@ -12,10 +12,27 @@ target datalayout = "e-m:e-p1:16:16-p2:32:32-p3:64:64-i8:8-i32:32-i64:64"
 @G3 = internal addrspace(1) global [65535 x i8] zeroinitializer, align 4
 @G4 = internal addrspace(2) global [2147483647 x i16] zeroinitializer, align 4
 
+; Too large but exempt: unreferenced, local linkage, has a section.
+@G5 = internal addrspace(1) global [65536 x i8] zeroinitializer, section "some_section_1", align 4
+@G6 = private addrspace(1) global [65536 x i8] zeroinitializer, section "some_section_2", align 4
+
+; Too large, has a section, but has a use so not exempt.
+@G7 = internal addrspace(1) global [65536 x i8] zeroinitializer, section "some_section_3", align 4
+@G7_user = global ptr addrspace(1) @G7
+
+; Too large, unreferenced, has a section, but external linkage so not exempt.
+@G8 = addrspace(1) global [65536 x i8] zeroinitializer, section "some_section_4", align 4
+
 ; CHECK: Global variable is too large to fit into the address space
 ; CHECK-NEXT: ptr addrspace(1) @G1
 ; CHECK-NEXT: [65536 x i8]
 ; CHECK: Global variable is too large to fit into the address space
 ; CHECK-NEXT: ptr addrspace(2) @G2
 ; CHECK-NEXT: [2147483648 x i16]
+; CHECK: Global variable is too large to fit into the address space
+; CHECK-NEXT: ptr addrspace(1) @G7
+; CHECK-NEXT: [65536 x i8]
+; CHECK: Global variable is too large to fit into the address space
+; CHECK-NEXT: ptr addrspace(1) @G8
+; CHECK-NEXT: [65536 x i8]
 ; CHECK-NOT: Global variable is too large to fit into the address space

Comment thread llvm/lib/IR/Verifier.cpp Outdated
Signed-off-by: Steffen Holst Larsen <sholstla@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants