ELF can handle some relocations of the form -sym + constant.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 2 Nov 2015 19:13:59 +0000 (19:13 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 2 Nov 2015 19:13:59 +0000 (19:13 +0000)
Remove code that was assuming that this would never work.

Thanks to Colin LeMahie for finding and diagnosing the bug.

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

include/llvm/MC/MCValue.h
lib/MC/MCExpr.cpp
test/MC/ELF/relocation-pc.s

index 6bdf43685f211c131dfcc40a8255621e0de2ec84..ead08fd90ca06ff20c9f1adc7bd7ae9111c14636 100644 (file)
@@ -35,10 +35,6 @@ class raw_ostream;
 /// relocation modifiers apply to the closest symbol or the whole
 /// expression.
 ///
 /// relocation modifiers apply to the closest symbol or the whole
 /// expression.
 ///
-/// In the general form, SymbolB can only be defined if SymbolA is, and both
-/// must be in the same (non-external) section. The latter constraint is not
-/// enforced, since a symbol's section may not be known at construction.
-///
 /// Note that this class must remain a simple POD value class, because we need
 /// it to live in unions etc.
 class MCValue {
 /// Note that this class must remain a simple POD value class, because we need
 /// it to live in unions etc.
 class MCValue {
@@ -67,7 +63,6 @@ public:
                      const MCSymbolRefExpr *SymB = nullptr,
                      int64_t Val = 0, uint32_t RefKind = 0) {
     MCValue R;
                      const MCSymbolRefExpr *SymB = nullptr,
                      int64_t Val = 0, uint32_t RefKind = 0) {
     MCValue R;
-    assert((!SymB || SymA) && "Invalid relocatable MCValue!");
     R.Cst = Val;
     R.SymA = SymA;
     R.SymB = SymB;
     R.Cst = Val;
     R.SymA = SymA;
     R.SymB = SymB;
index caa502086a0324111fc135cf53162b535a8bdaeb..56524031d69b8e0c0e41637f1276d1a556b96ed1 100644 (file)
@@ -585,11 +585,6 @@ EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout,
   const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A;
   const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B;
 
   const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A;
   const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B;
 
-  // If we have a negated symbol, then we must have also have a non-negated
-  // symbol in order to encode the expression.
-  if (B && !A)
-    return false;
-
   Res = MCValue::get(A, B, Result_Cst);
   return true;
 }
   Res = MCValue::get(A, B, Result_Cst);
   return true;
 }
index 28a911db8d961c7bbaa30255b095fe8e66d01894..85e97f05958436aa85944ef022e9360ed837e57c 100644 (file)
@@ -4,6 +4,7 @@
 
         loope   0                 # R_X86_64_PC8
         jmp     -256              # R_X86_64_PC32
 
         loope   0                 # R_X86_64_PC8
         jmp     -256              # R_X86_64_PC32
+        .word 0x42 - .            # R_X86_64_PC16
 
 // CHECK:        Section {
 // CHECK:          Index:
 
 // CHECK:        Section {
 // CHECK:          Index:
@@ -13,7 +14,7 @@
 // CHECK-NEXT:     ]
 // CHECK-NEXT:     Address: 0x0
 // CHECK-NEXT:     Offset:
 // CHECK-NEXT:     ]
 // CHECK-NEXT:     Address: 0x0
 // CHECK-NEXT:     Offset:
-// CHECK-NEXT:     Size: 48
+// CHECK-NEXT:     Size:
 // CHECK-NEXT:     Link:
 // CHECK-NEXT:     Info:
 // CHECK-NEXT:     AddressAlignment: 8
 // CHECK-NEXT:     Link:
 // CHECK-NEXT:     Info:
 // CHECK-NEXT:     AddressAlignment: 8
@@ -21,5 +22,6 @@
 // CHECK-NEXT:     Relocations [
 // CHECK-NEXT:       0x1 R_X86_64_PC8 - 0xFFFFFFFFFFFFFFFF
 // CHECK-NEXT:       0x3 R_X86_64_PC32 - 0xFFFFFFFFFFFFFEFC
 // CHECK-NEXT:     Relocations [
 // CHECK-NEXT:       0x1 R_X86_64_PC8 - 0xFFFFFFFFFFFFFFFF
 // CHECK-NEXT:       0x3 R_X86_64_PC32 - 0xFFFFFFFFFFFFFEFC
+// CHECK-NEXT:       0x7 R_X86_64_PC16 - 0x42
 // CHECK-NEXT:     ]
 // CHECK-NEXT:   }
 // CHECK-NEXT:     ]
 // CHECK-NEXT:   }