[llvm-commits] [llvm] r125648 - in /llvm/trunk: include/llvm/MC/MCObjectWriter.h lib/MC/ELFObjectWriter.cpp lib/MC/MCAssembler.cpp lib/MC/MCObjectWriter.cpp lib/MC/WinCOFFObjectWriter.cpp test/MC/ELF/relax.s

Rafael Espindola rafael.espindola at gmail.com
Tue Feb 15 19:25:55 PST 2011


Author: rafael
Date: Tue Feb 15 21:25:55 2011
New Revision: 125648

URL: http://llvm.org/viewvc/llvm-project?rev=125648&view=rev
Log:
Gas is very inconsistent about when a relaxation/relocation is needed. Do
the right thing and stop trying to copy it. Fixes PR8944.

Modified:
    llvm/trunk/include/llvm/MC/MCObjectWriter.h
    llvm/trunk/lib/MC/ELFObjectWriter.cpp
    llvm/trunk/lib/MC/MCAssembler.cpp
    llvm/trunk/lib/MC/MCObjectWriter.cpp
    llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
    llvm/trunk/test/MC/ELF/relax.s

Modified: llvm/trunk/include/llvm/MC/MCObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectWriter.h?rev=125648&r1=125647&r2=125648&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectWriter.h Tue Feb 15 21:25:55 2011
@@ -96,7 +96,7 @@
                                          const MCSymbolData &DataA,
                                          const MCFragment &FB,
                                          bool InSet,
-                                         bool IsPCRel) const = 0;
+                                         bool IsPCRel) const;
 
 
   /// Write the object file.

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=125648&r1=125647&r2=125648&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Tue Feb 15 21:25:55 2011
@@ -359,13 +359,6 @@
                                           MCDataFragment *F,
                                           const MCSectionData *SD);
 
-    virtual bool
-    IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
-                                           const MCSymbolData &DataA,
-                                           const MCFragment &FB,
-                                           bool InSet,
-                                           bool IsPCRel) const;
-
     virtual void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout);
     virtual void WriteSection(MCAssembler &Asm,
                       const SectionIndexMapTy &SectionIndexMap,
@@ -1181,24 +1174,6 @@
   }
 }
 
-bool
-ELFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
-                                                      const MCSymbolData &DataA,
-                                                      const MCFragment &FB,
-                                                      bool InSet,
-                                                      bool IsPCRel) const {
-  // FIXME: This is in here just to match gnu as output. If the two ends
-  // are in the same section, there is nothing that the linker can do to
-  // break it.
-  if (DataA.isExternal())
-    return false;
-
-  const MCSection &SecA = DataA.getSymbol().AliasedSymbol().getSection();
-  const MCSection &SecB = FB.getParent()->getSection();
-  // On ELF A - B is absolute if A and B are in the same section.
-  return &SecA == &SecB;
-}
-
 void ELFObjectWriter::CreateIndexedSections(MCAssembler &Asm,
                                             MCAsmLayout &Layout,
                                             GroupMapTy &GroupMap,

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=125648&r1=125647&r2=125648&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Tue Feb 15 21:25:55 2011
@@ -229,8 +229,10 @@
     } else if (!Target.getSymA()) {
       IsResolved = false;
     } else {
-      const MCSymbol &SA = Target.getSymA()->getSymbol();
-      if (SA.AliasedSymbol().isUndefined()) {
+      const MCSymbolRefExpr *A = Target.getSymA();
+      const MCSymbol &SA = A->getSymbol();
+      if (A->getKind() != MCSymbolRefExpr::VK_None ||
+          SA.AliasedSymbol().isUndefined()) {
         IsResolved = false;
       } else {
         const MCSymbolData &DataA = getSymbolData(SA);

Modified: llvm/trunk/lib/MC/MCObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectWriter.cpp?rev=125648&r1=125647&r2=125648&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectWriter.cpp Tue Feb 15 21:25:55 2011
@@ -66,3 +66,15 @@
                                                 InSet,
                                                 false);
 }
+
+bool
+MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
+                                                      const MCSymbolData &DataA,
+                                                      const MCFragment &FB,
+                                                      bool InSet,
+                                                      bool IsPCRel) const {
+  const MCSection &SecA = DataA.getSymbol().AliasedSymbol().getSection();
+  const MCSection &SecB = FB.getParent()->getSection();
+  // On ELF and COFF  A - B is absolute if A and B are in the same section.
+  return &SecA == &SecB;
+}

Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=125648&r1=125647&r2=125648&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Tue Feb 15 21:25:55 2011
@@ -179,13 +179,6 @@
                         MCValue Target,
                         uint64_t &FixedValue);
 
-  virtual bool
-  IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
-                                         const MCSymbolData &DataA,
-                                         const MCFragment &FB,
-                                         bool InSet,
-                                         bool IsPCRel) const;
-
   void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout);
 };
 }
@@ -719,19 +712,6 @@
   coff_section->Relocations.push_back(Reloc);
 }
 
-bool
-WinCOFFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
-                                                      const MCAssembler &Asm,
-                                                      const MCSymbolData &DataA,
-                                                      const MCFragment &FB,
-                                                      bool InSet,
-                                                      bool IsPCRel) const {
-  const MCSection &SecA = DataA.getSymbol().AliasedSymbol().getSection();
-  const MCSection &SecB = FB.getParent()->getSection();
-  // On COFF A - B is absolute if A and B are in the same section.
-  return &SecA == &SecB;
-}
-
 void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
                                       const MCAsmLayout &Layout) {
   // Assign symbol and section indexes and offsets.

Modified: llvm/trunk/test/MC/ELF/relax.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/relax.s?rev=125648&r1=125647&r2=125648&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/relax.s (original)
+++ llvm/trunk/test/MC/ELF/relax.s Tue Feb 15 21:25:55 2011
@@ -1,10 +1,6 @@
 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump  --dump-section-data | FileCheck  %s
 
-// Test that we do a relaxation for foo but not for bar or zed. Relaxing foo is
-// probably not necessary, but matches what gnu as does.
-
-// Also test that the relaxation done for foo uses the symbol, not section and
-// offset.
+// Test that we do not relax these.
 
 bar:
 .globl foo
@@ -20,22 +16,12 @@
 // CHECK-NEXT: ('sh_flags', 0x00000006)
 // CHECK-NEXT: ('sh_addr', 0x00000000)
 // CHECK-NEXT: ('sh_offset', 0x00000040)
-// CHECK-NEXT: ('sh_size', 0x00000009)
+// CHECK-NEXT: ('sh_size', 0x00000006)
 // CHECK-NEXT: ('sh_link', 0x00000000)
 // CHECK-NEXT: ('sh_info', 0x00000000)
 // CHECK-NEXT: ('sh_addralign', 0x00000004)
 // CHECK-NEXT: ('sh_entsize', 0x00000000)
-// CHECK-NEXT: ('_section_data', 'ebfee900 000000eb f7')
+// CHECK-NEXT: ('_section_data', 'ebfeebfc ebfa')
 
 // CHECK:       # Symbol 0x00000006
 // CHECK-NEXT: (('st_name', 0x00000005) # 'foo'
-
-// CHECK: .rela.text
-// CHECK: ('_relocations', [
-// CHECK-NEXT: Relocation 0x00000000
-// CHECK-NEXT:  (('r_offset', 0x00000003)
-// CHECK-NEXT:   ('r_sym', 0x00000006)
-// CHECK-NEXT:   ('r_type', 0x00000002)
-// CHECK-NEXT:   ('r_addend', 0xfffffffc)
-// CHECK-NEXT:  ),
-// CHECK-NEXT: ])





More information about the llvm-commits mailing list