[llvm] r219835 - Allow forward references to section symbols.
Rafael Espindola
rafael.espindola at gmail.com
Wed Oct 15 12:30:18 PDT 2014
Author: rafael
Date: Wed Oct 15 14:30:18 2014
New Revision: 219835
URL: http://llvm.org/viewvc/llvm-project?rev=219835&view=rev
Log:
Allow forward references to section symbols.
Added:
llvm/trunk/test/MC/ELF/section-sym2.s
Modified:
llvm/trunk/lib/MC/MCContext.cpp
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=219835&r1=219834&r2=219835&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Wed Oct 15 14:30:18 2014
@@ -119,11 +119,18 @@ MCSymbol *MCContext::getOrCreateSectionS
return Sym;
StringRef Name = Section.getSectionName();
+
+ StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name);
+ MCSymbol *OldSym = Entry.getValue();
+ if (OldSym && OldSym->isUndefined()) {
+ Sym = OldSym;
+ return OldSym;
+ }
+
StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name);
NameEntry->setValue(true);
Sym = new (*this) MCSymbol(NameEntry->getKey(), /*isTemporary*/ false);
- StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name);
if (!Entry.getValue())
Entry.setValue(Sym);
Added: llvm/trunk/test/MC/ELF/section-sym2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/section-sym2.s?rev=219835&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/section-sym2.s (added)
+++ llvm/trunk/test/MC/ELF/section-sym2.s Wed Oct 15 14:30:18 2014
@@ -0,0 +1,28 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -t -r --expand-relocs | FileCheck %s
+
+// Test that we can forward reference a section.
+
+mov .rodata, %rsi
+.section .rodata
+
+// CHECK:Relocations [
+// CHECK: Section (2) .rela.text {
+// CHECK: Relocation {
+// CHECK: Offset: 0x4
+// CHECK: Type: R_X86_64_32S (11)
+// CHECK: Symbol: .rodata
+// CHECK: Addend: 0x0
+// CHECK: }
+// CHECK: }
+// CHECK:]
+
+// There is only one .rodata symbol
+
+// CHECK:Symbols [
+// CHECK-NOT: Name: .rodata
+// CHECK: Name: .rodata
+// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Local (0x0)
+// CHECK-NEXT: Type: Section (0x3)
+// CHECK-NOT: Name: .rodata
More information about the llvm-commits
mailing list