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()); // If the location symbol to relocate is in MCEncodedFragmentWithFixups, // put the Fixup into location symbol's fragment. Otherwise @@ -838,8 +839,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 @@ -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: