access-softek / msp430-clang

0 stars 2 forks source link

Relocation Types defined by EABI are different from clang supported #23

Open chbessonova opened 5 years ago

chbessonova commented 5 years ago

p. 11.5.1 and Table 12 MSP430-EABI define relocation types (18 of them)

R_MSP430_NONE      0
R_MSP430_ABS32     1      S + A
R_MSP430_ABS16     2      S + A
R_MSP430_ABS8      3      S + A
R_MSP430_PCR16     4      S + A - P
...

Types supported by clang (and gcc) are not mentioned in MSP430-EABI (except first one):

R_MSP430_NONE,               0
R_MSP430_32,                 1
R_MSP430_10_PCREL,           2
R_MSP430_16,                 3
R_MSP430_16_PCREL,           4
R_MSP430_16_BYTE,            5
R_MSP430_16_PCREL_BYTE,      6
R_MSP430_2X_PCREL,           7
R_MSP430_RL_PCREL,           8
R_MSP430_8,                  9
R_MSP430_SYM_DIFF,           10

This may cause incompatibility between TI/IAR and clang toolchains.

Note: gcc supports those types defined in MSP430-EABI, but according to the comments, they are used for MSP430x instructions.

asl commented 5 years ago

@mskvortsov does R_MSP430_ABS32 equal to R_MSP430_32, R_MSP430_ABS16 to R_MSP430_16 and so on?

mskvortsov commented 5 years ago

TI and bfd relocs have equal semantics in general but are definitely binary incompatible. It seems like the mapping is

TI EABI           | GNU BFD ABI
------------------+-------------------------------------------
R_MSP430_NONE     | R_MSP430_NONE
R_MSP430_ABS32    | R_MSP430_32
R_MSP430_ABS16    | R_MSP430_16, R_MSP430_16_BYTE
R_MSP430_ABS8     | R_MSP430_8
R_MSP430_PCR16    | R_MSP430_16_PCREL, R_MSP430_16_PCREL_BYTE
R_MSP430_ABS_HI16 | ?
R_MSP430_PREL31   | ?
?                 | R_MSP430_10_PCREL
?                 | R_MSP430_2X_PCREL
?                 | R_MSP430_RL_PCREL
?                 | R_MSP430_SYM_DIFF

Surprisingly enough, I don't see a match for bfd's R_MSP430_10_PCREL in the EABI spec. That type of reloc is essential for any jmp. It seems to me like the spec is bogus/incomplete/outdated in this part.