[PATCH] D33727: [GlobalMerge] Don't merge globals that may be preempted

John Brawn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 31 09:25:23 PDT 2017


john.brawn created this revision.
Herald added a subscriber: javed.absar.

When a global may be preempted it needs to be accessed directly, instead of indirectly through a MergedGlobals symbol, for the preemption to work.

This fixes PR33136.


Repository:
  rL LLVM

https://reviews.llvm.org/D33727

Files:
  lib/CodeGen/GlobalMerge.cpp
  test/CodeGen/ARM/global-merge-external.ll


Index: test/CodeGen/ARM/global-merge-external.ll
===================================================================
--- test/CodeGen/ARM/global-merge-external.ll
+++ test/CodeGen/ARM/global-merge-external.ll
@@ -2,6 +2,7 @@
 ; RUN: llc < %s -mtriple=arm-eabi  -arm-global-merge -global-merge-on-external=true  | FileCheck %s --check-prefix=CHECK-MERGE
 ; RUN: llc < %s -mtriple=arm-eabi  -arm-global-merge -global-merge-on-external=false | FileCheck %s --check-prefix=CHECK-NO-MERGE
 ; RUN: llc < %s -mtriple=arm-macho -arm-global-merge                                 | FileCheck %s --check-prefix=CHECK-NO-MERGE
+; RUN: llc < %s -mtriple=arm-eabi  -arm-global-merge -relocation-model=pic           | FileCheck %s --check-prefix=CHECK-NO-MERGE
 
 @x = global i32 0, align 4
 @y = global i32 0, align 4
Index: lib/CodeGen/GlobalMerge.cpp
===================================================================
--- lib/CodeGen/GlobalMerge.cpp
+++ lib/CodeGen/GlobalMerge.cpp
@@ -556,6 +556,10 @@
     if (GV.isDeclaration() || GV.isThreadLocal() || GV.hasSection())
       continue;
 
+    // It's not safe to merge globals that may be preempted
+    if (TM && !TM->shouldAssumeDSOLocal(M, &GV))
+      continue;
+
     if (!(MergeExternalGlobals && GV.hasExternalLinkage()) &&
         !GV.hasInternalLinkage())
       continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33727.100876.patch
Type: text/x-patch
Size: 1326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170531/78c7fa90/attachment.bin>


More information about the llvm-commits mailing list