MC tweak symbol difference resolution for non-local symbols.
authorJim Grosbach <grosbach@apple.com>
Tue, 17 Jan 2012 22:14:39 +0000 (22:14 +0000)
committerJim Grosbach <grosbach@apple.com>
Tue, 17 Jan 2012 22:14:39 +0000 (22:14 +0000)
When the non-local symbol in the expression is in the same fragment
as the second symbol, the assembler can still evaluate the expression
without needing a relocation.

For example, on ARM:
_foo:
ldr lr, (_foo - 4)

rdar://10348687

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148341 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MachObjectWriter.cpp
test/MC/MachO/ARM/darwin-ARM-reloc.s
test/MC/MachO/reloc-pcrel-offset.s
test/MC/MachO/reloc-pcrel.s

index e016f09c95f0e5b605debbce0e007bd3c15e1a8b..ce222b75cf4de4b7067645c4aca2c0e3101fbcc4 100644 (file)
@@ -590,8 +590,8 @@ IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
     // assembler locals.
 
     if (!Asm.getBackend().hasReliableSymbolDifference()) {
-      if ((!SA.isTemporary() && Asm.getSubsectionsViaSymbols()) ||
-           !SA.isInSection() || &SecA != &SecB)
+      if (!SA.isInSection() || &SecA != &SecB ||
+          (!SA.isTemporary() && &FB != Asm.getSymbolData(SA).getFragment()))
         return false;
       return true;
     }
index fe69a94c276dd3adb052ffd9f914e3159afc7b13..b98c80c46e8e5f5c647b9c1c8794f161a3ad8f5e 100644 (file)
@@ -12,9 +12,9 @@ _f1:
 
         .data
 _d0:
-Ld0_0:  
+Ld0_0:
         .long Lsc0_0 - Ld0_0
-        
+
        .section        __TEXT,__cstring,cstring_literals
 Lsc0_0:
         .long 0
index bc611d7f369d48cd81b75c5aa8564fc65bb57e63..e113e9616cc07aa9502a3b9427724131dbccaa4c 100644 (file)
@@ -11,6 +11,7 @@
 
         .text
 _a:
+_b:
         call _a
 
         .subsections_via_symbols
index b6d4be66891be18ae54a26b437a970e5bfa1f71b..11334150368a5f664581ec1ff45fd9e5d1a434c6 100644 (file)
@@ -8,13 +8,13 @@
 // CHECK:  ('word-1', 0x6)),
 // CHECK: # Relocation 2
 // CHECK: (('word-0', 0x40),
-// CHECK:  ('word-1', 0xd000002)),
+// CHECK:  ('word-1', 0xd000003)),
 // CHECK: # Relocation 3
 // CHECK: (('word-0', 0x3b),
-// CHECK:  ('word-1', 0xd000002)),
+// CHECK:  ('word-1', 0xd000003)),
 // CHECK: # Relocation 4
 // CHECK: (('word-0', 0x36),
-// CHECK:  ('word-1', 0xd000002)),
+// CHECK:  ('word-1', 0xd000003)),
 // CHECK: # Relocation 5
 // CHECK: (('word-0', 0xe0000031),
 // CHECK:  ('word-1', 0x4)),
@@ -41,6 +41,7 @@
 _a:
         xorl %eax,%eax
 _b:
+_d:
         xorl %eax,%eax
 L0:
         xorl %eax,%eax