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

Upgrade Rust base (aa35e73b) #137

Closed
wants to merge 4,644 commits into from
Closed

Upgrade Rust base (aa35e73b) #137

wants to merge 4,644 commits into from

Conversation

shepmaster
Copy link
Member

No description provided.

flip1995 and others added 30 commits April 3, 2019 18:22
- libarena
- librustc_allocator
- librustc_borrowck
- librustc_codegen_ssa
- librustc_codegen_utils
- librustc_driver
- librustc_errors
- librustc_incremental
- librustc_metadata
- librustc_passes
- librustc_privacy
- librustc_resolve
- librustc_save_analysis
- librustc_target
- librustc_traits
- libsyntax
- libsyntax_ext
- libsyntax_pos
- libfmt_macros
- librustdoc
This avoids the dependency on host libraries such as libgcc_s which
may be undesirable in some deployment environments where these aren't
available.
When using the `rustfix-coverage` flag, some tests currently fail
because they define a different error-format than `json`.

The current implementation crashes when encountering those tests. Since
we don't care about non-json test output when collecting the coverage
data, we handle those tests by returning an empty `Vec` instead.
Functions with uninhabited return values are already marked `noreturn`,
but we were still generating return instructions for this. When running
with `-C passes=lint`, LLVM prints:

    Unusual: Return statement in function with noreturn attribute

The LLVM manual makes a stronger statement about `noreturn` though:

> This produces undefined behavior at runtime if the function ever does
dynamically return.

We now emit an `abort` anywhere that would have tried to return an
uninhabited value.
Revert rust-lld place changes

Fixes rust-lang#59661.

Instead of rust-lang#59668 it reverts only failed part.
@shepmaster
Copy link
Member Author

shepmaster commented Apr 15, 2019

Problem

LLVM ERROR: Cannot select: t2: i16 = addrspacecast[1 -> 0] undef:i16
  t1: i16 = undef
In function: _ZN4core3ptr87_$LT$impl$u20$core..fmt..Debug$u20$for$u20$unsafe$u20$fn$LP$A$RP$$u20$.$GT$$u20$Ret$GT$3fmt17h0fdf8ca7140def9bE
; ModuleID = 'bugpoint-reduced-simplified.bc'
source_filename = "core.37hoedwx-cgu.0"
target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
target triple = "avr-unknown-unknown"

define void @"_ZN4core3ptr87_$LT$impl$u20$core..fmt..Debug$u20$for$u20$unsafe$u20$fn$LP$A$RP$$u20$.$GT$$u20$Ret$GT$3fmt17h0fdf8ca7140def9bE"() unnamed_addr addrspace(1) #0 {
start:
  %0 = addrspacecast {} addrspace(1)* undef to {}*
  store {}* %0, {}** undef, align 1
  ret void
}

attributes #0 = { "target-cpu"="atmega328p" }

!llvm.module.flags = !{!0}

!0 = !{i32 2, !"Debug Info Version", i32 3}

@shepmaster
Copy link
Member Author

shepmaster commented Apr 15, 2019

Problem

LLVM ERROR: ran out of registers during register allocation

Repro:

; ModuleID = 'bugpoint-reduced-simplified.bc'
source_filename = "core.37hoedwx-cgu.0"
target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
target triple = "avr-unknown-unknown"

%num__flt2dec__Part = type { [0 x i8], i8, [4 x i8] }
%num__flt2dec__decoder__FullDecoded = type { [26 x i8], i8, [0 x i8] }
%num__flt2dec__Formatted = type { [0 x i8], { [0 x i8]*, i16 }, [0 x i8], { [0 x %num__flt2dec__Part]*, i16 }, [0 x i8] }
%num__flt2dec__Part__Copy = type { [1 x i8], { [0 x i8]*, i16 }, [0 x i8] }

@anon.4c2386cf7531a237a70031c52b819347.56 = external dso_local unnamed_addr constant <{ [1 x i8] }>, align 1
@anon.4c2386cf7531a237a70031c52b819347.57 = external dso_local unnamed_addr constant <{ [3 x i8] }>, align 1
@anon.4c2386cf7531a237a70031c52b819347.63 = external dso_local unnamed_addr constant <{ [3 x i8] }>, align 1
@anon.4c2386cf7531a237a70031c52b819347.64 = external dso_local unnamed_addr constant <{ [3 x i8] }>, align 1

declare dso_local fastcc { [0 x %num__flt2dec__Part]*, i16 } @core__slice__Index([0 x %num__flt2dec__Part]*, i16, i16) unnamed_addr addrspace(1) #0

declare i32 @rust_eh_personality(...) unnamed_addr addrspace(1) #0

declare void @_ZN4core3num7flt2dec7decoder6decode17h56dc0fcd87a4559cE({ [0 x i8], i8, [0 x i8], %num__flt2dec__decoder__FullDecoded, [0 x i8] }*, double) unnamed_addr addrspace(1) #0

declare { [0 x i8]*, i16 } @_ZN4core3num7flt2dec14determine_sign17h04b9993823707283E(i8, %num__flt2dec__decoder__FullDecoded*, i1) unnamed_addr addrspace(1) #0

define void @_ZN4core3num7flt2dec19to_shortest_exp_str17h47df2ff6a62ba60cE(%num__flt2dec__Formatted*, double, i8, i16, i16, i1, [0 x i8]*, i16, [0 x %num__flt2dec__Part]*, i16) unnamed_addr addrspace(1) #0 personality i32 (...) addrspace(1)* @rust_eh_personality {
start:
  %10 = icmp ult i16 %9, 6
  br i1 %10, label %bb4, label %bb5

bb4:                                              ; preds = %start
  unreachable

bb5:                                              ; preds = %start
  call addrspace(1) void @_ZN4core3num7flt2dec7decoder6decode17h56dc0fcd87a4559cE({ [0 x i8], i8, [0 x i8], %num__flt2dec__decoder__FullDecoded, [0 x i8] }* noalias nocapture nonnull sret dereferenceable(28) null, double %1)
  %11 = call addrspace(1) { [0 x i8]*, i16 } @_ZN4core3num7flt2dec14determine_sign17h04b9993823707283E(i8 %2, %num__flt2dec__decoder__FullDecoded* noalias nonnull readonly align 1 dereferenceable(27) undef, i1 zeroext undef)
  switch i2 undef, label %bb13 [
    i2 0, label %bb15
    i2 1, label %bb18
    i2 -2, label %bb30
    i2 -1, label %bb32
  ]

bb13:                                             ; preds = %bb5
  unreachable

bb15:                                             ; preds = %bb5
  %12 = tail call fastcc addrspace(1) { [0 x %num__flt2dec__Part]*, i16 } @core__slice__Index([0 x %num__flt2dec__Part]* noalias nonnull readonly align 1 %8, i16 %9, i16 1)
  %13 = getelementptr inbounds %num__flt2dec__Formatted, %num__flt2dec__Formatted* %0, i16 0, i32 3, i32 1
  store i16 0, i16* %13, align 1
  ret void

bb18:                                             ; preds = %bb5
  %14 = bitcast [0 x %num__flt2dec__Part]* %8 to %num__flt2dec__Part__Copy*
  %15 = getelementptr inbounds %num__flt2dec__Part__Copy, %num__flt2dec__Part__Copy* %14, i16 0, i32 1, i32 0
  store [0 x i8]* bitcast (<{ [3 x i8] }>* @anon.4c2386cf7531a237a70031c52b819347.57 to [0 x i8]*), [0 x i8]** %15, align 1
  unreachable

bb30:                                             ; preds = %bb5
  %16 = icmp slt i16 %3, 1
  %17 = icmp sgt i16 %4, 0
  %_61.0 = and i1 %16, %17
  %. = select i1 %5, [0 x i8]* bitcast (<{ [3 x i8] }>* @anon.4c2386cf7531a237a70031c52b819347.63 to [0 x i8]*), [0 x i8]* bitcast (<{ [3 x i8] }>* @anon.4c2386cf7531a237a70031c52b819347.64 to [0 x i8]*)
  %_60.sroa.5.0 = select i1 %_61.0, [0 x i8]* bitcast (<{ [1 x i8] }>* @anon.4c2386cf7531a237a70031c52b819347.56 to [0 x i8]*), [0 x i8]* %.
  %_60.sroa.7.0 = select i1 %_61.0, i16 1, i16 3
  store [0 x i8]* %_60.sroa.5.0, [0 x i8]** undef, align 1
  %_60.sroa.7.0..sroa_idx = getelementptr inbounds [0 x %num__flt2dec__Part], [0 x %num__flt2dec__Part]* %8, i16 0, i16 0, i32 0, i16 3
  %_60.sroa.7.0..sroa_cast52 = bitcast i8* %_60.sroa.7.0..sroa_idx to i16*
  store i16 %_60.sroa.7.0, i16* %_60.sroa.7.0..sroa_cast52, align 1
  unreachable

bb32:                                             ; preds = %bb5
  unreachable
}

attributes #0 = { "target-cpu"="atmega328p" }

!llvm.module.flags = !{!0}

!0 = !{i32 2, !"Debug Info Version", i32 3}

@dylanmckay
Copy link
Member

The first problem looks like a program address space zero bug.

The second one sounds like the regular.

One thing to note is that upstream Rust changed how they acquire LLVM. There's a new repository (avr-rust/llvm-project), so we will need to decide what do do with the previous LLVM (avr-rust/llvm) and the issues / PRs there.

Yeah, the glacial "Move to GitHub"...

I reckon we should fork github.com/llvm/llvm-project, add our branches, leave both repositories up, set the old avr-rust/llvm repo as read-only and go from there.

@shepmaster
Copy link
Member Author

should fork github.com/llvm/llvm-project, add our branches

That’s actually already done and used by this branch.

@dylanmckay
Copy link
Member

When I compile the "ran out of registers" bug on LLVM master. it passes.

@dylanmckay
Copy link
Member

LLVM ERROR: Cannot select: t2: i16 = addrspacecast[1 -> 0] undef:i16

Submitted a fix for upstream code review D62775.

@dylanmckay
Copy link
Member

I now think that the addrspacecast has been introduced erroneously by the LLVM middle end - I cannot see any reference to addrspacecast in the entire Rust codebase.

At the moment, the AVR backend does not support addrspacecasts whatsoever. See the upstream fix in my above comment for info.

@dylanmckay
Copy link
Member

Here is the full IR generated from libcore.

libcore.ll.txt

This was generated along the lines of rustup run avr-rust-aa35e73b "xargo" "rustc --target avr-atmega328p --release --target-dir /tmp/avr-libcore -v -- --emit llvm-ir"

@dylanmckay
Copy link
Member

The IR triggering the addrspacecast bug is for the implementation of Debug::fmt for any &T where T: Debug.

For some reason, the %self argument to the IR, a pointer to the receiver, is in addrspace(1). This is also the only function in the entire libcore to have a nonzero address space pointer as the receiver.

$ cat ~/libcore.ll |rg "define.*addrspace.*%self"

define internal zeroext i1 @"_ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17hbd9cadb576049f93E"({ i8*, i8* } ({}*) addrspace(1)*** noalias nocapture readonly align 1 dereferenceable(2) %self, %"fmt::Formatter"* align 1 dereferenceable(27) %f) unnamed_addr addrspace(1) #6 {

@dylanmckay
Copy link
Member

DEBUG 2019-06-07T10:11:25Z: rustc_codegen_llvm::declare: declare_rust_fn(name="_ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h215fbfbb6915067E", sig=Binder(([&&unsafe fn(*const ()), &mut fmt::Formatter<'_>]; c_variadic: false)->result::Result<(), fmt::Error>))

Here is the function that is failing. It is the debug implementation for either &&unsafe fn(*const ()) (void ({}*) addrspace(1)***)

@dylanmckay
Copy link
Member

Here is the IR of the failing function

; <&T as core::fmt::Debug>::fmt
; Function Attrs: uwtable
define internal zeroext i1 @"_ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17hbd9cadb576049f93E"({ i8*, i8* } ({}*) addrspace(1)*** noalias nocapture readonly align 1 dereferenceable(2) %self, %"fmt::Formatter"* align 1 dereferenceable(27) %f) unnamed_addr addrspace(1) #6 {
start:
  %buf.i.i.i.i = alloca [128 x i8], align 1
  %0 = bitcast { i8*, i8* } ({}*) addrspace(1)*** %self to {} addrspace(1)***
  %1 = load {} addrspace(1)**, {} addrspace(1)*** %0, align 1, !nonnull !456
  %2 = load {} addrspace(1)*, {} addrspace(1)** %1, align 1, !alias.scope !5154, !nonnull !456
  %3 = addrspacecast {} addrspace(1)* %2 to {}*
  %4 = ptrtoint {}* %3 to i16
  %5 = getelementptr inbounds %"fmt::Formatter", %"fmt::Formatter"* %f, i16 0, i32 7, i32 0
  %6 = load i8, i8* %5, align 1, !range !2, !noalias !5157
  %7 = getelementptr inbounds %"fmt::Formatter", %"fmt::Formatter"* %f, i16 0, i32 7, i32 1
  %8 = load i16, i16* %7, align 1, !noalias !5157
  %9 = bitcast %"fmt::Formatter"* %f to i32*
  %10 = load i32, i32* %9, align 1, !noalias !5157
  %11 = and i32 %10, 4
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %bb6.i.i, label %bb2.i.i

bb2.i.i:                                          ; preds = %start
  %13 = or i32 %10, 8
  store i32 %13, i32* %9, align 1, !noalias !5157
  %14 = icmp eq i8 %6, 0
  br i1 %14, label %bb3.i.i, label %bb6.i.i

bb3.i.i:                                          ; preds = %bb2.i.i
  store i16 6, i16* %7, align 1, !noalias !5157
  store i8 1, i8* %5, align 1, !noalias !5157
  br label %bb6.i.i

bb6.i.i:                                          ; preds = %bb3.i.i, %bb2.i.i, %start
  %15 = phi i32 [ %10, %start ], [ %13, %bb3.i.i ], [ %13, %bb2.i.i ]
  %16 = or i32 %15, 4
  store i32 %16, i32* %9, align 1, !noalias !5157
  %17 = getelementptr inbounds [128 x i8], [128 x i8]* %buf.i.i.i.i, i16 0, i16 0
  call addrspace(1) void @llvm.lifetime.start.p0i8(i64 128, i8* nonnull %17), !noalias !5160
  %18 = getelementptr inbounds [128 x i8], [128 x i8]* %buf.i.i.i.i, i16 0, i16 128
  br label %bb15.i.i.i.i

bb15.i.i.i.i:                                     ; preds = %bb15.i.i.i.i, %bb6.i.i
  %iter.sroa.4.0.i.i.i.i = phi i8* [ %18, %bb6.i.i ], [ %19, %bb15.i.i.i.i ]
  %x.0.i.i.i.i = phi i16 [ %4, %bb6.i.i ], [ %20, %bb15.i.i.i.i ]
  %curr.0.i.i.i.i = phi i16 [ 128, %bb6.i.i ], [ %26, %bb15.i.i.i.i ]
  %19 = getelementptr inbounds i8, i8* %iter.sroa.4.0.i.i.i.i, i16 -1
  %20 = lshr i16 %x.0.i.i.i.i, 4
  %21 = trunc i16 %x.0.i.i.i.i to i8
  %22 = and i8 %21, 15
  %23 = icmp ult i8 %22, 10
  %24 = or i8 %22, 48
  %25 = add nuw nsw i8 %22, 87
  %_0.0.i15.i.i.i.i = select i1 %23, i8 %24, i8 %25
  store i8 %_0.0.i15.i.i.i.i, i8* %19, align 1, !noalias !5160
  %26 = add nsw i16 %curr.0.i.i.i.i, -1
  %27 = icmp eq i16 %20, 0
  br i1 %27, label %bb43.i.i.i.i, label %bb15.i.i.i.i

bb43.i.i.i.i:                                     ; preds = %bb15.i.i.i.i
  %28 = icmp ugt i16 %26, 128
  br i1 %28, label %bb1.i.i.i.i.i.i.i, label %"_ZN4core3ptr87_$LT$impl$u20$core..fmt..Debug$u20$for$u20$unsafe$u20$fn$LP$A$RP$$u20$.$GT$$u20$Ret$GT$3fmt17ha5a3565824dd93e2E.exit"

bb1.i.i.i.i.i.i.i:                                ; preds = %bb43.i.i.i.i
; call core::slice::slice_index_order_fail
  tail call addrspace(1) void @_ZN4core5slice22slice_index_order_fail17h1a521a1329c8fcf9E(i16 %26, i16 128) #17, !noalias !5160
  unreachable

"_ZN4core3ptr87_$LT$impl$u20$core..fmt..Debug$u20$for$u20$unsafe$u20$fn$LP$A$RP$$u20$.$GT$$u20$Ret$GT$3fmt17ha5a3565824dd93e2E.exit": ; preds = %bb43.i.i.i.i
  %29 = getelementptr inbounds [128 x i8], [128 x i8]* %buf.i.i.i.i, i16 0, i16 %26
  %30 = sub i16 129, %curr.0.i.i.i.i
  %_3.sroa.0.0._3.sroa.0.0..cast.i.i.i.i.i = bitcast i8* %29 to [0 x i8]*
; call core::fmt::Formatter::pad_integral
  %31 = call zeroext addrspace(1) i1 @_ZN4core3fmt9Formatter12pad_integral17h8cbb788acd2ae784E(%"fmt::Formatter"* nonnull align 1 dereferenceable(27) %f, i1 zeroext true, [0 x i8]* noalias nonnull readonly align 1 bitcast (<{ [2 x i8] }>* @anon.1eadd1440c2e72f10a9c27e27f9e4574.191 to [0 x i8]*), i16 2, [0 x i8]* noalias nonnull readonly align 1 %_3.sroa.0.0._3.sroa.0.0..cast.i.i.i.i.i, i16 %30), !noalias !5160
  call addrspace(1) void @llvm.lifetime.end.p0i8(i64 128, i8* nonnull %17), !noalias !5160
  store i8 %6, i8* %5, align 1, !noalias !5157
  store i16 %8, i16* %7, align 1, !noalias !5157
  store i32 %10, i32* %9, align 1, !noalias !5157
  ret i1 %31
}

@dylanmckay
Copy link
Member

It seems like LLVM/Rust is choking because when debug printing function pointers.

This is the shoddy IR

  %3 = addrspacecast {} addrspace(1)* %2 to {}*
  %4 = ptrtoint {}* %3 to i16

In order to convert an addrspace(1) pointer to an integer for debug printing, it first attempts to convert it to a pointer in the default address space zero, and then convert that pointer to an integer for printing.

Think of it like this PROGMEM function pointer -> RAM pointer -> integer representation.

On AVR, you cannot convert a PROGMEM function pointer into a RAM pointer (the physical memory spaces are disjoint). Also, it probably makes more sense to print the PROGMEM function pointer when debug printing functions.

We should just go PROGMEM function pointer -> integer representation. The address space cast is unnecessary, and in fact, harmful.

I am not sure if it is possible to implement the addrspacecast instruction in the AVR backend.

We need to modify Rust so that it does not attempt this address space conversion and instead use ptrtoint on the addrspace(1) pointer.

@shepmaster
Copy link
Member Author

That code is here; but it doesn't do anything too weird, so any changes may need to be lower down.

@ecstatic-morse
Copy link

ecstatic-morse commented Jun 8, 2019

The underlying issue is that *const T always has addrspace(0). I think explicit casts (ptr as *const T) should preserve the address space of their input here.

@dylanmckay
Copy link
Member

Here is the mir for the function in question

// MIR for `ptr::<impl at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2625:9: 2630:10>::fmt`
// source = MirSource { instance: Item(DefId(0/0:9218 ~ core[fd1a]::ptr[0]::{{impl}}[235]::fmt[0])), promoted: None }
// pass_name = TypeckMir
// disambiguator = before

fn  ptr::<impl at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2625:9: 2630:10>::fmt(_1: &for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret, _2: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
    let mut _0: result::Result<(), fmt::Error>; // return place
    let mut _3: &*const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret;
    let mut _4: &*const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret;
    let _5: *const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret;
    let mut _6: for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret;
    let mut _7: &mut fmt::Formatter<'_>;

    bb0: {
        StorageLive(_3);                 // bb0[0]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:35: 2627:59
        StorageLive(_4);                 // bb0[1]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:35: 2627:59
        StorageLive(_5);                 // bb0[2]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:36: 2627:59
        StorageLive(_6);                 // bb0[3]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:37: 2627:42
        _6 = (*_1);                      // bb0[4]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:37: 2627:42
        _5 = move _6 as *const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret (Misc); // bb0[5]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:36: 2627:59
        StorageDead(_6);                 // bb0[6]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:58: 2627:59
        _4 = &_5;                        // bb0[7]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:35: 2627:59
        _3 = &(*_4);                     // bb0[8]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:35: 2627:59
        StorageLive(_7);                 // bb0[9]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:61: 2627:62
        _7 = &mut (*_2);                 // bb0[10]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:61: 2627:62
        _0 = const fmt::Pointer::fmt(move _3, move _7) -> [return: bb2, unwind: bb1]; // bb0[11]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:17: 2627:63
                                         // ty::Const
                                         // + ty: for<'r, 's, 't0> fn(&'r *const for<'t1> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'t1>, ...) -> Ret, &'s mut fmt::Formatter<'t0>) -> result::Result<(), fmt::Error> {<*const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret as fmt::Pointer>::fmt}
                                         // + val: Scalar(Bits { size: 0, bits: 0 })
                                         // mir::Constant
                                         // + span: /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:17: 2627:34
                                         // + ty: for<'r, 's, 't0> fn(&'r *const for<'t1> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'t1>, ...) -> Ret, &'s mut fmt::Formatter<'t0>) -> result::Result<(), fmt::Error> {<*const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret as fmt::Pointer>::fmt}
                                         // + literal: Const { ty: for<'r, 's, 't0> fn(&'r *const for<'t1> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'t1>, ...) -> Ret, &'s mut fmt::Formatter<'t0>) -> result::Result<(), fmt::Error> {<*const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret as fmt::Pointer>::fmt}, val: Scalar(Bits { size: 0, bits: 0 }) }
    }

    bb1 (cleanup): {
        resume;                          // bb1[0]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2626:13: 2629:14
    }

    bb2: {
        StorageDead(_7);                 // bb2[0]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:62: 2627:63
        StorageDead(_3);                 // bb2[1]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:62: 2627:63
        StorageDead(_4);                 // bb2[2]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2629:13: 2629:14
        StorageDead(_5);                 // bb2[3]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2629:13: 2629:14
        return;                          // bb2[4]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2629:14: 2629:14
    }
}

@dylanmckay
Copy link
Member

Raised #143 for the addrspace issue.

@dylanmckay
Copy link
Member

dylanmckay commented Jun 8, 2019

This PR (currently at 8b7240e) can successfully compile the blink program in release mode.

When I try to compile in debug mode, I get errorsl ike this:

gu.o): in function `LBB76_7':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x11d88): undefined reference to `__lshrsi3'
          /usr/bin/avr-ld: /home/dylan/.xargo/lib/rustlib/avr-atmega328p/lib/libcompiler_builtins-95059f720b775154.rlib(compiler_builtins-95059f720b775154.compiler_builtins.c92c25ra-cgu.0.rc
gu.o): in function `LBB83_21':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x12db4): undefined reference to `__ashlsi3'
          /usr/bin/avr-ld: compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x12dc8): undefined reference to `__lshrsi3'
          /usr/bin/avr-ld: /home/dylan/.xargo/lib/rustlib/avr-atmega328p/lib/libcompiler_builtins-95059f720b775154.rlib(compiler_builtins-95059f720b775154.compiler_builtins.c92c25ra-cgu.0.rcgu.o): in function `LBB84_21':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x13496): undefined reference to `__ashlsi3'
          /usr/bin/avr-ld: compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x134b4): undefined reference to `__lshrsi3'
          /usr/bin/avr-ld: /home/dylan/.xargo/lib/rustlib/avr-atmega328p/lib/libcompiler_builtins-95059f720b775154.rlib(compiler_builtins-95059f720b775154.compiler_builtins.c92c25ra-cgu.0.rcgu.o): in function `LBB85_24':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x13bcc): undefined reference to `__ashlsi3'
          /usr/bin/avr-ld: compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x13be8): undefined reference to `__lshrsi3'
          /usr/bin/avr-ld: /home/dylan/.xargo/lib/rustlib/avr-atmega328p/lib/libcompiler_builtins-95059f720b775154.rlib(compiler_builtins-95059f720b775154.compiler_builtins.c92c25ra-cgu.0.rcgu.o): in function `LBB90_93':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1565a): undefined reference to `__lshrsi3'
          /usr/bin/avr-ld: /home/dylan/.xargo/lib/rustlib/avr-atmega328p/lib/libcompiler_builtins-95059f720b775154.rlib(compiler_builtins-95059f720b775154.compiler_builtins.c92c25ra-cgu.0.rc
gu.o): in function `<i32 as compiler_builtins::int::Int>::wrapping_shl':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x18eac): undefined reference to `__ashlsi3'
          /usr/bin/avr-ld: /home/dylan/.xargo/lib/rustlib/avr-atmega328p/lib/libcompiler_builtins-95059f720b775154.rlib(compiler_builtins-95059f720b775154.compiler_builtins.c92c25ra-cgu.0.rc
gu.o): in function `LBB148_9':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1a9f2): undefined reference to `__divmodti4'
          /usr/bin/avr-ld: /home/dylan/.xargo/lib/rustlib/avr-atmega328p/lib/libcompiler_builtins-95059f720b775154.rlib(compiler_builtins-95059f720b775154.compiler_builtins.c92c25ra-cgu.0.rc
gu.o): in function `LBB149_9':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1ac42): undefined reference to `__divmodti4'
          /usr/bin/avr-ld: /home/dylan/.xargo/lib/rustlib/avr-atmega328p/lib/libcompiler_builtins-95059f720b775154.rlib(compiler_builtins-95059f720b775154.compiler_builtins.c92c25ra-cgu.0.rc
gu.o): in function `<u32 as compiler_builtins::int::WideInt>::wide_shift_left':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1b7ec): undefined reference to `__ashlsi3'
          /usr/bin/avr-ld: compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1b806): undefined reference to `__lshrsi3'
          /usr/bin/avr-ld: compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1b82c): undefined reference to `__ashlsi3'
          /usr/bin/avr-ld: /home/dylan/.xargo/lib/rustlib/avr-atmega328p/lib/libcompiler_builtins-95059f720b775154.rlib(compiler_builtins-95059f720b775154.compiler_builtins.c92c25ra-cgu.0.rc
gu.o): in function `LBB169_3':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1b8d2): undefined reference to `__lshrsi3'
          /usr/bin/avr-ld: compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1b8ea): undefined reference to `__ashlsi3'
          /usr/bin/avr-ld: compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1b906): undefined reference to `__ashlsi3'
          /usr/bin/avr-ld: compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1b934): undefined reference to `__lshrsi3'
          /usr/bin/avr-ld: /home/dylan/.xargo/lib/rustlib/avr-atmega328p/lib/libcompiler_builtins-95059f720b775154.rlib(compiler_builtins-95059f720b775154.compiler_builtins.c92c25ra-cgu.0.rc
gu.o): in function `LBB169_7':
          compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1b976): undefined reference to `__lshrsi3'
          /usr/bin/avr-ld: compiler_builtins.c92c25ra-cgu.0:(.progmem.data+0x1b98e): undefined reference to `__ashlsi3'

Sounds like avr-llvm/llvm#163.

@dylanmckay
Copy link
Member

dylanmckay commented Jun 8, 2019

I've raised PR #144, which is another rebase on top of this. I've also cherry-picked some commits at the top of avr-support that hadn't been pulled into this branch.

@dylanmckay
Copy link
Member

Superseded by #144 .

@dylanmckay dylanmckay closed this Jun 9, 2019
@shepmaster shepmaster deleted the avr-support-aa35e73b branch June 9, 2019 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.