The 32-bit type relocation (R_MIPS_32) cannot be used for instructions below:
ori $4, $4, start
ori $4, $4, (start - .)
We should print an error instead.
Differential D81908
[Mips] Error if a non-immediate operand is used while an immediate is expected hev on Jun 15 2020, 10:05 PM. Authored by
Details The 32-bit type relocation (R_MIPS_32) cannot be used for instructions below: ori $4, $4, start We should print an error instead.
Diff Detail
Event TimelineComment Actions Can you please add a test under llvm/test/MC/Mips/? You can reuse the following template ## File-level comment about the purpose of the test # RUN: llvm-mc -triple=... %s | FileCheck %s # CHECK: ... See llvm/test/MC/X86/reloc-directive-elf-32.s for an example. Use ninja check-llvm-mc-mips to test llvm/test/MC/Mips. Comment Actions Does this patch depend on D81919?
Comment Actions Thanks for review.
Comment Actions But both patches change content of the same if (Kind == MCExpr::SymbolRef) statement. Comment Actions Rigid: % llvm-mc -triple=ppc64 <<< 'or 3, 3, start; start:' ... <stdin>:1:10: error: invalid operand for instruction # The diagnostic is from `PPCGenAsmMatcher.inc:MatchAndEmitInstruction`, which is not great. llvm-mc improperly rejects or 3, 3, start-. % powerpc64le-linux-gnu-as <<< 'or 3, 3, start; start:' {standard input}: Assembler messages: {standard input}:1: Error: unsupported relocation against .text Permissive: % aarch64-linux-gnu-as <<< 'orr w3, w3, start; start:' % mipsel-linux-gnu-as <<< 'ori $3, $3, start; start:' # succeeded % llvm-objdump -dr ... 0: 04 00 63 34 ori $3, $3, 4 <start> 00000000: R_MIPS_LO16 .text % mips64el-linux-gnuabi64-as <<< 'ori $3, $3, start; start:' # succeeded % llvm-objdump -dr ... 0: 00 00 63 34 ori $3, $3, 0 <.text> 0000000000000000: R_MIPS_LO16/R_MIPS_NONE/R_MIPS_NONE .text+0x4 powerpc's behavior is definitely correct. AArch64 and MIPS's permissive behaviors are not good. A symbolic value (which can be 32-bit/64-bit) requires more bits than the immediate bits. I think flagging the instruction in the case of a symbolic value is fine. FWIW: I filed a feature request for GNU as: https://sourceware.org/bugzilla/show_bug.cgi?id=26126
Comment Actions
To MIPS64, ORI and DADDIU only have the 16-bit signed immediate, but GNU toolchain treat it as %lo(MCBinaryExpr), so LLVM toolchain is just able to reject it as @hev implementation, or workaround ExprKind::Binary to ExprKind::Target for BAD relocation directive N64 testcase D81919 Comment Actions Thanks for review.
Comment Actions This version looks good to me. The diagnostic should probably be similar to error: expected 16-bit signed immediate |