Index: lib/MC/MCExpr.cpp =================================================================== --- lib/MC/MCExpr.cpp +++ lib/MC/MCExpr.cpp @@ -607,7 +607,9 @@ // the InSet flag is set to get the current difference anyway (used for // example to calculate symbol sizes). if (Asm && - (InSet || !Asm->getBackend().requiresDiffExpressionRelocations())) { + (InSet || (LHS_A && !LHS_A->getSymbol().getSection().hasInstructions()) || + (LHS_B && !LHS_B->getSymbol().getSection().hasInstructions()) || + !Asm->getBackend().requiresDiffExpressionRelocations())) { // First, fold out any differences which are fully resolved. By // reassociating terms in // Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst). Index: test/DebugInfo/RISCV/relax-debug-frame.ll =================================================================== --- test/DebugInfo/RISCV/relax-debug-frame.ll +++ test/DebugInfo/RISCV/relax-debug-frame.ll @@ -2,10 +2,12 @@ ; RUN: | llvm-readobj -r | FileCheck -check-prefix=RELAX %s ; ; RELAX: .rela.{{eh|debug}}_frame { -; RELAX: R_RISCV_ADD32 -; RELAX: R_RISCV_SUB32 -; RELAX: R_RISCV_SET6 -; RELAX: R_RISCV_SUB6 +; RELAX-NOT: 0x0 R_RISCV_ADD32 +; RELAX-NOT: 0x0 R_RISCV_SUB32 +; RELAX: 0x20 R_RISCV_ADD32 +; RELAX: 0x20 R_RISCV_SUB32 +; RELAX: 0x25 R_RISCV_SET6 +; RELAX: 0x25 R_RISCV_SUB6 source_filename = "frame.c" ; Function Attrs: noinline nounwind optnone