From 5cf3cc624609b420319acef498becf48cc011c9a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 3 Jul 2019 12:48:04 +0000 Subject: [PATCH] [ELF][RISCV] Allow R_RISCV_ADD in relocateNonAlloc() gcc may generate .debug_info/.debug_aranges/.debug_line/etc that are relocated by R_RISCV_ADD*/R_RISCV_SUB* pairs. Allow R_RISCV_ADD in non-SHF_ALLOC section to fix link errors like: ld.lld: error: print.c:(.debug_frame+0x60): has non-ABS relocation R_RISCV_ADD64 against symbol '.L0 ' Differential Revision: https://reviews.llvm.org/D63259 llvm-svn: 365035 --- lld/ELF/InputSection.cpp | 2 +- lld/test/ELF/riscv-reloc-add.s | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 7fc7b01..08fbbe8 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -838,7 +838,7 @@ void InputSection::relocateNonAlloc(uint8_t *Buf, ArrayRef Rels) { if (Expr == R_NONE) continue; - if (Expr != R_ABS && Expr != R_DTPREL) { + if (Expr != R_ABS && Expr != R_DTPREL && Expr != R_RISCV_ADD) { std::string Msg = getLocation(Offset) + ": has non-ABS relocation " + toString(Type) + " against symbol '" + toString(Sym) + "'"; diff --git a/lld/test/ELF/riscv-reloc-add.s b/lld/test/ELF/riscv-reloc-add.s index 64772c8..85fd20e 100644 --- a/lld/test/ELF/riscv-reloc-add.s +++ b/lld/test/ELF/riscv-reloc-add.s @@ -24,3 +24,9 @@ _start: .word .L1 - .L0 .half .L1 - .L0 .byte .L1 - .L0 + +## Debug section may use R_RISCV_ADD64/R_RISCV_SUB64 pairs to measure lengths +## of code ranges (e.g. DW_AT_high_pc). Check we allow R_RISCV_ADD*/R_RISCV_SUB* +## in such non-SHF_ALLOC sections in -pie/-shared mode. +.section .debug_info +.quad .L1 - .L0 -- 2.7.4