OSDN Git Service

[RISCV] Add symbol diff relocation support for RISC-V
authorAlex Bradbury <asb@lowrisc.org>
Wed, 23 May 2018 12:36:18 +0000 (12:36 +0000)
committerAlex Bradbury <asb@lowrisc.org>
Wed, 23 May 2018 12:36:18 +0000 (12:36 +0000)
commite54d539419dbb8b441be47fc08b8d98a6e657535
treedd722a4585436af38fb704e279c279913c19c325
parent8ee85f1e7afeae57166d75fe827860c679e51032
[RISCV] Add symbol diff relocation support for RISC-V

For RISC-V it is desirable to have relaxation happen in the linker once
addresses are known, and as such the size between two instructions/byte
sequences in a section could change.

For most assembler expressions, this is fine, as the absolute address results
in the expression being converted to a fixup, and finally relocations.
However, for expressions such as .quad .L2-.L1, the assembler folds this down
to a constant once fragments are laid out, under the assumption that the
difference can no longer change, although in the case of linker relaxation the
differences can change at link time, so the constant is incorrect. One place
where this commonly appears is in debug information, where the size of a
function expression is in a form similar to the above.

This patch extends the assembler to allow an AsmBackend to declare that it
does not want the assembler to fold down this expression, and instead generate
a pair of relocations that allow the linker to carry out the calculation. In
this case, the expression is not folded, but when it comes to emitting a
fixup, the generic FK_Data_* fixups are converted into a pair, one for the
addition half, one for the subtraction, and this is passed to the relocation
generating methods as usual. I have named these FK_Data_Add_* and
FK_Data_Sub_* to indicate which half these are for.

For RISC-V, which supports this via e.g. the R_RISCV_ADD64, R_RISCV_SUB64 pair
of relocations, these are also set to always emit relocations relative to
local symbols rather than section offsets. This is to deal with the fact that
if relocations were calculated on e.g. .text+8 and .text+4, the result 12
would be stored rather than 4 as both addends are added in the linker.

Differential Revision: https://reviews.llvm.org/D45181
Patch by Simon Cook.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333079 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/MC/MCAsmBackend.h
include/llvm/MC/MCFixup.h
lib/MC/MCAsmBackend.cpp
lib/MC/MCAssembler.cpp
lib/MC/MCExpr.cpp
lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp
test/MC/RISCV/fixups-expr.s [new file with mode: 0644]
test/MC/RISCV/hilo-constaddr-expr.s [new file with mode: 0644]
test/MC/RISCV/hilo-constaddr.s