Skip to content

Commit 0fdd924

Browse files
chbessonovaasl
authored andcommitted
[MSP430] Use R_MSP430_16_BYTE type for FK_Data_2 fixup
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 }; LLD: test.c:(.data+0x0): invalid value in R_MSP430_16 GNU 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_MSP320_16.
1 parent 9ff50a3 commit 0fdd924

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/llvm/lib/Target/MSP430/MCTargetDesc/MSP430ELFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MSP430ELFObjectWriter : public MCELFObjectTargetWriter {
3434
// Translate fixup kind to ELF relocation type.
3535
switch ((unsigned)Fixup.getKind()) {
3636
case FK_Data_1: return ELF::R_MSP430_8;
37-
case FK_Data_2: return ELF::R_MSP430_16;
37+
case FK_Data_2: return ELF::R_MSP430_16_BYTE;
3838
case FK_Data_4: return ELF::R_MSP430_32;
3939
case MSP430::fixup_32: return ELF::R_MSP430_32;
4040
case MSP430::fixup_10_pcrel: return ELF::R_MSP430_10_PCREL;

src/llvm/test/MC/MSP430/reloc.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
; RUN: llvm-mc -triple msp430 -show-encoding < %s | FileCheck %s
2+
; RUN: llvm-mc -filetype=obj -triple msp430 < %s | llvm-readobj -r \
3+
; RUN: | FileCheck -check-prefix=RELOC %s
24

35
mov disp+2(r8), r15
46
; CHECK: mov disp+2(r8), r15 ; encoding: [0x1f,0x48,A,A]
57
; CHECK: ; fixup A - offset: 2, value: disp+2, kind: fixup_16_byte
8+
; RELOC: R_MSP430_16_BYTE disp 0x2
69

710
mov disp+2, r15
811
; CHECK: mov disp+2, r15 ; encoding: [0x1f,0x40,A,A]
912
; CHECK: ; fixup A - offset: 2, value: disp+2, kind: fixup_16_pcrel_byte
13+
; RELOC: R_MSP430_16_PCREL_BYTE disp 0x2
1014

1115
mov &disp+2, r15
1216
; CHECK: mov &disp+2, r15 ; encoding: [0x1f,0x42,A,A]
1317
; CHECK: ; fixup A - offset: 2, value: disp+2, kind: fixup_16
18+
; RELOC: R_MSP430_16_BYTE disp 0x2
1419

1520
mov disp, disp+2
1621
; CHECK: mov disp, disp+2 ; encoding: [0x90,0x40,A,A,B,B]
1722
; CHECK: ; fixup A - offset: 2, value: disp, kind: fixup_16_pcrel_byte
1823
; CHECK: ; fixup B - offset: 4, value: disp+2, kind: fixup_16_pcrel_byte
24+
; RELOC: R_MSP430_16_PCREL_BYTE disp 0x0
25+
; RELOC: R_MSP430_16_PCREL_BYTE disp 0x2
1926

2027
jmp foo
2128
; CHECK: jmp foo ; encoding: [A,0b001111AA]
2229
; CHECK: ; fixup A - offset: 0, value: foo, kind: fixup_10_pcrel
30+
; RELOC: R_MSP430_10_PCREL foo 0x0
31+
32+
.short _ctype+2
33+
; RELOC: R_MSP430_16_BYTE _ctype 0x2

0 commit comments

Comments
 (0)