[llvm] r235300 - Look past locals in comdats.

Rafael Espindola rafael.espindola at gmail.com
Mon Apr 20 05:44:06 PDT 2015


Author: rafael
Date: Mon Apr 20 07:44:06 2015
New Revision: 235300

URL: http://llvm.org/viewvc/llvm-project?rev=235300&view=rev
Log:
Look past locals in comdats.

We have to avoid converting a reference to a global into a reference to a local,
but it is fine to look past a local.

Patch by Vasileios Kalintiris.

I just moved the comment and added thet test.

Modified:
    llvm/trunk/lib/MC/ELFObjectWriter.cpp
    llvm/trunk/test/MC/ELF/relocation.s

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=235300&r1=235299&r2=235300&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Mon Apr 20 07:44:06 2015
@@ -1683,22 +1683,21 @@ bool ELFObjectWriter::isWeak(const MCSym
   if (::isWeak(SD))
     return true;
 
-  const MCSymbol &Sym = SD.getSymbol();
-  if (!Sym.isInSection())
-    return false;
-
-  const auto &Sec = cast<MCSectionELF>(Sym.getSection());
-  if (!Sec.getGroup())
-    return false;
-
   // It is invalid to replace a reference to a global in a comdat
   // with a reference to a local since out of comdat references
   // to a local are forbidden.
   // We could try to return false for more cases, like the reference
   // being in the same comdat or Sym being an alias to another global,
   // but it is not clear if it is worth the effort.
-  return true;
+  if (MCELF::GetBinding(SD) != ELF::STB_GLOBAL)
+    return false;
+
+  const MCSymbol &Sym = SD.getSymbol();
+  if (!Sym.isInSection())
+    return false;
 
+  const auto &Sec = cast<MCSectionELF>(Sym.getSection());
+  return Sec.getGroup();
 }
 
 MCObjectWriter *llvm::createELFObjectWriter(MCELFObjectTargetWriter *MOTW,

Modified: llvm/trunk/test/MC/ELF/relocation.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/relocation.s?rev=235300&r1=235299&r2=235300&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/relocation.s (original)
+++ llvm/trunk/test/MC/ELF/relocation.s Mon Apr 20 07:44:06 2015
@@ -7,6 +7,7 @@
 	.globl pr23272
 pr23272:
 pr23272_2:
+pr23272_3 = pr23272_2
 
         .text
 bar:
@@ -52,6 +53,7 @@ bar:
         .long foo at plt
 
         .quad	pr23272_2 - pr23272
+        .quad	pr23272_3 - pr23272
 // CHECK:        Section {
 // CHECK:          Name: .rela.text
 // CHECK:          Relocations [





More information about the llvm-commits mailing list