[MC][Target] Implement support for R_X86_64_SIZE{32,64}.
authorDavide Italiano <davide@freebsd.org>
Wed, 4 Mar 2015 06:49:39 +0000 (06:49 +0000)
committerDavide Italiano <davide@freebsd.org>
Wed, 4 Mar 2015 06:49:39 +0000 (06:49 +0000)
Differential Revision: D7990
Reviewed by: rafael, majnemer

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

include/llvm/MC/MCExpr.h
lib/MC/MCExpr.cpp
lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
test/MC/ELF/relocation.s

index 5e2ef3f..c017fef 100644 (file)
@@ -188,6 +188,7 @@ public:
     VK_GOTPAGE,
     VK_GOTPAGEOFF,
     VK_SECREL,
+    VK_SIZE,      // symbol@SIZE
     VK_WEAKREF,   // The link between the symbols in .weakref foo, bar
 
     VK_ARM_NONE,
index 709dc6b..049113c 100644 (file)
@@ -192,6 +192,7 @@ StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
   case VK_GOTPAGE: return "GOTPAGE";
   case VK_GOTPAGEOFF: return "GOTPAGEOFF";
   case VK_SECREL: return "SECREL32";
+  case VK_SIZE: return "SIZE";
   case VK_WEAKREF: return "WEAKREF";
   case VK_ARM_NONE: return "none";
   case VK_ARM_TARGET1: return "target1";
@@ -311,6 +312,7 @@ MCSymbolRefExpr::getVariantKindForName(StringRef Name) {
     .Case("gotpageoff", VK_GOTPAGEOFF)
     .Case("imgrel", VK_COFF_IMGREL32)
     .Case("secrel32", VK_SECREL)
+    .Case("size", VK_SIZE)
     .Case("l", VK_PPC_LO)
     .Case("h", VK_PPC_HI)
     .Case("ha", VK_PPC_HA)
index e8b0b4c..569b811 100644 (file)
@@ -123,6 +123,9 @@ unsigned X86ELFObjectWriter::GetRelocType(const MCValue &Target,
         case MCSymbolRefExpr::VK_DTPOFF:
           Type = ELF::R_X86_64_DTPOFF64;
           break;
+        case MCSymbolRefExpr::VK_SIZE:
+          Type = ELF::R_X86_64_SIZE64;
+          break;
         }
         break;
       case X86::reloc_signed_4byte:
@@ -144,6 +147,9 @@ unsigned X86ELFObjectWriter::GetRelocType(const MCValue &Target,
         case MCSymbolRefExpr::VK_DTPOFF:
           Type = ELF::R_X86_64_DTPOFF32;
           break;
+        case MCSymbolRefExpr::VK_SIZE:
+          Type = ELF::R_X86_64_SIZE32;
+          break;
         }
         break;
       case FK_Data_4:
index c0e6007..1e0409f 100644 (file)
@@ -34,6 +34,13 @@ bar:
         movl  $_GLOBAL_OFFSET_TABLE_, %eax
         movabs  $_GLOBAL_OFFSET_TABLE_, %rax
 
+        .quad    blah@SIZE                        # R_X86_64_SIZE64
+        .quad    blah@SIZE + 32                   # R_X86_64_SIZE64
+        .quad    blah@SIZE - 32                   # R_X86_64_SIZE64
+         movl    blah@SIZE, %eax                  # R_X86_64_SIZE32
+         movl    blah@SIZE + 32, %eax             # R_X86_64_SIZE32
+         movl    blah@SIZE - 32, %eax             # R_X86_64_SIZE32
+
 // CHECK:        Section {
 // CHECK:          Name: .rela.text
 // CHECK:          Relocations [
@@ -62,6 +69,12 @@ bar:
 // CHECK-NEXT:       0x98 R_X86_64_PC32 foo 0xFFFFFFFFFFFFFFFB
 // CHECK-NEXT:       0x9D R_X86_64_GOTPC32 _GLOBAL_OFFSET_TABLE_ 0x1
 // CHECK-NEXT:       0xA3 R_X86_64_GOTPC64 _GLOBAL_OFFSET_TABLE_ 0x2
+// CHECK-NEXT:       0xAB R_X86_64_SIZE64 blah 0x0
+// CHECK-NEXT:       0xB3 R_X86_64_SIZE64 blah 0x20
+// CHECK-NEXT:       0xBB R_X86_64_SIZE64 blah 0xFFFFFFFFFFFFFFE0
+// CHECK-NEXT:       0xC6 R_X86_64_SIZE32 blah 0x0
+// CHECK-NEXT:       0xCD R_X86_64_SIZE32 blah 0x20
+// CHECK-NEXT:       0xD4 R_X86_64_SIZE32 blah 0xFFFFFFFFFFFFFFE0
 // CHECK-NEXT:     ]
 // CHECK-NEXT:   }