commit | b9b39db5d7677710f1d00dc8ff5844ad2abb269f | [log] [tgz] |
---|---|---|
author | Fangrui Song <i@maskray.me> | Sat Mar 29 11:12:40 2025 -0700 |
committer | GitHub <noreply@github.com> | Sat Mar 29 11:12:40 2025 -0700 |
tree | ffee4dc30b27f117a0648adcb63f229f28b2ee9a | |
parent | fe6fb910df9d1b9a9e2e7a6e8228d020668e0129 [diff] |
RISCVAsmParser: Don't treat operands with relocation specifier as parse-time constants An immediate operand is encoded as an `MCExpr`, with `RISCVMCExpr` specifying an operand that includes a relocation specifier. When https://reviews.llvm.org/D23568 added initial fixup and relocation support in 2017, it adapted code from `PPCMCExpr` (for `@l` `@ha`) to evaluate the `RISCVMCExpr` operand. (PPCAsmParser had considerable technical debt, though I’ve recently streamlined it somewhat, e.g. 8560da28c69de481f3ad147722577e87b902facb) Evaluating RISCVMCExpr during parsing is unnecessary. For example, there's no need to treat `lui a0, %hi(2)` differently from `lui a0, %hi(foo)` when foo has not been defined yet. This evaluation introduces unnecessary complexity. For instance, parser functions require an extra check like `VK == RISCVMCExpr::VK_None`, as seen in these examples: ``` if (!evaluateConstantImm(getImm(), Imm, VK) || VK != RISCVMCExpr::VK_None) return IsConstantImm && isUInt<N>(Imm) && VK == RISCVMCExpr::VK_None; ``` This PR eliminates the parse-time evaluation of `RISCVMCExpr`, aligning it more closely with other targets. --- `abs = 0x12345; lui t3, %hi(abs)` now generates R_RISCV_HI20/R_RISCV_RELAX with linker relaxation. (Tested by test/MC/RISCV/linker-relaxation.s) (Notably, since commit ba2de8f22d0cac86d89c1806fb54ed3463349342 in lld/ELF, the linker can handle R_RISCV_HI relocations with a symbol index of 0 in -pie mode.) Pull Request: https://github.com/llvm/llvm-project/pull/133377
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.