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 segmentation fault with circular module #97589

Closed
xhalo32 opened this issue May 31, 2022 · 2 comments · Fixed by #130246
Closed

rustc segmentation fault with circular module #97589

xhalo32 opened this issue May 31, 2022 · 2 comments · Fixed by #130246
Labels
C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xhalo32
Copy link

xhalo32 commented May 31, 2022

The rust compiler segfaults when using the path attribute #[path = "this_file.rs"] pointing to itself with an inner line documentation comment in the file.

Steps to reproduce

Install this version of rust on linux:

rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-unknown-linux-gnu
release: 1.60.0
LLVM version: 14.0.0

Create the following file structure:

lib.rs:

pub mod recursive;

recursive.rs:

//! this comment causes the circular dependency checker to break

#[path = "recursive.rs"]
mod recursive;

And compiling lib.rs will cause the segfault:

rustc lib.rs
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x4b3d23)[0x7fbfcf6b3d23]
/usr/lib/libc.so.6(+0x3e8e0)[0x7fbfcec318e0]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x1fa8e30)[0x7fbfd11a8e30]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x1f95ba6)[0x7fbfd1195ba6]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(_RNvMs0_NtNtCsjVjzjquPLq5_11rustc_parse6parser4exprNtB7_6Parser21parse_assoc_expr_with+0x11b)[0x7fbfd11938fb]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x2005145)[0x7fbfd1205145]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x1f8ff53)[0x7fbfd118ff53]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(_RNvMNtNtCsjVjzjquPLq5_11rustc_parse6parser4attrNtB4_6Parser15parse_attribute+0x645)[0x7fbfd118eab5]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x1f8e021)[0x7fbfd118e021]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(_RNvMNtNtCsjVjzjquPLq5_11rustc_parse6parser4itemNtB4_6Parser9parse_mod+0x84)[0x7fbfd11baa44]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(_RNvNtCseWJ2MiKGUQh_12rustc_expand6module18parse_external_mod+0x46e)[0x7fbfd1c0060e]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x1f20ee2)[0x7fbfd1120ee2]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(_RNvXsk_NtCseWJ2MiKGUQh_12rustc_expand6expandNtB5_19InvocationCollectorNtNtCsnWACUGdVye_9rustc_ast9mut_visit10MutVisitor13flat_map_item+0x167)[0x7fbfd115a547]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x29ebad1)[0x7fbfd1bebad1]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x1f50ea8)[0x7fbfd1150ea8]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x1f212ce)[0x7fbfd11212ce]
...
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(_RNvXsk_NtCseWJ2MiKGUQh_12rustc_expand6expandNtB5_19InvocationCollectorNtNtCsnWACUGdVye_9rustc_ast9mut_visit10MutVisitor13flat_map_item+0x167)[0x7fbfd115a547]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x29ebad1)[0x7fbfd1bebad1]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x1f50ea8)[0x7fbfd1150ea8]
/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-75e5f32fc3580f6c.so(+0x1f212ce)[0x7fbfd11212ce]
fish: Job 1, 'rustc lib.rs' terminated by signal SIGSEGV (Address boundary error)

Notes

  • Segfault does not occur without the inner line documentation comment
  • Segfault does not occur with an outer line documentation comment on pub mod recursive in lib.rs
  • Segfault does not occur with lib.rs containing a circular module declaration to itself, rather requires another file
@Noratrieb
Copy link
Member

Noratrieb commented May 31, 2022

I could reproduce this on a recent nightly

rustc 1.63.0-nightly (ebbcbfc23 2022-05-27)
binary: rustc
commit-hash: ebbcbfc236ced21d5e6a92269edb704692ff26b8
commit-date: 2022-05-27
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.4

@cuviper cuviper added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 31, 2022
@Enselic
Copy link
Member

Enselic commented Mar 16, 2024

Triage: Seems worthwhile to get help with fixing. Labeling E-help-wanted.

@Enselic Enselic added the E-help-wanted Call for participation: Help is requested to fix this issue. label Mar 16, 2024
dianne added a commit to dianne/rust that referenced this issue Sep 11, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 21, 2024
…nkov

rustc_expand: remember module `#[path]`s during expansion

During invocation collection, if a module item parsed from a `#[path]` attribute needed a second pass after parsing, its path wouldn't get added to the file path stack, so cycle detection broke. This checks the `#[path]` in such cases, so that it gets added appropriately. I think it should work identically to the case for external modules that don't need a second pass, but I'm not 100% sure.

Fixes rust-lang#97589
@bors bors closed this as completed in 6ce3767 Sep 22, 2024
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. E-help-wanted Call for participation: Help is requested to fix this issue. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants