Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp cg_llvm debuginfo handling to use the LLVM-C API #134001

Open
workingjubilee opened this issue Dec 7, 2024 · 1 comment
Open

Revamp cg_llvm debuginfo handling to use the LLVM-C API #134001

workingjubilee opened this issue Dec 7, 2024 · 1 comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@workingjubilee
Copy link
Member

We currently use C++ code for some of our debuginfo stuff with LLVM. We should port it to the C API, so we don't have to continue maintaining irksome C++ bindings. This is the primary header in question: https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm-c/DebugInfo.h

@workingjubilee workingjubilee added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 7, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 7, 2024
@workingjubilee workingjubilee changed the title Revamp LLVM debuginfo handling to use the LLVM-C API Revamp `cg_llv debuginfo handling to use the LLVM-C API Dec 7, 2024
@workingjubilee workingjubilee changed the title Revamp `cg_llv debuginfo handling to use the LLVM-C API Revamp cg_llvm debuginfo handling to use the LLVM-C API Dec 7, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 7, 2024
@Zalathar
Copy link
Contributor

Zalathar commented Dec 7, 2024

Incomplete list of places where the LLVM-C API appears to be inadequate:

  • LLVMDIBuilderCreateCompileUnit
    • We pass a DICompileUnit::DebugNameTableKind to the C++ constructor, but the C API unconditionally passes DICompileUnit::DebugNameTableKind::Default.
    • There doesn't appear to be a way to change this afterwards.
    • This has something to do with not emitting .debug_pubnames and .debug_pubtypes on DWARFv4 or lower.
  • LLVMDIBuilderCreateFile
    • Doesn't allow passing an optional checksum or optional source text.
  • LLVMDIBuilderCreateFunction
    • Only supports a subset of DISubprogram::DISPFlags.
  • LLVMDIBuilderCreateEnumerator
    • Does not allow specifying bit-width of the value; default width appears to be 64, which cannot hold 128-bit values.
    • Unclear whether this is important or not.
  • LLVMDIBuilderCreateEnumerationType
    • Does not allow specifying IsScoped; default value is false but we always pass true.

LLVM-C functions that require LLVM 19, so we can't use them yet:

  • LLVMDIBuilderInsertDeclareRecordAtEnd

Wrapper functions that call a C++ method with no equivalent in the C API:

  • LLVMRustDIBuilderCreateMethod
  • LLVMRustDIBuilderCreateVariantMemberType
  • LLVMRustDIBuilderCreateVariantPart
  • LLVMRustDIBuilderCreateTemplateTypeParameter
  • LLVMRustDICompositeTypeReplaceArrays
  • LLVMRustDILocationCloneWithBaseDiscriminator

Wrapper functions that do non-trivial things and don't map cleanly to a single C or C++ API function:

  • LLVMRustDIBuilderCreateStaticVariable
  • LLVMRustDIBuilderCreateVariable

Wrapper functions for getting various DWARF constants:

  • LLVMRustDIBuilderCreateOpDeref
  • LLVMRustDIBuilderCreateOpPlusUconst
  • LLVMRustDIBuilderCreateOpLLVMFragment

bors added a commit to rust-lang-ci/rust that referenced this issue Dec 12, 2024
cg_llvm: Replace most of our DIBuilder wrappers with LLVM-C API bindings

Many of our `LLVMRust` wrapper functions for building debug info can be replaced with their equivalents in the LLVM-C API.

This mostly implements rust-lang#134001, though it punts on some of the trickier cases noted at rust-lang#134001 (comment).

---

Marking as draft for now, because I want to give myself more time to review my own changes.

r? workingjubilee
jhpratt added a commit to jhpratt/rust that referenced this issue Feb 4, 2025
…gjubilee

cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 1)

Part of rust-lang#134001, follow-up to rust-lang#136326, extracted from rust-lang#134009.

This PR performs an arbitrary subset of the LLVM-C binding migrations from rust-lang#134009, which should make it less tedious to review. The remaining migrations can occur in one or more subsequent PRs.
fmease added a commit to fmease/rust that referenced this issue Feb 5, 2025
…gjubilee

cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 1)

Part of rust-lang#134001, follow-up to rust-lang#136326, extracted from rust-lang#134009.

This PR performs an arbitrary subset of the LLVM-C binding migrations from rust-lang#134009, which should make it less tedious to review. The remaining migrations can occur in one or more subsequent PRs.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 5, 2025
Rollup merge of rust-lang#136375 - Zalathar:llvm-di-builder, r=workingjubilee

cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 1)

Part of rust-lang#134001, follow-up to rust-lang#136326, extracted from rust-lang#134009.

This PR performs an arbitrary subset of the LLVM-C binding migrations from rust-lang#134009, which should make it less tedious to review. The remaining migrations can occur in one or more subsequent PRs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants