[MSP430] Use R_MSP430_16_BYTE type for FK_Data_2 fixup
authorAnton Korobeynikov <anton@korobeynikov.info>
Fri, 16 Nov 2018 19:20:51 +0000 (19:20 +0000)
committerAnton Korobeynikov <anton@korobeynikov.info>
Fri, 16 Nov 2018 19:20:51 +0000 (19:20 +0000)
Linker fails to link example like this (simplified case from newlib
sources):

$ cat test.c

extern const char _ctype_b[];
struct _t { char *ptr; };
struct _t T = { ((char *) _ctype_b + 3) };
$ cat ctype.c

char _ctype_b[4] = { 0, 0, 0, 0 };
LD: test.o:(.data+0x0): warning: internal error: unsupported relocation error

We also follow gnu toolchain here, where 2-byte relocation mapped to
R_MSP430_16_BYTE, instead of R_MSP430_16.

Patch by Kristina Bessonova!

Differential Revision: https://reviews.llvm.org/D54620

llvm-svn: 347074

llvm/lib/Target/MSP430/MCTargetDesc/MSP430ELFObjectWriter.cpp
llvm/test/MC/MSP430/reloc.s

index 30d077b..e47db24 100644 (file)
@@ -34,7 +34,7 @@ protected:
     // Translate fixup kind to ELF relocation type.
     switch ((unsigned)Fixup.getKind()) {
     case FK_Data_1:                   return ELF::R_MSP430_8;
-    case FK_Data_2:                   return ELF::R_MSP430_16;
+    case FK_Data_2:                   return ELF::R_MSP430_16_BYTE;
     case FK_Data_4:                   return ELF::R_MSP430_32;
     case MSP430::fixup_32:            return ELF::R_MSP430_32;
     case MSP430::fixup_10_pcrel:      return ELF::R_MSP430_10_PCREL;
index 42dd64a..61a25f4 100644 (file)
@@ -20,3 +20,8 @@
          jmp    foo
 ; CHECK: jmp    foo             ; encoding: [A,0b001111AA]
 ; CHECK:                        ;   fixup A - offset: 0, value: foo, kind: fixup_10_pcrel
+
+; RUN: llvm-mc -filetype=obj -triple msp430 < %s | llvm-readobj -r \
+; RUN:   | FileCheck -check-prefix=RELOC %s
+.short  _ctype+3
+; RELOC: R_MSP430_16_BYTE _ctype 0x3