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

Clang reapeatedly calls emitDwarfDIE and giving SIGSEGV: invalid memory reference error #76920

Open
sundeep-kokkonda opened this issue Jan 4, 2024 · 5 comments
Labels
clang Clang issues not falling into any other category

Comments

@sundeep-kokkonda
Copy link

While building rust sources (in Yocto distro for custom target - i686-poky-linux-gnu), when the 'p384' crate compiling we are getting 'signal: 11, SIGSEGV: invalid memory reference' error. This issue is occurring when build is for 32-bit architecture machines with DEBUG enabled.

Initially it was seen with LLVM version: 16.0.5 and we could reproduce the issue with LLVM version: 17.0.4.

Below is the error text with LLVM version: 17.0.4:

error: rustc interrupted by SIGSEGV, printing backtrace
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x9ea726)[0x7ff413b9f726]
/home/skokkonda/00_Work/12360/poky/build/tmp/sysroots-uninative/x86_64-linux/lib/libc.so.6(+0x391f0)[0x7ff412de91f0]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x2e15dbe)[0x7ff415fcadbe]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x2e15f01)[0x7ff415fcaf01]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x2e15fb6)[0x7ff415fcafb6]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x2e7d7d9)[0x7ff4160327d9]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x2cdccf9)[0x7ff415e91cf9]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x2c64abe)[0x7ff415e19abe]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x2cda7c4)[0x7ff415e8f7c4]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1afe8b3)[0x7ff414cb38b3]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b2300b)[0x7ff414cd800b]
### cycle encountered after 11 frames with period 12
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
### recursed 20 times
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]
/home/skokkonda/00_Work/12360/mini/recipe-sysroot-native/usr/bin/../lib/librustc_driver-af0ab23c1eb07079.so(+0x1b23bc8)[0x7ff414cd8bc8]

rust version info:

rustc 1.74.1 (a28077b28 2023-12-04) (built from a source tarball)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: x86_64-unknown-linux-gnu
release: 1.74.1
LLVM version: 17.0.4

This we've discussed in rust community - rust-lang/rust#113612 (comment) and, we suspect that the issue is from llvm function - llvm::AsmPrinter::emitDwarfDIE(llvm::DIE const&) const
The gbd back trace is here - rust-lang/rust#113612 (comment)

The attached 'p384.zip' contains the llvm-ir file.
p384.zip

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jan 4, 2024
@DimitryAndric
Copy link
Collaborator

I can compile that .ll file just fine with clang 17.0.6, but it takes quite a lot of memory (~1.1GiB):

$ time -l clang -O2 -c p384-d8c37f70a895ae9a.p384.395dc485c0d4f4c4-cgu.0.rcgu.ll
warning: overriding the module target triple with x86_64-unknown-freebsd15.0 [-Woverride-module]
1 warning generated.
       88.40 real        79.68 user         8.71 sys
   1200620  maximum resident set size
     75543  average shared memory size
       799  average unshared data size
       488  average unshared stack size
    287413  page reclaims
         0  page faults
         0  swaps
         0  block input operations
        10  block output operations
         0  messages sent
         0  messages received
         0  signals received
         4  voluntary context switches
      1088  involuntary context switches

Are you sure you aren't simply running out of RAM for that segfault?

@sundeep-kokkonda
Copy link
Author

We are also able to compile the .ll file successfully with clang.

But the actual error is occuring with below build command when compiled with 'rustc' (It runs out of stack when calling this llvm::AsmPrinter::emitDwarfDIE(llvm::DIE const&) const function repeatedly)

rustc --crate-name p384 --edition=2021 ./p384/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=llvm-ir,asm  -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="arithmetic"' --cfg 'feature="default"' --cfg 'feature="digest"' --cfg 'feature="ecdh"' --cfg 'feature="ecdsa"' --cfg 'feature="ecdsa-core"' --cfg 'feature="pem"' --cfg 'feature="pkcs8"' --cfg 'feature="sha2"' --cfg 'feature="sha384"' --cfg 'feature="std"' -C metadata=d8c37f70a895ae9a -C extra-filename=-d8c37f70a895ae9a --out-dir ./out-dir/ --target i686-poky-linux-gnu -C linker=./target-rust-ccld -L dependency=./target/i686-poky-linux-gnu/debug/deps -L dependency=./target/debug/deps --extern ecdsa_core=./libecdsa-56052b755f8dfd63.rmeta --extern primeorder=./libprimeorder-37f2cfa27107f3c6.rmeta --extern elliptic_curve=./libelliptic_curve-1d96c4c68159c10a.rmeta --extern sha2=./libsha2-c133927e5aa6c865.rmeta --cap-lints allow -L ./recipe-sysroot/usr/lib/rustlib/i686-poky-linux-gnu/lib

And, we're not sure how 'rustc' uses llvm/clang in background to compile the crates. (As I mentioned this was already discussed in rust community and narrowed down to llvm issue rust-lang/rust#113612 (comment))

This issue is not occuring with x86_64 arch, only observed with 32-bit arch witn DEBUG enabled.

@DimitryAndric
Copy link
Collaborator

Well, if the host you are running on is 32-bit and rustc is a 32-bit executable, then it is not strange that it is running out of stack. I suppose there is no way you can do a cross-compilation on a 64-bit host, which should have more stack available?

@sundeep-kokkonda
Copy link
Author

May be your understanding is incorrect. The host I am running is a 64-bit and rustc is 64 bit executable.

> file ./recipe-sysroot-native/usr/bin/rustc
./recipe-sysroot-native/usr/bin/rustc: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /home/skokkonda/00_Work/12360/poky/build/tmp/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2, BuildID[sha1]=6a6d4dd3aff8c9920ba7614bbd736a953a0e5aeb, for GNU/Linux 3.2.0, not stripped

Let me clarify this as well - ,
This issue is not occurring with x86_64 arch, only observed with 32-bit arch with DEBUG enabled (Here I mean, the issue is not occurring when the target arch is x86_64-poky-linux-gnu. Only issue is occurring when compiling for 32-bit target arch i686-poky-linux-gnu. In brief, we are building Cargo for a custom target using Yocto, there we observed this issue.)

@coder0xff
Copy link

rust-lang/rust#122357 has a minimal reproduction in Rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

No branches or pull requests

3 participants