forked from OSchip/llvm-project
[MC] Support constant offset for symbol PendingFixup
This patch add support relocation offset of sym+constant(like `foo+4`) form for pending fixup. In the past, llvm-mc ignored the constant in sym+constant form, for `foo+4`, `4` would be ignored. And test case ``` .text ret nop nop .reloc foo+4, R_RISCV_32, 6 .data .globl foo foo: .word 0 .word 0 .word 0 ``` when run `llvm-mc -filetype=obj -triple=riscv64 %s | llvm-readobj -r` The output is ``` Relocations [ Section (3) .rela.text { 0x0 R_RISCV_32 - 0x6 } ] ``` After applying this patch, the output is ``` Relocations [ Section (3) .rela.text { 0x4 R_RISCV_32 - 0x6 } ] ``` Differential Revision: https://reviews.llvm.org/D117316
This commit is contained in:
parent
cc4beda039
commit
d606e23305
|
@ -119,7 +119,8 @@ void MCObjectStreamer::resolvePendingFixups() {
|
|||
continue;
|
||||
}
|
||||
flushPendingLabels(PendingFixup.DF, PendingFixup.DF->getContents().size());
|
||||
PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset());
|
||||
PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset() +
|
||||
PendingFixup.Fixup.getOffset());
|
||||
|
||||
// If the location symbol to relocate is in MCEncodedFragmentWithFixups,
|
||||
// put the Fixup into location symbol's fragment. Otherwise
|
||||
|
@ -838,8 +839,9 @@ MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
|
|||
return None;
|
||||
}
|
||||
|
||||
PendingFixups.emplace_back(&SRE.getSymbol(), DF,
|
||||
MCFixup::create(-1, Expr, Kind, Loc));
|
||||
PendingFixups.emplace_back(
|
||||
&SRE.getSymbol(), DF,
|
||||
MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
# CHECK: Section ({{.*}}) .rela.data {
|
||||
# CHECK-NEXT: 0x0 R_RISCV_32 - 0x6
|
||||
# CHECK-NEXT: 0x4 R_RISCV_32 - 0x6
|
||||
# CHECK-NEXT: }
|
||||
|
||||
# CHECK: Section ({{.*}}) .rela.debug_line {
|
||||
|
@ -55,6 +56,7 @@
|
|||
.reloc line, R_RISCV_32, 6
|
||||
.reloc probe, R_RISCV_32, 6
|
||||
|
||||
.reloc foo+4, R_RISCV_32, 6
|
||||
.data
|
||||
.globl foo
|
||||
foo:
|
||||
|
|
Loading…
Reference in New Issue