diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -119,7 +119,8 @@ continue; } flushPendingLabels(PendingFixup.DF, PendingFixup.DF->getContents().size()); - PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset()); + PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset() + + PendingFixup.Fixup.getOffset()); PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup); } PendingFixups.clear(); @@ -816,8 +817,9 @@ 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; } diff --git a/llvm/test/MC/RISCV/reloc-directive.s b/llvm/test/MC/RISCV/reloc-directive.s --- a/llvm/test/MC/RISCV/reloc-directive.s +++ b/llvm/test/MC/RISCV/reloc-directive.s @@ -22,6 +22,7 @@ # CHECK-NEXT: 0x0 R_RISCV_NONE - 0x9 # CHECK-NEXT: 0x0 R_RISCV_32 - 0x9 # CHECK-NEXT: 0x0 R_RISCV_64 - 0x9 +# CHECK-NEXT: 0x4 R_RISCV_32 - 0x6 .text ret nop @@ -38,6 +39,8 @@ .reloc 0, BFD_RELOC_32, 9 .reloc 0, BFD_RELOC_64, 9 + .reloc foo+4, R_RISCV_32, 6 + .data .globl foo foo: