[PATCH] support for directive .reloc

Akira Hatanaka ahatanak at gmail.com
Wed Dec 11 22:14:23 PST 2013


The attached patch adds support for .reloc directives, which I believe hasn't been implemented yet.

https://sourceware.org/binutils/docs/as/Reloc.html#Reloc

The initial motivation for adding this support was to enable linker optimization for mips. .reloc serves as a hint to the linker to turn a function call using jalr (jump and link register) into a pc-relative bal (branch and link), if the callee is close enough to the jalr.

(before optimization)
lw      $25,%call16(foo2)($28)
.reloc  $L1,R_MIPS_JALR,foo2
$L1: jalr      $25

(after optimization)
lw      $25,%call16(foo2)($28)
bal foo2

I also made a change in ELFObjectFile.h that was necessary for mips to print the symbol against which a relocation is applied (needed this for the test case).


http://llvm-reviews.chandlerc.com/D2393

Files:
  include/llvm/MC/MCAsmBackend.h
  include/llvm/MC/MCAssembler.h
  include/llvm/MC/MCObjectStreamer.h
  include/llvm/MC/MCStreamer.h
  include/llvm/Object/ELFObjectFile.h
  lib/MC/MCAsmStreamer.cpp
  lib/MC/MCAssembler.cpp
  lib/MC/MCObjectStreamer.cpp
  lib/MC/MCParser/AsmParser.cpp
  lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
  lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
  lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h
  test/MC/Mips/reloc.s
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2393.1.patch
Type: text/x-patch
Size: 14561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131211/afa58f05/attachment.bin>


More information about the llvm-commits mailing list