-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
rust-analyzer fails to expand proc-macro when mold linker is used #80
Comments
I created a new Rust project on my machine, copy-n-paste your code and build it with mold. I also built rust-analyzer with mold. But I couldn't reproduce the issue -- |
I saw (and still see) this problem only when running rust-analyzer on a
project that uses mold. The same code links and runs fine. I guess I'll try
to upgrade all the things first and if it's still not working - to make a
better reproduction, maybe a docker imagine or something like that.
…On Wed, Jul 7, 2021, 21:55 Rui Ueyama ***@***.***> wrote:
I created a new Rust project on my machine, copy-n-paste your code and
build it with mold. I also built rust-analyzer with mold. But I couldn't
reproduce the issue -- rust-analyzer analysis-stats . works with and
without mold. Is there more hidden conditions to reproduce the issue? Did
you observe the same issue when building programs that are publicly
available? (If so, I can try that too)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#80 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAQFI4HMEDBS2ZI4GXKAY3TWRMGHANCNFSM473SW6OQ>
.
|
Yeah, it's great if you can reproduce the issue in a Docker. |
Steps to reproduce the problem: # cat Cargo.toml
[package]
name = "dummy"
version = "0.0.0"
edition = "2018"
[dependencies]
object = { version = "0.25.3", default-features = false, features = ["read_core", "elf"] }
memmap2 = "0.3.0"
# cat src/main.rs
use std::env;
use std::fs::File;
use memmap2::MmapOptions;
use object::read::{File as BinaryFile};
fn main() {
let args: Vec<String> = env::args().collect();
let file = File::open(&args[1]).expect(":'(\t");
let mmap = unsafe { MmapOptions::new().map(&file).expect(":'(\t") };
BinaryFile::parse(&*mmap).expect(":(\t");
}
# ~/.cargo/bin/cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
# echo 'void foo() {};' | clang -xc - -fuse-ld=/root/mold/mold -shared -o libfoo.so
# ./target/debug/dummy /lib/x86_64-linux-gnu/libc.so.6
# echo $?
0
# ./target/debug/dummy $(readlink -f libfoo.so)
thread 'main' panicked at ':( : Error("Invalid ELF section header offset/size/alignment")', src/main.rs:11:31
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
# echo $?
101 |
Update: If I add the "unaligned" feature to the object dependency, then it works. This is not present at https://github.com/rust-analyzer/rust-analyzer/search?l=TOML&q=object . I don't know why it works though. |
Let me know if an example above is working for you. If not - I'll try to make something in docker. |
@nehaljwani Thank you very much for the detailed instructions on how to reproduce the issue! With that, I could easily reproduce it and found the cause of the issue. The bug was a little bit surprising -- we haven't aligned the section header to a 4 or 8 byte boundaries until now. x86 isn't sensitive to data alignments, so it happened to work. The problem has been fixed. |
I'm using stable rustc, most recent rust-analyzer and static build of mold as of a week ago or so.
config.toml:
When deriving via proc macro is used (here serde, but any other proc macro fails
rust analyzer fails to expand the macro with an error like this:
(this error is most likely about some different proc macro)
You can invoke rust analyzer like this
The same code works as expected when compiled in a usual way
The text was updated successfully, but these errors were encountered: