Produce a R_X86_64_32 when the value is >=0.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 20 Sep 2010 19:20:47 +0000 (19:20 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 20 Sep 2010 19:20:47 +0000 (19:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114339 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/ELFObjectWriter.cpp
test/MC/ELF/basic-elf.ll
test/MC/ELF/relocation.s [new file with mode: 0644]

index 35f029d2fa11ec27b58bb55f85f50d550c25388c..ebbba1327ddc90bf667f41561d8fc6e07c1fcaa6 100644 (file)
@@ -541,10 +541,13 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
       case X86::reloc_pcrel_4byte:
       case FK_Data_4:
         // check that the offset fits within a signed long
-        if (isInt<32>(Target.getConstant()))
+        if (Target.getConstant() < 0) {
+          assert(isInt<32>(Target.getConstant()));
           Type = ELF::R_X86_64_32S;
-        else
+        } else {
+          assert(isUInt<32>(Target.getConstant()));
           Type = ELF::R_X86_64_32;
+        }
         break;
       case FK_Data_2: Type = ELF::R_X86_64_16; break;
       case X86::reloc_pcrel_1byte:
index abdce7e35898178776dcb8967fdf8ec8a45af72b..bc9ec131860275295c87171b231e61f5c561883b 100644 (file)
@@ -72,7 +72,7 @@ declare i32 @puts(i8* nocapture) nounwind
 ; 64:   ('_relocations', [
 ; 64:     # Relocation 0
 ; 64:     (('r_offset', 5)
-; 64:      ('r_type', 11)
+; 64:      ('r_type', 10)
 ; 64:      ('r_addend', 0)
 ; 64:     ),
 ; 64:     # Relocation 1
@@ -82,7 +82,7 @@ declare i32 @puts(i8* nocapture) nounwind
 ; 64:     ),
 ; 64:     # Relocation 2
 ; 64:     (('r_offset', 15)
-; 64:      ('r_type', 11)
+; 64:      ('r_type', 10)
 ; 64:      ('r_addend', 6)
 ; 64:     ),
 ; 64:     # Relocation 3
diff --git a/test/MC/ELF/relocation.s b/test/MC/ELF/relocation.s
new file mode 100644 (file)
index 0000000..b9b87dd
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump  --dump-section-data | FileCheck  %s
+
+// Test that we produce a R_X86_64_32.
+
+        .long   Lset1
+
+
+// CHECK: # Relocation 0
+// CHECK-NEXT:  (('r_offset', 0)
+// CHECK-NEXT:   ('r_sym', 4)
+// CHECK-NEXT:   ('r_type', 10)
+// CHECK-NEXT:   ('r_addend', 0)