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

rustc doesn't seem to acknowledge llvm-args's dwarf-version flag #101892

Closed
yehuthi opened this issue Sep 16, 2022 · 3 comments
Closed

rustc doesn't seem to acknowledge llvm-args's dwarf-version flag #101892

yehuthi opened this issue Sep 16, 2022 · 3 comments
Labels
C-bug Category: This is a bug.

Comments

@yehuthi
Copy link

yehuthi commented Sep 16, 2022

I'm trying to get DWARF version 3 in my binary with rustc main.rs -o ./out -g -Cllvm-args="--dwarf-version=3" but it doesn't seem to work:

$ readelf --debug-dump=info ./out | grep -A 2 'Compilation Unit @' | grep Version
   Version:       5
   Version:       5
   Version:       5
   Version:       5
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       5

For context: the reason I want to do this is because I want to use the Coz profiler with Rust and it seemingly doesn't like DWARF version 5 which Rust generates (its dying words are: unknown compilation unit version 5), so I want to compile with version 3 because that's what the Coz README specifies. See also Coz issues #193, #107.

A few notes:

  • I also tried adding -C link-arg=-gdwarf-3 as mentioned in the first comment to the first issue above which didn't help.
  • I got the idea to try the dwarf-version flag from rustc -Cllvm-args="--help".
  • I'm not sure if this is a case of user error since I'm oblivious to the inner working of rustc and I apologize in advance. I'm also not sure if what I'm trying to do is deliberately impossible and if so I might consider this an issue in the rustc help message informing of the option, rather than the code-generation.
  • Minimal example here.

I'm on x86_64 Arch Linux and rustc 1.65.0-nightly (1d37ed6 2022-09-09).

@yehuthi yehuthi added the C-bug Category: This is a bug. label Sep 16, 2022
@Urgau
Copy link
Member

Urgau commented Sep 16, 2022

I believe setting the dwarf version with -Cllvm-args is not supported because rustc always sets the version in the LLVM-IR.

However there is a nightly flag -Zdwarf-version to set the dwarf version.
You should be able to set version 3 like this: -Zdwarf-version=3.

@yehuthi
Copy link
Author

yehuthi commented Sep 16, 2022

Thanks @Urgau, -Zdwarf-version=3 does seem to help it, 6 units have version 3, but most units still have versions 4 and 5:

   Version:       5
   Version:       5
   Version:       5
   Version:       5
   Version:       3
   Version:       3
   Version:       3
   Version:       3
   Version:       3
   Version:       3
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       4
   Version:       5

Is this an incorrect behavior for the flag or is it permissive towards the code-gen in this way?

@Urgau
Copy link
Member

Urgau commented Sep 16, 2022

Thanks @Urgau, -Zdwarf-version=3 does seem to help it, 6 units have version 3, but most units still have versions 4 and 5:

This is probably because the units who don't have version 3 comes from the pre-compiled standard libraries units. Those are not affected by your -Zdwarf-version=3 and are compiled with the default settings.

Is this an incorrect behavior for the flag or is it permissive towards the code-gen in this way?

I don't think it's a incorrect behavior because it's doing what you told him to do. Which is to compile your crate and it's dependencies (if they are not already compiled, like for core, alloc, std, ...) with the flags your provided. So if one if these dependency has another dwarf version it will simply be merged with the other one.


If you compile the standard libraries yourself with cargo build-std feature, you should have all the units with the correct dwarf version:

RUSTFLAGS="-Zdwarf-version=3" cargo +nightly -Zbuild-std build

NOTE: I have not tested this, I may be wrong.

@yehuthi yehuthi closed this as completed Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants