[llvm-commits] [llvm] r103443 - in /llvm/trunk: lib/MC/MachObjectWriter.cpp test/MC/MachO/reloc.s

Daniel Dunbar daniel at zuster.org
Mon May 10 16:15:20 PDT 2010


Author: ddunbar
Date: Mon May 10 18:15:20 2010
New Revision: 103443

URL: http://llvm.org/viewvc/llvm-project?rev=103443&view=rev
Log:
MC/Mach-O: Fix another mismatch with .weak_definition, we shouldn't use a
scattered relocation entry with a .weak_definition.

Modified:
    llvm/trunk/lib/MC/MachObjectWriter.cpp
    llvm/trunk/test/MC/MachO/reloc.s

Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=103443&r1=103442&r2=103443&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Mon May 10 18:15:20 2010
@@ -740,15 +740,24 @@
 
     // If this is a difference or a defined symbol plus an offset, then we need
     // a scattered relocation entry.
+    // Differences always require scattered relocations.
+    if (Target.getSymB())
+        return RecordScatteredRelocation(Asm, Layout, Fragment, Fixup,
+                                         Target, FixedValue);
+
+    // Get the symbol data, if any.
+    MCSymbolData *SD = 0;
+    if (Target.getSymA())
+      SD = &Asm.getSymbolData(Target.getSymA()->getSymbol());
+
+    // If this is an internal relocation with an offset, it also needs a
+    // scattered relocation entry.
     uint32_t Offset = Target.getConstant();
     if (IsPCRel)
       Offset += 1 << Log2Size;
-    if (Target.getSymB() ||
-        (Target.getSymA() && !Target.getSymA()->getSymbol().isUndefined() &&
-         Offset)) {
-      RecordScatteredRelocation(Asm, Layout, Fragment, Fixup,Target,FixedValue);
-      return;
-    }
+    if (Offset && SD && !doesSymbolRequireExternRelocation(SD))
+      return RecordScatteredRelocation(Asm, Layout, Fragment, Fixup,
+                                       Target, FixedValue);
 
     // See <reloc.h>.
     uint32_t Address = Layout.getFragmentOffset(Fragment) + Fixup.Offset;
@@ -765,9 +774,6 @@
       Type = RIT_Vanilla;
       Value = 0;
     } else {
-      const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
-      MCSymbolData *SD = &Asm.getSymbolData(*Symbol);
-
       // Check whether we need an external or internal relocation.
       if (doesSymbolRequireExternRelocation(SD)) {
         IsExtern = 1;

Modified: llvm/trunk/test/MC/MachO/reloc.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/reloc.s?rev=103443&r1=103442&r2=103443&view=diff
==============================================================================
--- llvm/trunk/test/MC/MachO/reloc.s (original)
+++ llvm/trunk/test/MC/MachO/reloc.s Mon May 10 18:15:20 2010
@@ -50,6 +50,7 @@
 _f1:
         .data
         .long _f1
+        .long _f1 + 4
 
 // CHECK: ('cputype', 7)
 // CHECK: ('cpusubtype', 3)
@@ -63,9 +64,9 @@
 // CHECK:   ('size', 260)
 // CHECK:   ('segment_name', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
 // CHECK:   ('vm_addr', 0)
-// CHECK:   ('vm_size', 67)
+// CHECK:   ('vm_size', 71)
 // CHECK:   ('file_offset', 392)
-// CHECK:   ('file_size', 67)
+// CHECK:   ('file_size', 71)
 // CHECK:   ('maxprot', 7)
 // CHECK:   ('initprot', 7)
 // CHECK:   ('num_sections', 3)
@@ -78,7 +79,7 @@
 // CHECK:     ('size', 8)
 // CHECK:     ('offset', 392)
 // CHECK:     ('alignment', 0)
-// CHECK:     ('reloc_offset', 460)
+// CHECK:     ('reloc_offset', 464)
 // CHECK:     ('num_reloc', 1)
 // CHECK:     ('flags', 0x80000400)
 // CHECK:     ('reserved1', 0)
@@ -89,61 +90,64 @@
 // CHECK:     (('word-0', 0x1),
 // CHECK:      ('word-1', 0x5000003)),
 // CHECK:   ])
-// CHECK:   ('_section_data', '\xe96\x00\x00\x00\xeb\xf9\xc3')
+// CHECK:   ('_section_data', '\xe9:\x00\x00\x00\xeb\xf9\xc3')
 // CHECK:     # Section 1
 // CHECK:    (('section_name', '__data\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
 // CHECK:     ('segment_name', '__DATA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
 // CHECK:     ('address', 8)
-// CHECK:     ('size', 47)
+// CHECK:     ('size', 51)
 // CHECK:     ('offset', 400)
 // CHECK:     ('alignment', 0)
-// CHECK:     ('reloc_offset', 468)
-// CHECK:     ('num_reloc', 10)
+// CHECK:     ('reloc_offset', 472)
+// CHECK:     ('num_reloc', 11)
 // CHECK:     ('flags', 0x0)
 // CHECK:     ('reserved1', 0)
 // CHECK:     ('reserved2', 0)
 // CHECK:    ),
 // CHECK:   ('_relocations', [
 // CHECK:     # Relocation 0
-// CHECK:     (('word-0', 0x2b),
+// CHECK:     (('word-0', 0x2f),
 // CHECK:      ('word-1', 0xc000007)),
 // CHECK:     # Relocation 1
+// CHECK:     (('word-0', 0x2b),
+// CHECK:      ('word-1', 0xc000007)),
+// CHECK:     # Relocation 2
 // CHECK:     (('word-0', 0x8000002a),
 // CHECK:      ('word-1', 0x18)),
-// CHECK:     # Relocation 2
+// CHECK:     # Relocation 3
 // CHECK:     (('word-0', 0x90000028),
 // CHECK:      ('word-1', 0x18)),
-// CHECK:     # Relocation 3
+// CHECK:     # Relocation 4
 // CHECK:     (('word-0', 0xa0000024),
 // CHECK:      ('word-1', 0x18)),
-// CHECK:     # Relocation 4
+// CHECK:     # Relocation 5
 // CHECK:     (('word-0', 0xa0000020),
 // CHECK:      ('word-1', 0x18)),
-// CHECK:     # Relocation 5
+// CHECK:     # Relocation 6
 // CHECK:     (('word-0', 0xa4000014),
 // CHECK:      ('word-1', 0x1c)),
-// CHECK:     # Relocation 6
+// CHECK:     # Relocation 7
 // CHECK:     (('word-0', 0xa1000000),
 // CHECK:      ('word-1', 0x24)),
-// CHECK:     # Relocation 7
+// CHECK:     # Relocation 8
 // CHECK:     (('word-0', 0x8),
 // CHECK:      ('word-1', 0x4000002)),
-// CHECK:     # Relocation 8
+// CHECK:     # Relocation 9
 // CHECK:     (('word-0', 0x4),
 // CHECK:      ('word-1', 0xc000009)),
-// CHECK:     # Relocation 9
+// CHECK:     # Relocation 10
 // CHECK:     (('word-0', 0x0),
 // CHECK:      ('word-1', 0xc000009)),
 // CHECK:   ])
-// CHECK:   ('_section_data', '\x00\x00\x00\x00\x04\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xed\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00"\x00\x00\x00,\x00q\x00\x00\x00\x00')
+// CHECK:   ('_section_data', '\x00\x00\x00\x00\x04\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xed\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00"\x00\x00\x00,\x00q\x00\x00\x00\x00\x04\x00\x00\x00')
 // CHECK:     # Section 2
 // CHECK:    (('section_name', '__const\x00\x00\x00\x00\x00\x00\x00\x00\x00')
 // CHECK:     ('segment_name', '__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
-// CHECK:     ('address', 55)
+// CHECK:     ('address', 59)
 // CHECK:     ('size', 12)
-// CHECK:     ('offset', 447)
+// CHECK:     ('offset', 451)
 // CHECK:     ('alignment', 0)
-// CHECK:     ('reloc_offset', 548)
+// CHECK:     ('reloc_offset', 560)
 // CHECK:     ('num_reloc', 4)
 // CHECK:     ('flags', 0x0)
 // CHECK:     ('reserved1', 0)
@@ -161,17 +165,17 @@
 // CHECK:      ('word-1', 0x18)),
 // CHECK:     # Relocation 3
 // CHECK:     (('word-0', 0xa1000000),
-// CHECK:      ('word-1', 0x37)),
+// CHECK:      ('word-1', 0x3b)),
 // CHECK:   ])
-// CHECK:   ('_section_data', '\x02\x00\x00\x00;\x00\x00\x00\x00\x00\x00\x00')
+// CHECK:   ('_section_data', '\xfe\xff\xff\xff?\x00\x00\x00\x00\x00\x00\x00')
 // CHECK:   ])
 // CHECK:  ),
 // CHECK:   # Load Command 1
 // CHECK:  (('command', 2)
 // CHECK:   ('size', 24)
-// CHECK:   ('symoff', 580)
+// CHECK:   ('symoff', 592)
 // CHECK:   ('nsyms', 10)
-// CHECK:   ('stroff', 700)
+// CHECK:   ('stroff', 712)
 // CHECK:   ('strsize', 88)
 // CHECK:   ('_string_data', '\x00undef\x00local_a_ext\x00.objc_class_name_A\x00_f1\x00local_a\x00local_a_elt\x00local_b\x00local_c\x00bar\x00_f0\x00\x00\x00')
 // CHECK:   ('_symbols', [
@@ -212,7 +216,7 @@
 // CHECK:     ('n_type', 0xe)
 // CHECK:     ('n_sect', 3)
 // CHECK:     ('n_desc', 0)
-// CHECK:     ('n_value', 55)
+// CHECK:     ('n_value', 59)
 // CHECK:     ('_string', 'bar')
 // CHECK:    ),
 // CHECK:     # Symbol 5





More information about the llvm-commits mailing list