[llvm] r235167 - Don't walk aliases from global to local symbols in comdats.

Rafael Espindola rafael.espindola at gmail.com
Fri Apr 17 01:46:11 PDT 2015


Author: rafael
Date: Fri Apr 17 03:46:11 2015
New Revision: 235167

URL: http://llvm.org/viewvc/llvm-project?rev=235167&view=rev
Log:
Don't walk aliases from global to local symbols in comdats.

This fixes pr23196.

Added:
    llvm/trunk/test/MC/ELF/alias-to-local.s
Modified:
    llvm/trunk/lib/MC/ELFObjectWriter.cpp

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=235167&r1=235166&r2=235167&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Fri Apr 17 03:46:11 2015
@@ -769,7 +769,36 @@ static const MCSymbol *getWeakRef(const
 }
 
 static bool isWeak(const MCSymbolData &D) {
-  return D.getFlags() & ELF_STB_Weak || MCELF::GetType(D) == ELF::STT_GNU_IFUNC;
+  if (MCELF::GetType(D) == ELF::STT_GNU_IFUNC)
+    return true;
+
+  switch (MCELF::GetBinding(D)) {
+  default:
+    llvm_unreachable("Unknown binding");
+  case ELF::STB_LOCAL:
+    return false;
+  case ELF::STB_GLOBAL:
+    break;
+  case ELF::STB_WEAK:
+  case ELF::STB_GNU_UNIQUE:
+    return true;
+  }
+
+  const MCSymbol &Sym = D.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;
 }
 
 void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,

Added: llvm/trunk/test/MC/ELF/alias-to-local.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/alias-to-local.s?rev=235167&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/alias-to-local.s (added)
+++ llvm/trunk/test/MC/ELF/alias-to-local.s Fri Apr 17 03:46:11 2015
@@ -0,0 +1,18 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu < %s | llvm-readobj -r | FileCheck %s
+
+// CHECK:      Relocations [
+// CHECK-NEXT:   Section {{.*}} .rela.text {
+// CHECK-NEXT:     0x1 R_X86_64_32 zed 0x0
+// CHECK-NEXT:   }
+// CHECK-NEXT: ]
+
+foo:
+	movl	$zed, %eax
+
+
+	.section	.data.bar,"aGw", at progbits,zed,comdat
+bar:
+	.byte	42
+
+	.globl	zed
+zed = bar





More information about the llvm-commits mailing list