MC/Mach-O: Mark absolute variable's appropriately, and add Mach-O support for
authorDaniel Dunbar <daniel@zuster.org>
Wed, 5 May 2010 19:01:05 +0000 (19:01 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 5 May 2010 19:01:05 +0000 (19:01 +0000)
writing them.
 - <rdar://problem/7885351> integrated assembler broken for i386 objc code

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

lib/MC/MCAsmStreamer.cpp
lib/MC/MCMachOStreamer.cpp
lib/MC/MCSymbol.cpp
lib/MC/MachObjectWriter.cpp
test/MC/MachO/reloc.s

index 1d231bbffa0ef89eac2952da797f5b599020a944..22b1a376e3aacb5768660800cf16424da95a15dc 100644 (file)
@@ -239,7 +239,6 @@ void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
   EmitEOL();
 
   // FIXME: Lift context changes into super class.
-  // FIXME: Set associated section.
   Symbol->setVariableValue(Value);
 }
 
index b4bd55753588bb4f8ebbe10b2789a4854d165ad0..5ca31943f1f7485ab700aae161397db49c16425f 100644 (file)
@@ -193,7 +193,6 @@ void MCMachOStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
 
 void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
   // FIXME: Lift context changes into super class.
-  // FIXME: Set associated section.
   Symbol->setVariableValue(AddValueSymbols(Value));
 }
 
index 82d72a3e95b3be2981d00da73cc5716155e0b86e..07751f7298443e5de4e9e0ea432a954be66114bb 100644 (file)
@@ -44,6 +44,10 @@ void MCSymbol::setVariableValue(const MCExpr *Value) {
   assert((isUndefined() || (isAbsolute() && isa<MCConstantExpr>(Value))) &&
          "Invalid redefinition!");
   this->Value = Value;
+
+  // Mark the variable as absolute as appropriate.
+  if (isa<MCConstantExpr>(Value))
+    setAbsolute();
 }
 
 void MCSymbol::print(raw_ostream &OS) const {
index f4aef96e302963ee5e885ef68d69f12df8017451..bb8eb10a483899fab6b19d4439d4396eac98a5d7 100644 (file)
@@ -404,7 +404,7 @@ public:
     // Compute the symbol address.
     if (Symbol.isDefined()) {
       if (Symbol.isAbsolute()) {
-        llvm_unreachable("FIXME: Not yet implemented!");
+        Address = cast<MCConstantExpr>(Symbol.getVariableValue())->getValue();
       } else {
         Address = Layout.getSymbolAddress(&Data);
       }
@@ -552,7 +552,7 @@ public:
       // possible. This seems to be done because the debugger doesn't fully
       // understand x86_64 relocation entries, and expects to find values that
       // have already been fixed up.
-      if (Symbol->isDefined()) {
+      if (Symbol->isInSection()) {
         const MCSectionMachO &Section = static_cast<const MCSectionMachO&>(
           Fragment->getParent()->getSection());
         if (Section.hasAttribute(MCSectionMachO::S_ATTR_DEBUG))
index c305eeb723c331aa00776bff59c26011528f9e8c..73a69c3cc549fa6aa5d40bf7d2fe76db34f3e01f 100644 (file)
@@ -41,6 +41,9 @@ L1:
         jmp L1
         ret
 
+        .objc_class_name_A=0
+       .globl .objc_class_name_A
+
 // CHECK: ('cputype', 7)
 // CHECK: ('cpusubtype', 3)
 // CHECK: ('filetype', 1)
@@ -117,10 +120,10 @@ L1:
 // CHECK:      ('word-1', 0x4000002)),
 // CHECK:     # Relocation 7
 // CHECK:     (('word-0', 0x4),
-// CHECK:      ('word-1', 0xc000007)),
+// CHECK:      ('word-1', 0xc000008)),
 // CHECK:     # Relocation 8
 // CHECK:     (('word-0', 0x0),
-// CHECK:      ('word-1', 0xc000007)),
+// CHECK:      ('word-1', 0xc000008)),
 // 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')
 // CHECK:     # Section 2
@@ -157,13 +160,13 @@ L1:
 // CHECK:  (('command', 2)
 // CHECK:   ('size', 24)
 // CHECK:   ('symoff', 568)
-// CHECK:   ('nsyms', 8)
-// CHECK:   ('stroff', 664)
-// CHECK:   ('strsize', 64)
-// CHECK:   ('_string_data', '\x00undef\x00local_a_ext\x00local_a\x00local_a_elt\x00local_b\x00local_c\x00bar\x00_f0\x00\x00')
+// CHECK:   ('nsyms', 9)
+// CHECK:   ('stroff', 676)
+// CHECK:   ('strsize', 84)
+// CHECK:   ('_string_data', '\x00undef\x00local_a_ext\x00.objc_class_name_A\x00local_a\x00local_a_elt\x00local_b\x00local_c\x00bar\x00_f0\x00\x00\x00')
 // CHECK:   ('_symbols', [
 // CHECK:     # Symbol 0
-// CHECK:    (('n_strx', 19)
+// CHECK:    (('n_strx', 38)
 // CHECK:     ('n_type', 0xe)
 // CHECK:     ('n_sect', 2)
 // CHECK:     ('n_desc', 0)
@@ -171,7 +174,7 @@ L1:
 // CHECK:     ('_string', 'local_a')
 // CHECK:    ),
 // CHECK:     # Symbol 1
-// CHECK:    (('n_strx', 27)
+// CHECK:    (('n_strx', 46)
 // CHECK:     ('n_type', 0xe)
 // CHECK:     ('n_sect', 2)
 // CHECK:     ('n_desc', 0)
@@ -179,7 +182,7 @@ L1:
 // CHECK:     ('_string', 'local_a_elt')
 // CHECK:    ),
 // CHECK:     # Symbol 2
-// CHECK:    (('n_strx', 39)
+// CHECK:    (('n_strx', 58)
 // CHECK:     ('n_type', 0xe)
 // CHECK:     ('n_sect', 2)
 // CHECK:     ('n_desc', 0)
@@ -187,7 +190,7 @@ L1:
 // CHECK:     ('_string', 'local_b')
 // CHECK:    ),
 // CHECK:     # Symbol 3
-// CHECK:    (('n_strx', 47)
+// CHECK:    (('n_strx', 66)
 // CHECK:     ('n_type', 0xe)
 // CHECK:     ('n_sect', 2)
 // CHECK:     ('n_desc', 0)
@@ -195,7 +198,7 @@ L1:
 // CHECK:     ('_string', 'local_c')
 // CHECK:    ),
 // CHECK:     # Symbol 4
-// CHECK:    (('n_strx', 55)
+// CHECK:    (('n_strx', 74)
 // CHECK:     ('n_type', 0xe)
 // CHECK:     ('n_sect', 3)
 // CHECK:     ('n_desc', 0)
@@ -203,7 +206,7 @@ L1:
 // CHECK:     ('_string', 'bar')
 // CHECK:    ),
 // CHECK:     # Symbol 5
-// CHECK:    (('n_strx', 59)
+// CHECK:    (('n_strx', 78)
 // CHECK:     ('n_type', 0xe)
 // CHECK:     ('n_sect', 1)
 // CHECK:     ('n_desc', 0)
@@ -211,6 +214,14 @@ L1:
 // CHECK:     ('_string', '_f0')
 // CHECK:    ),
 // CHECK:     # Symbol 6
+// CHECK:    (('n_strx', 19)
+// CHECK:     ('n_type', 0x3)
+// CHECK:     ('n_sect', 0)
+// CHECK:     ('n_desc', 0)
+// CHECK:     ('n_value', 0)
+// CHECK:     ('_string', '.objc_class_name_A')
+// CHECK:    ),
+// CHECK:     # Symbol 7
 // CHECK:    (('n_strx', 7)
 // CHECK:     ('n_type', 0xf)
 // CHECK:     ('n_sect', 2)
@@ -218,7 +229,7 @@ L1:
 // CHECK:     ('n_value', 16)
 // CHECK:     ('_string', 'local_a_ext')
 // CHECK:    ),
-// CHECK:     # Symbol 7
+// CHECK:     # Symbol 8
 // CHECK:    (('n_strx', 1)
 // CHECK:     ('n_type', 0x1)
 // CHECK:     ('n_sect', 0)
@@ -234,8 +245,8 @@ L1:
 // CHECK:   ('ilocalsym', 0)
 // CHECK:   ('nlocalsym', 6)
 // CHECK:   ('iextdefsym', 6)
-// CHECK:   ('nextdefsym', 1)
-// CHECK:   ('iundefsym', 7)
+// CHECK:   ('nextdefsym', 2)
+// CHECK:   ('iundefsym', 8)
 // CHECK:   ('nundefsym', 1)
 // CHECK:   ('tocoff', 0)
 // CHECK:   ('ntoc', 0)