thepowersgang/mrustc

SIGSEGV compiling 1.54.0 librustc_mir on OSX

catap opened this issue · 12 comments

catap commented

I've used a local root ca1096a which crashes as:

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000050
Exception Codes:       0x0000000000000001, 0x0000000000000050

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [4891]

VM Region Info: 0x50 is not in any region.  Bytes before following region: 140737487339440
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      shared memory            7ffffff08000-7ffffff09000 [    4K] r-x/r-x SM=SHM  

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   mrustc                        	       0x10f044004 (anonymous namespace)::Visitor::visit_path_params(HIR::PathParams&) + 30
1   mrustc                        	       0x10effb47c HIR::Visitor::visit_trait_path(HIR::TraitPath&) + 62
2   mrustc                        	       0x10f043ed2 (anonymous namespace)::Visitor::visit_trait_path(HIR::TraitPath&) + 1378
3   mrustc                        	       0x10effacd4 HIR::Visitor::visit_params(HIR::GenericParams&) + 220
4   mrustc                        	       0x10effa56d HIR::Visitor::visit_struct(HIR::ItemPath, HIR::Struct&) + 25
5   mrustc                        	       0x10f03feed (anonymous namespace)::Visitor::visit_struct(HIR::ItemPath, HIR::Struct&) + 99
6   mrustc                        	       0x10eff89ff HIR::Visitor::visit_module(HIR::ItemPath, HIR::Module&) + 2125
7   mrustc                        	       0x10eff88e3 HIR::Visitor::visit_module(HIR::ItemPath, HIR::Module&) + 1841
8   mrustc                        	       0x10eff88e3 HIR::Visitor::visit_module(HIR::ItemPath, HIR::Module&) + 1841
9   mrustc                        	       0x10eff88e3 HIR::Visitor::visit_module(HIR::ItemPath, HIR::Module&) + 1841
10  mrustc                        	       0x10eff7ce4 HIR::Visitor::visit_crate(HIR::Crate&) + 158
11  mrustc                        	       0x10f03f93d ConvertHIR_LifetimeElision(HIR::Crate&) + 77
12  mrustc                        	       0x10ee0d3bb void CompilePhaseV<main::$_13>(char const*, main::$_13) + 36
13  mrustc                        	       0x10ee0bbae main + 6528
14  dyld                          	    0x7ff80192341f start + 1903

(for my reference) See #316 (comment)
Crash was in 1.54 rustc_mir

@catap I don't have access to a mac to reproduce that error.
It looks like it's a null reference being passed through to one of the visitors (Address is 0x50), but I can't see quite where that could be coming from, there's no values that could be non-null near enough in that call tree.

Could you run with debugging enabled for that phase (MRUSTC_DEBUG=Lifetime Elision) and maybe with something like valgrind to try and narrow down where the bad reference is coming from?

catap commented

@thepowersgang I've scrolled up terminal history and discover that line near the crash:

rustc-1.54.0-src/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs:1864:50-58 warn:0:Unexpected attribute inline on expression

which seems quite related to the issue.

If it doesn't help I'll retry with MRUSTC_DEBUG but in a couple of hours.

Nah, that's completely unrelated - it's from the expand stage, and the crash is after HIR generation.

I spent maybe too long trying to reproduce the error by cross-building for OSX, and got a successful build of that crate.
It's likely some undefined behavior somewhere in that call chain being triggered by the compiler you're using.

catap commented

@thepowersgang I'm using stock compiler from macOS 13 here. Nothing unusual. I just run the build on the machine and as soon as it fails will share with you an update

catap commented

@thepowersgang I still have all build artifacts on that machine and was able to
make it quite fast. Here the output which you've required.

librustc_mir.rlib_dbg.txt.gz

catap commented

I've used:

Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: x86_64-apple-darwin22.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

to build everything

Iterator invalidation :(
Inherited bounds resized the parameter list currently being enumerated.

catap commented

:(

The above commit (417f293) has a potential fix.

catap commented
:info:build [RUSTC] -o output-1.54.0/prefix/bin/hello_world
:info:build ./output-1.54.0/prefix/bin/hello_world
:info:build hello, world

it works!