[llvm-commits] [llvm] r117575 - in /llvm/trunk: lib/MC/ELFObjectWriter.cpp test/MC/ELF/rename.s
Rafael Espindola
rafael.espindola at gmail.com
Thu Oct 28 12:08:03 PDT 2010
Author: rafael
Date: Thu Oct 28 14:08:03 2010
New Revision: 117575
URL: http://llvm.org/viewvc/llvm-project?rev=117575&view=rev
Log:
Fix relocations with renamed symbols.
Added:
llvm/trunk/test/MC/ELF/rename.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=117575&r1=117574&r2=117575&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu Oct 28 14:08:03 2010
@@ -644,13 +644,14 @@
int Index = 0;
int64_t Value = Target.getConstant();
const MCSymbol *Symbol = 0;
+ const MCSymbol *Renamed = 0;
bool IsPCRel = isFixupKindX86PCRel(Fixup.getKind());
if (!Target.isAbsolute()) {
Symbol = &AliasedSymbol(Target.getSymA()->getSymbol());
- const MCSymbol *Renamed = Renames.lookup(Symbol);
- if (Renamed)
- Symbol = Renamed;
+ Renamed = Renames.lookup(Symbol);
+ if (!Renamed)
+ Renamed = Symbol;
MCSymbolData &SD = Asm.getSymbolData(*Symbol);
MCFragment *F = SD.getFragment();
@@ -685,7 +686,7 @@
// Offset of the symbol in the section
Value += Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);
} else {
- UsedInReloc.insert(Symbol);
+ UsedInReloc.insert(Renamed);
Index = -1;
}
Addend = Value;
@@ -833,7 +834,7 @@
ERE.Index = Index;
ERE.Type = Type;
- ERE.Symbol = Symbol;
+ ERE.Symbol = Renamed;
ERE.r_offset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
Added: llvm/trunk/test/MC/ELF/rename.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/rename.s?rev=117575&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/rename.s (added)
+++ llvm/trunk/test/MC/ELF/rename.s Thu Oct 28 14:08:03 2010
@@ -0,0 +1,46 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s
+
+// When doing a rename, all the checks for where the relocation should go
+// should be performed with the original symbol. Only if we decide to relocate
+// with the symbol we should then use the renamed one.
+
+// This is a regression test for a bug where we used bar5@@@zed when deciding
+// if we should relocate with the symbol or with the section and we would then
+// not produce a relocation with .text.
+
+defined1:
+defined3:
+ .symver defined3, bar5@@@zed
+ .long defined3
+
+ .global defined1
+
+// Section 1 is .text
+// CHECK: # Section 0x00000001
+// CHECK-NEXT: (('sh_name', 0x00000001) # '.text'
+// CHECK-NEXT: ('sh_type', 0x00000001)
+// CHECK-NEXT: ('sh_flags', 0x00000006)
+// CHECK-NEXT: ('sh_addr', 0x00000000)
+// CHECK-NEXT: ('sh_offset', 0x00000040)
+// CHECK-NEXT: ('sh_size', 0x00000004)
+// CHECK-NEXT: ('sh_link', 0x00000000)
+// CHECK-NEXT: ('sh_info', 0x00000000)
+// CHECK-NEXT: ('sh_addralign', 0x00000004)
+// CHECK-NEXT: ('sh_entsize', 0x00000000)
+
+// Symbol 2 is section 1
+// CHECK: # Symbol 0x00000002
+// CHECK-NEXT: (('st_name', 0x00000000) # ''
+// CHECK-NEXT: ('st_bind', 0x00000000)
+// CHECK-NEXT: ('st_type', 0x00000003)
+// CHECK-NEXT: ('st_other', 0x00000000)
+// CHECK-NEXT: ('st_shndx', 0x00000001)
+// CHECK-NEXT: ('st_value', 0x00000000)
+// CHECK-NEXT: ('st_size', 0x00000000)
+
+// The relocation uses symbol 2
+// CHECK: # Relocation 0x00000000
+// CHECK-NEXT: (('r_offset', 0x00000000)
+// CHECK-NEXT: ('r_sym', 0x00000002)
+// CHECK-NEXT: ('r_type', 0x0000000a)
+// CHECK-NEXT: ('r_addend', 0x00000000)
More information about the llvm-commits
mailing list