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 panicked struct cannot be packed and aligned #83107

Closed
Andy-Python-Programmer opened this issue Mar 14, 2021 · 5 comments · Fixed by #83319
Closed

Rustc panicked struct cannot be packed and aligned #83107

Andy-Python-Programmer opened this issue Mar 14, 2021 · 5 comments · Fixed by #83319
Labels
A-layout Area: Memory layout of types C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Andy-Python-Programmer
Copy link
Contributor

Andy-Python-Programmer commented Mar 14, 2021

Code

#[repr(packed, align(0x1000))]
struct GDT {
    kernel_null: GDTEntry,
    kernel_code: GDTEntry,
    kernel_data: GDTEntry,
    user_null: GDTEntry,
    user_code: GDTEntry,
    user_data: GDTEntry,
}

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (44e3daf5e 2020-12-31)
binary: rustc
commit-hash: 44e3daf5eee8263dfc3a2509e78ddd1f6f783a0e
commit-date: 2020-12-31
host: x86_64-pc-windows-msvc
release: 1.51.0-nightly

Error output

error[E0587]: type has conflicting packed and align representation hints
  --> src\gdt.rs:34:1
   |
34 | / struct GDT {
35 | |     kernel_null: GDTEntry,
36 | |     kernel_code: GDTEntry,
37 | |     kernel_data: GDTEntry,
...  |
40 | |     user_data: GDTEntry,
41 | | }
   | |_^

error: internal compiler error: compiler\rustc_middle\src\ty\layout.rs:283:13: struct cannot be packed and aligned

thread 'rustc' panicked at 'Box<Any>', compiler\rustc_errors\src\lib.rs:958:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.51.0-nightly (44e3daf5e 2020-12-31) running on x86_64-pc-windows-msvc

note: compiler flags: -Z unstable-options -C panic=abort -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin   

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [layout_raw] computing layout of `gdt::GDT`
#1 [layout_raw] computing layout of `core::option::Option<gdt::GDT>`
end of query stack
error: aborting due to 2 previous errors
Backtrace

PS H:\Andy\Rust\aero> $Env:RUST_BACKTRACE="full"; cargo run -- -L H:\Programs\qemu
   Compiling aero v0.1.0 (H:\Andy\Rust\aero)
error[E0587]: type has conflicting packed and align representation hints
  --> src\gdt.rs:34:1
   |
34 | / struct GDT {
35 | |     kernel_null: GDTEntry,
36 | |     kernel_code: GDTEntry,
37 | |     kernel_data: GDTEntry,
...  |
40 | |     user_data: GDTEntry,
41 | | }
   | |_^

error: internal compiler error: compiler\rustc_middle\src\ty\layout.rs:283:13: struct cannot be packed and aligned

thread 'rustc' panicked at 'Box<Any>', compiler\rustc_errors\src\lib.rs:958:9
stack backtrace:
   0:     0x7ff8a16bbcf5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h17841712fc816a42
   1:     0x7ff8a16e84fb - core::fmt::write::ha3ea633b18d2da75
   2:     0x7ff8a16ad5dd - <std::io::IoSlice as core::fmt::Debug>::fmt::h9df41d37d9186c48
   3:     0x7ff8a16bfecd - std::panicking::take_hook::h78f8a454f3a4df82
   4:     0x7ff8a16bf9d3 - std::panicking::take_hook::h78f8a454f3a4df82
   5:     0x7ff8a1c72267 - rustc_driver::report_ice::h1d5c5221edf9c73d
   6:     0x7ff8a16c09af - std::panicking::rust_panic_with_hook::h9fd6ff93f12148ea
   7:     0x7ff8a6434cc0 - <rustc_errors::diagnostic::StringPart as core::fmt::Debug>::fmt::h7af67de8d2c3b61b
   8:     0x7ff8a6434c49 - <rustc_errors::diagnostic::StringPart as core::fmt::Debug>::fmt::h7af67de8d2c3b61b
   9:     0x7ff8a6434c61 - <rustc_errors::diagnostic::StringPart as core::fmt::Debug>::fmt::h7af67de8d2c3b61b
  10:     0x7ff8a642c3cb - rustc_errors::HandlerInner::err_count::h50c6ffc480963ac8
  11:     0x7ff8a642a532 - rustc_errors::Handler::bug::hb269e1fa812030f1
  12:     0x7ff8a5f72f5f - rustc_middle::util::bug::bug_fmt::ha0061901ad88904d
  13:     0x7ff8a5f6c260 - rustc_middle::ty::context::TyCtxt::article_and_description::h7f14ebacbcec16d1
  14:     0x7ff8a5f6c203 - rustc_middle::ty::context::TyCtxt::article_and_description::h7f14ebacbcec16d1
  15:     0x7ff8a5f72e89 - rustc_middle::util::bug::bug_fmt::ha0061901ad88904d
  16:     0x7ff8a5f72df7 - rustc_middle::util::bug::bug_fmt::ha0061901ad88904d
  17:     0x7ff8a6193605 - rustc_middle::ty::layout::provide::ha2084c0ba82f554f
  18:     0x7ff8a6198f58 - rustc_middle::ty::layout::provide::ha2084c0ba82f554f
  19:     0x7ff8a61910ce - <rustc_middle::ty::layout::LayoutError as core::fmt::Display>::fmt::h34fee29140973e21
  20:     0x7ff8a61aa2ce - rustc_middle::ty::print::pretty::<impl core::fmt::Display for &rustc_middle::ty::consts::Const>::fmt::he09b2b8aabe4d576
  21:     0x7ff8a615393f - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::debug_node::h067a466f347afbfa
  22:     0x7ff8a60a3b9d - ZN12rustc_middle2ty111_DERIVE_rustc_data_structures_stable_hasher_HashStable_rustc_middle_ich_StableHashingContext_ctx_FOR_SymbolName159_$LT$impl$u20$rustc_data_structures..stable_hasher..HashStable$LT$rustc_middle..ich..hcx..StableHashingContext$GT$$u20$
  23:     0x7ff8a5f9f759 - <rustc_middle::traits::query::type_op::AscribeUserType as core::fmt::Debug>::fmt::h49093761cb58c0fe
  24:     0x7ff8a61cffcf - rustc_middle::ty::context::tls::TLV::__getit::h11706421b91a7f31
  25:     0x7ff8a61a0ae5 - <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of::hf8e84e4cfee5d9c9
  26:     0x7ff8a604976f - rustc_middle::ty::structural_impls::<impl rustc_middle::ty::context::Lift for rustc_ast::ast::InlineAsmOptions>::lift_to_tcx::h4b1c274e9c27b41d
  27:     0x7ff8a5dfcd3a - <rustc_infer::infer::error_reporting::nice_region_error::find_anon_type::TyPathVisitor as rustc_hir::intravisit::Visitor>::visit_lifetime::hd4dc4e580c3cd603
  28:     0x7ff8a6049c14 - rustc_middle::ty::structural_impls::<impl rustc_middle::ty::context::Lift for rustc_ast::ast::InlineAsmOptions>::lift_to_tcx::h4b1c274e9c27b41d
  29:     0x7ff8a5deee98 - <rustc_infer::infer::error_reporting::nice_region_error::find_anon_type::TyPathVisitor as rustc_hir::intravisit::Visitor>::visit_lifetime::hd4dc4e580c3cd603
  30:     0x7ff8a61946d7 - rustc_middle::ty::layout::provide::ha2084c0ba82f554f
  31:     0x7ff8a61910ce - <rustc_middle::ty::layout::LayoutError as core::fmt::Display>::fmt::h34fee29140973e21
  32:     0x7ff8a61aa2ce - rustc_middle::ty::print::pretty::<impl core::fmt::Display for &rustc_middle::ty::consts::Const>::fmt::he09b2b8aabe4d576
  33:     0x7ff8a615393f - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::debug_node::h067a466f347afbfa
  34:     0x7ff8a60a3b9d - ZN12rustc_middle2ty111_DERIVE_rustc_data_structures_stable_hasher_HashStable_rustc_middle_ich_StableHashingContext_ctx_FOR_SymbolName159_$LT$impl$u20$rustc_data_structures..stable_hasher..HashStable$LT$rustc_middle..ich..hcx..StableHashingContext$GT$$u20$
  35:     0x7ff8a5f9f759 - <rustc_middle::traits::query::type_op::AscribeUserType as core::fmt::Debug>::fmt::h49093761cb58c0fe
  36:     0x7ff8a61cffcf - rustc_middle::ty::context::tls::TLV::__getit::h11706421b91a7f31
  37:     0x7ff8a61a0ae5 - <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of::hf8e84e4cfee5d9c9
  38:     0x7ff8a604976f - rustc_middle::ty::structural_impls::<impl rustc_middle::ty::context::Lift for rustc_ast::ast::InlineAsmOptions>::lift_to_tcx::h4b1c274e9c27b41d
  39:     0x7ff8a5dfcd3a - <rustc_infer::infer::error_reporting::nice_region_error::find_anon_type::TyPathVisitor as rustc_hir::intravisit::Visitor>::visit_lifetime::hd4dc4e580c3cd603
  40:     0x7ff8a6049c14 - rustc_middle::ty::structural_impls::<impl rustc_middle::ty::context::Lift for rustc_ast::ast::InlineAsmOptions>::lift_to_tcx::h4b1c274e9c27b41d
  41:     0x7ff8a5deedfe - <rustc_infer::infer::error_reporting::nice_region_error::find_anon_type::TyPathVisitor as rustc_hir::intravisit::Visitor>::visit_lifetime::hd4dc4e580c3cd603
  42:     0x7ff8a61946d7 - rustc_middle::ty::layout::provide::ha2084c0ba82f554f
  43:     0x7ff8a61910ce - <rustc_middle::ty::layout::LayoutError as core::fmt::Display>::fmt::h34fee29140973e21
  44:     0x7ff8a61aa2ce - rustc_middle::ty::print::pretty::<impl core::fmt::Display for &rustc_middle::ty::consts::Const>::fmt::he09b2b8aabe4d576
  45:     0x7ff8a615393f - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::debug_node::h067a466f347afbfa
  46:     0x7ff8a60a3b9d - ZN12rustc_middle2ty111_DERIVE_rustc_data_structures_stable_hasher_HashStable_rustc_middle_ich_StableHashingContext_ctx_FOR_SymbolName159_$LT$impl$u20$rustc_data_structures..stable_hasher..HashStable$LT$rustc_middle..ich..hcx..StableHashingContext$GT$$u20$
  47:     0x7ff8a5f9f759 - <rustc_middle::traits::query::type_op::AscribeUserType as core::fmt::Debug>::fmt::h49093761cb58c0fe
  48:     0x7ff8a61cffcf - rustc_middle::ty::context::tls::TLV::__getit::h11706421b91a7f31
  49:     0x7ff8a61a0ae5 - <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of::hf8e84e4cfee5d9c9
  50:     0x7ff8a604976f - rustc_middle::ty::structural_impls::<impl rustc_middle::ty::context::Lift for rustc_ast::ast::InlineAsmOptions>::lift_to_tcx::h4b1c274e9c27b41d
  51:     0x7ff8a5dfcdbc - <rustc_infer::infer::error_reporting::nice_region_error::find_anon_type::TyPathVisitor as rustc_hir::intravisit::Visitor>::visit_lifetime::hd4dc4e580c3cd603
  52:     0x7ff8a6049c14 - rustc_middle::ty::structural_impls::<impl rustc_middle::ty::context::Lift for rustc_ast::ast::InlineAsmOptions>::lift_to_tcx::h4b1c274e9c27b41d
  53:     0x7ff8a5deedfe - <rustc_infer::infer::error_reporting::nice_region_error::find_anon_type::TyPathVisitor as rustc_hir::intravisit::Visitor>::visit_lifetime::hd4dc4e580c3cd603
  54:     0x7ff8a61946d7 - rustc_middle::ty::layout::provide::ha2084c0ba82f554f
  55:     0x7ff8a61910ce - <rustc_middle::ty::layout::LayoutError as core::fmt::Display>::fmt::h34fee29140973e21
  56:     0x7ff8a61aa2ce - rustc_middle::ty::print::pretty::<impl core::fmt::Display for &rustc_middle::ty::consts::Const>::fmt::he09b2b8aabe4d576
  57:     0x7ff8a615393f - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::debug_node::h067a466f347afbfa
  58:     0x7ff8a60a3b9d - ZN12rustc_middle2ty111_DERIVE_rustc_data_structures_stable_hasher_HashStable_rustc_middle_ich_StableHashingContext_ctx_FOR_SymbolName159_$LT$impl$u20$rustc_data_structures..stable_hasher..HashStable$LT$rustc_middle..ich..hcx..StableHashingContext$GT$$u20$
  59:     0x7ff8a5f9f759 - <rustc_middle::traits::query::type_op::AscribeUserType as core::fmt::Debug>::fmt::h49093761cb58c0fe
  60:     0x7ff8a61cffcf - rustc_middle::ty::context::tls::TLV::__getit::h11706421b91a7f31
  61:     0x7ff8a61a0ae5 - <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of::hf8e84e4cfee5d9c9
  62:     0x7ff8a604976f - rustc_middle::ty::structural_impls::<impl rustc_middle::ty::context::Lift for rustc_ast::ast::InlineAsmOptions>::lift_to_tcx::h4b1c274e9c27b41d
  63:     0x7ff8a5dfcd3a - <rustc_infer::infer::error_reporting::nice_region_error::find_anon_type::TyPathVisitor as rustc_hir::intravisit::Visitor>::visit_lifetime::hd4dc4e580c3cd603
  64:     0x7ff8a6049c14 - rustc_middle::ty::structural_impls::<impl rustc_middle::ty::context::Lift for rustc_ast::ast::InlineAsmOptions>::lift_to_tcx::h4b1c274e9c27b41d
  65:     0x7ff8a5deedfe - <rustc_infer::infer::error_reporting::nice_region_error::find_anon_type::TyPathVisitor as rustc_hir::intravisit::Visitor>::visit_lifetime::hd4dc4e580c3cd603
  66:     0x7ff8a61946d7 - rustc_middle::ty::layout::provide::ha2084c0ba82f554f
  67:     0x7ff8a61910ce - <rustc_middle::ty::layout::LayoutError as core::fmt::Display>::fmt::h34fee29140973e21
  68:     0x7ff8a61aa2ce - rustc_middle::ty::print::pretty::<impl core::fmt::Display for &rustc_middle::ty::consts::Const>::fmt::he09b2b8aabe4d576
  69:     0x7ff8a615393f - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::debug_node::h067a466f347afbfa
  70:     0x7ff8a60a3b9d - ZN12rustc_middle2ty111_DERIVE_rustc_data_structures_stable_hasher_HashStable_rustc_middle_ich_StableHashingContext_ctx_FOR_SymbolName159_$LT$impl$u20$rustc_data_structures..stable_hasher..HashStable$LT$rustc_middle..ich..hcx..StableHashingContext$GT$$u20$
  71:     0x7ff8a5f9f759 - <rustc_middle::traits::query::type_op::AscribeUserType as core::fmt::Debug>::fmt::h49093761cb58c0fe
  72:     0x7ff8a61cffcf - rustc_middle::ty::context::tls::TLV::__getit::h11706421b91a7f31
  73:     0x7ff8a61a0ae5 - <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of::hf8e84e4cfee5d9c9
  74:     0x7ff8a44471fd - rustc_typeck::check::check::check_wf_new::hf875d581dce6c8aa
  75:     0x7ff8a4448182 - rustc_typeck::check::check::check_item_type::h47398e2438eb86aa
  76:     0x7ff8a4476b46 - <rustc_typeck::check::diverges::Diverges as core::fmt::Debug>::fmt::h7504e50660f2fc6e
  77:     0x7ff8a445329d - rustc_typeck::check::check::check_item_type::h47398e2438eb86aa
  78:     0x7ff8a454350d - <rustc_typeck::check::method::probe::ProbeScope as core::fmt::Debug>::fmt::h59d2657f5d430788
  79:     0x7ff8a44a47c6 - <rustc_typeck::check::closure::ExpectedSig as core::fmt::Debug>::fmt::h63fe94f68923706f
  80:     0x7ff8a446b90b - <rustc_typeck::check::diverges::Diverges as core::fmt::Debug>::fmt::h7504e50660f2fc6e
  81:     0x7ff8a44f73d4 - <rustc_typeck::outlives::explicit::ExplicitPredicatesMap as core::fmt::Debug>::fmt::h15dabe84aedef1e5
  82:     0x7ff8a43dd6f1 - rustc_typeck::check::writeback::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::resolve_type_vars_in_body::h4f2ac8a0d3054276
  83:     0x7ff8a440948f - rustc_typeck::check::writeback::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::resolve_type_vars_in_body::h4f2ac8a0d3054276
  84:     0x7ff8a45672f0 - rustc_typeck::check_crate::h5df5a5c81bc68977
  85:     0x7ff8a1e7bf6a - rustc_interface::passes::QueryContext::print_stats::h17fbfce938bb87d2
  86:     0x7ff8a1ca68cb - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h0da38a96661182e5
  87:     0x7ff8a1ca82e6 - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h0da38a96661182e5
  88:     0x7ff8a1c3023f - chalk_engine::table::AnswerIndex::increment::h2f98e994e5b69c67
  89:     0x7ff8a1c827d1 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::hc313d7aa265f4349
  90:     0x7ff8a1c2c07c - chalk_engine::table::AnswerIndex::increment::h2f98e994e5b69c67
  91:     0x7ff8a1ca9a95 - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h0da38a96661182e5
  92:     0x7ff8a1c744e5 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::hc313d7aa265f4349
  93:     0x7ff8a1cabc0c - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h0da38a96661182e5
  94:     0x7ff8a1c76395 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::hc313d7aa265f4349
  95:     0x7ff8a1c9e8f5 - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h0da38a96661182e5
  96:     0x7ff8a1c0d80d - <tracing_subscriber::util::TryInitError as core::fmt::Display>::fmt::hbce8757813226e4d
  97:     0x7ff8a16cffd3 - std::sys::windows::thread::Thread::new::h0de7ecb752bc4a62
  98:     0x7ff9231d7034 - BaseThreadInitThunk
  99:     0x7ff9241a2651 - RtlUserThreadStart

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.51.0-nightly (44e3daf5e 2020-12-31) running on x86_64-pc-windows-msvc

note: compiler flags: -Z unstable-options -C panic=abort -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [layout_raw] computing layout of `gdt::GDT`
#1 [layout_raw] computing layout of `core::option::Option<gdt::GDT>`
#2 [layout_raw] computing layout of `core::cell::UnsafeCell<core::option::Option<gdt::GDT>>`
#3 [layout_raw] computing layout of `spin::Once<gdt::GDT>`
#4 [layout_raw] computing layout of `lazy_static::lazy::Lazy<gdt::GDT>`
#5 [check_mod_item_types] checking item types in module `gdt`
#6 [analysis] running analysis passes on this crate
end of query stack

@Andy-Python-Programmer Andy-Python-Programmer added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 14, 2021
@jonas-schievink
Copy link
Contributor

Can't reproduce, can you provide the full code that's needed to reproduce this?

@Andy-Python-Programmer
Copy link
Contributor Author

Andy-Python-Programmer commented Mar 14, 2021

Sure

//! This file contains the source for the GDT (Global Descriptor Table).
//! The GDT contains entries telling the CPU about memory segments.
//!
//! **Notes**: https://wiki.osdev.org/Global_Descriptor_Table

use core::intrinsics::size_of;

use lazy_static::lazy_static;

// TODO: Each GDT for every different arch.
// TODO: https://github.com/rust-lang/rust/issues/83107

/// The GDT Descriptor containing the size of offset of the table.
#[repr(C, packed)]
struct GDTDescriptor {
    /// The size of the table subtracted by 1.
    /// The size of the table is subtracted by 1 as the maximum value
    /// of `size` is 65535, while the GDT can be up to 65536 bytes.
    size: u16,
    /// The linear address of the table.
    offset: u64,
}

impl GDTDescriptor {
    /// Create a new GDT descriptor.
    #[inline]
    pub fn new(size: u16, offset: u64) -> Self {
        Self { size, offset }
    }
}

/// A GDT entry.
#[repr(C)]
struct GDTEntry {
    limit_low: u16,
    base_low: u16,
    base_middle: u8,
    access_byte: u8,
    /// Four bits of the variable is the limit and rest four bits of the
    /// variable are the flags.
    limit_hi_flags: u8,
    base_high: u8,
}

impl GDTEntry {
    /// Create a new GDT entry.
    #[inline]
    fn new(
        limit_low: u16,
        base_low: u16,
        base_middle: u8,
        access_byte: u8,
        limit_hi_flags: u8,
        base_high: u8,
    ) -> Self {
        Self {
            limit_low,
            base_low,
            base_middle,
            access_byte,
            limit_hi_flags,
            base_high,
        }
    }
}

/// The GDT.
#[repr(C, packed, align(0x1000))]
struct GDT {
    /// The kernel null segment: `0x00`.
    kernel_null: GDTEntry,
    /// The kernel code segment: `0x08`.
    kernel_code: GDTEntry,
    /// The kernel data segment: `0x10`.
    kernel_data: GDTEntry,
    /// The user null segment.
    user_null: GDTEntry,
    /// The user code segment.
    user_code: GDTEntry,
    /// The user data segment.
    user_data: GDTEntry,
}

/// Initialize the GDT.
pub fn init() {
    unsafe {
        let gdt_descriptor = GDTDescriptor::new(
            (size_of::<GDT>() - 1) as u16,
            (&GLOBAL_DESCRIPTOR_TABLE as *const _) as u64,
        );
    }
}

lazy_static! {
    /// The GDT (Global Descriptor Table).
    static ref GLOBAL_DESCRIPTOR_TABLE: GDT = GDT {
        kernel_null: GDTEntry::new(0, 0, 0, 0x00, 0x00, 0),
        kernel_code: GDTEntry::new(0, 0, 0, 0x9a, 0xa0, 0),
        kernel_data: GDTEntry::new(0, 0, 0, 0x92, 0xa0, 0),
        user_null: GDTEntry::new(0, 0, 0, 0x00, 0x00, 0),
        user_code: GDTEntry::new(0, 0, 0, 0x9a, 0xa0, 0),
        user_data: GDTEntry::new(0, 0, 0, 0x92, 0xa0, 0)
    };
}

@jonas-schievink jonas-schievink added A-layout Area: Memory layout of types I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 14, 2021
@JohnTitor
Copy link
Member

MCVE:

#[repr(packed, align(0x1000))]
pub struct Foo {
    val: u16,
}

static BAR: Foo = Foo {
    val: 0,
};

fn main() {}

@apiraino
Copy link
Contributor

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 17, 2021
@apiraino
Copy link
Contributor

apiraino commented Mar 17, 2021

bisection:

searched nightlies: from nightly-2020-06-01 to nightly-2021-03-17
regressed nightly: nightly-2020-10-27
searched commits: from 4760b8f to fd54259
regressed commit: b9a94c9

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2020-06-01 --regress=ice 

fanninpm added a commit to fanninpm/glacier that referenced this issue Mar 19, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 19, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 15, 2021
Layout error instead of an ICE for packed and aligned types

Fixes rust-lang#83107.
@bors bors closed this as completed in b1f8e27 Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-layout Area: Memory layout of types C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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.

6 participants