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

Invalid bitcast error when building rustc (rustc-std-workspace-core) #110472

Closed
bryangarza opened this issue Apr 18, 2023 · 10 comments
Closed

Invalid bitcast error when building rustc (rustc-std-workspace-core) #110472

bryangarza opened this issue Apr 18, 2023 · 10 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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.

Comments

@bryangarza
Copy link
Contributor

bryangarza commented Apr 18, 2023

Description

I'm building rustc on an Amazon Linux 2 (m5.24xlarge) machine. This has worked for me the last 5 months, but currently, HEAD is giving me an error when running ./x.py build library.

I thought that it was maybe something I had caused, so I spun up a brand new instance, but I'm still able to reproduce.

Meta

uname -a:

Linux <redacted> <redacted>.amzn2int.x86_64 #1 SMP Sat Mar 11 23:51:58 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

rust HEAD

7908a1d65496b88626e4b7c193c81d777005d6f3

Error output

Assembling stage1 compiler
Building stage1 library artifacts (x86_64-unknown-linux-gnu)
   Compiling compiler_builtins v0.1.91
   Compiling core v0.0.0 (/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/library/core)
   Compiling libc v0.2.140
   Compiling cc v1.0.77
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/library/std)
   Compiling unwind v0.0.0 (/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/library/unwind)
   Compiling rustc-std-workspace-core v1.99.0 (/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/library/rustc-std-workspace-core)
Invalid bitcast
ptr bitcast (ptr addrspace(14979816) @anon.0dd304449d08a524feadd4cd33e8bcb6.1 to ptr)
LLVM ERROR: Broken module found, compilation aborted!
error: could not compile `core`
warning: build failed, waiting for other jobs to finish...
huge alignment values are unsupported
  %15 = load i64, ptr %9, align 70368744177664
huge alignment values are unsupported
  %16 = load i64, ptr %8, align 70368744177664
huge alignment values are unsupported
  %26 = load i32, ptr %20, align 70368744177664
huge alignment values are unsupported
  %27 = load i32, ptr %19, align 70368744177664
huge alignment values are unsupported
  %37 = load i16, ptr %31, align 70368744177664
huge alignment values are unsupported
  %38 = load i16, ptr %30, align 70368744177664
huge alignment values are unsupported
  %146 = load i128, ptr %144, align 70368744177664
huge alignment values are unsupported
  %147 = load i128, ptr %145, align 70368744177664
in function _ZN17compiler_builtins3mem6memcmp17h39b65de6ac43991cE
LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `compiler_builtins`
huge alignment values are unsupported
  %2 = load i32, huge alignment values are unsupportedptr
   %0, align %703687441776643 = load i
64, ptr %2, align 70368744177664
in function in function _ZN70_$LT$libc..unix..linux_like..in_addr$u20$as$u20$core..clone..Clone$GT$5clone17h3189a06ce16fa8eaE_ZN4libc4unix10linux_like5linux3gnu76_$LT$impl$u20$libc..unix..linux_like..linux..gnu..b64..x86_64..siginfo_t$GT$8si_value17h7c477f7ca72cc0a2E

LLVM ERROR: Broken function found, compilation aborted!LLVM ERROR: Broken function found, compilation aborted!

error: could not compile `libc`
Build completed unsuccessfully in 0:03:28
@bryangarza bryangarza 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 Apr 18, 2023
@nikic
Copy link
Contributor

nikic commented Apr 18, 2023

Could you please rerun the last rustc command (maybe you need to pass -v to get it) with -C save-temps and zip the *.bc files it produces?

@nikic nikic added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Apr 18, 2023
@bryangarza
Copy link
Contributor Author

Could you please rerun the last rustc command (maybe you need to pass -v to get it) with -C save-temps and zip the *.bc files it produces?

Here it is:
save-temps.zip

the command I ran

(I actually ran it twice because the first time I wasn't sure if it was working and then I later found where the *.bc files are stored.)

cd "/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2" && AR_x86_64_unknown_linux_gnu="ar" CARGO_INCREMENTAL="1" CARGO_PROFILE_RELEASE_DEBUG="0" CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS="false" CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS="false" CARGO_TARGET_DIR="/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/x86_64-unknown-linux-gnu/stage1-std" CC_x86_64_unknown_linux_gnu="cc" CFG_COMPILER_HOST_TRIPLE="x86_64-unknown-linux-gnu" CFG_RELEASE_CHANNEL="dev" CFLAGS_x86_64_unknown_linux_gnu="-ffunction-sections -fdata-sections -fPIC -m64" CXXFLAGS_x86_64_unknown_linux_gnu="-ffunction-sections -fdata-sections -fPIC -m64" CXX_x86_64_unknown_linux_gnu="c++" LIBC_CHECK_CFG="1" RANLIB_x86_64_unknown_linux_gnu="ar s" REAL_LIBRARY_PATH_VAR="LD_LIBRARY_PATH" RUSTBUILD_NATIVE_DIR="/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/x86_64-unknown-linux-gnu/native" RUSTC="/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/bootstrap/debug/rustc" RUSTC_BACKTRACE_ON_ICE="1" RUSTC_BOOTSTRAP="1" RUSTC_BREAK_ON_ICE="1" RUSTC_ERROR_METADATA_DST="/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/tmp/extended-error-metadata" RUSTC_FORCE_UNSTABLE="1" RUSTC_INSTALL_BINDIR="bin" RUSTC_LIBDIR="/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/x86_64-unknown-linux-gnu/stage1/lib" RUSTC_LINT_FLAGS="-Wrust_2018_idioms -Wunused_lifetimes -Wsemicolon_in_expressions_from_macros -Dwarnings" RUSTC_REAL="/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" RUSTC_SNAPSHOT="/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/x86_64-unknown-linux-gnu/stage0/bin/rustc" RUSTC_SNAPSHOT_LIBDIR="/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/x86_64-unknown-linux-gnu/stage0/lib" RUSTC_STAGE="1" RUSTC_SYSROOT="/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/x86_64-unknown-linux-gnu/stage1" RUSTC_VERBOSE="1" RUSTDOC="/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/bootstrap/debug/rustdoc" RUSTDOCFLAGS="-Csymbol-mangling-version=legacy -Zunstable-options -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(stdarch_intel_sde) --check-cfg=values(no_fp_fmt_parse) --check-cfg=values(no_global_oom_handling) --check-cfg=values(no_rc) --check-cfg=values(no_sync) --check-cfg=values(freebsd12) --check-cfg=values(freebsd13) --check-cfg=values(backtrace_in_libstd) --check-cfg=values(target_env,"libnx") --check-cfg=values(target_arch,"asmjs","spirv","nvptx","xtensa","loongarch64") --check-cfg=values(target_env,"ohos") -Dwarnings -Wrustdoc::invalid_codeblock_attributes --crate-version 1.71.0-dev -Zcrate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/\")" RUSTDOC_REAL="/path/to/nowhere/rustdoc/not/required" RUSTFLAGS="-Csymbol-mangling-version=legacy -Zunstable-options -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(stdarch_intel_sde) --check-cfg=values(no_fp_fmt_parse) --check-cfg=values(no_global_oom_handling) --check-cfg=values(no_rc) --check-cfg=values(no_sync) --check-cfg=values(freebsd12) --check-cfg=values(freebsd13) --check-cfg=values(backtrace_in_libstd) --check-cfg=values(target_env,"libnx") --check-cfg=values(target_arch,"asmjs","spirv","nvptx","xtensa","loongarch64") --check-cfg=values(target_env,"ohos") -Zmacro-backtrace -Clink-args=-Wl,-z,origin -Clink-args=-Wl,-rpath,$ORIGIN/../lib -Csplit-debuginfo=off -Cprefer-dynamic -Cllvm-args=-import-instr-limit=10 -Zinline-mir -Cembed-bitcode=yes -Clto=off -Csave-temps=yes -Zcrate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/\")" RUST_TEST_THREADS="96" WINAPI_NO_BUNDLED_LIBRARIES="1" __CARGO_DEFAULT_LIB_METADATA="devstd" "/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "--release" "-Zcheck-cfg=names,values,output" "-Zbinary-dep-depinfo" "-j" "96" "-v" "--features" " panic-unwind backtrace" "--manifest-path" "/local/home/garzbrya/projects/rustc/issue-110467-safe-transmute2/library/test/Cargo.toml" "--message-format" "json-render-diagnostics"

@nikic
Copy link
Contributor

nikic commented Apr 19, 2023

Some of the optimized bitcode files do contain invalid alignments, but I did not manage to produce such corrupted files from the unoptimized bitcodes files.

@bryangarza
Copy link
Contributor Author

Update: I used git bisect -- the LLVM 16 commit seems to be the one causing the error #109474

@bryangarza
Copy link
Contributor Author

Seems setting download-ci-llvm = false in the config.toml allows the build to succeed without errors

@pnkfelix
Copy link
Member

pnkfelix commented May 3, 2023

I did some reduction of the libc input and got things down to this, which reproduces the problem but only with the rustc that is built with download-ci-llvm=true:

#![feature(no_core, const_trait_impl, rustc_attrs, lang_items, fundamental, auto_traits)]
#![no_std]
#![no_core]
#![crate_type="rlib"]

#[lang = "copy"] trait Copy: Clone { }
#[lang = "clone"] trait Clone: Sized { fn clone(&self) -> Self; }
#[lang = "sized"] trait Sized { }
#[lang = "freeze"] unsafe auto trait Freeze {}
#[lang = "receiver"] trait Receiver { } impl<T: ?Sized> Receiver for &T {}

impl Copy for u8 {}
impl Copy for [u8; 1] {}
impl Clone for u8 { fn clone(&self) -> Self { *self } }
impl Clone for [u8; 1] { fn clone(&self) -> Self { *self } }

struct Pc { _size: [u8; 1], }
impl Copy for Pc {}
impl Clone for Pc { fn clone(&self) -> Pc { *self } }

Invocation:

./build/x86_64-unknown-linux-gnu/stage1/bin/rustc simple.rs -C opt-level=1 -Clto=false -C codegen-units=1 -C llvm-args=-opt-bisect-limit=10

Output:

BISECT: running pass (1) Annotation2MetadataPass on [module]
BISECT: running pass (2) ForceFunctionAttrsPass on [module]
BISECT: running pass (3) InferFunctionAttrsPass on [module]
BISECT: running pass (4) LowerExpectIntrinsicPass on _ZN36_$LT$u8$u20$as$u20$simple..Clone$GT$5clone17h3411880f7ff41262E
BISECT: running pass (5) SimplifyCFGPass on _ZN36_$LT$u8$u20$as$u20$simple..Clone$GT$5clone17h3411880f7ff41262E
BISECT: running pass (6) SROAPass on _ZN36_$LT$u8$u20$as$u20$simple..Clone$GT$5clone17h3411880f7ff41262E
BISECT: running pass (7) EarlyCSEPass on _ZN36_$LT$u8$u20$as$u20$simple..Clone$GT$5clone17h3411880f7ff41262E
BISECT: running pass (8) LowerExpectIntrinsicPass on _ZN57_$LT$$u5b$u8$u3b$$u20$1$u5d$$u20$as$u20$simple..Clone$GT$5clone17hfbbe4e8d0c1471c4E
BISECT: running pass (9) SimplifyCFGPass on _ZN57_$LT$$u5b$u8$u3b$$u20$1$u5d$$u20$as$u20$simple..Clone$GT$5clone17hfbbe4e8d0c1471c4E
BISECT: running pass (10) SROAPass on _ZN57_$LT$$u5b$u8$u3b$$u20$1$u5d$$u20$as$u20$simple..Clone$GT$5clone17hfbbe4e8d0c1471c4E
BISECT: NOT running pass (11) EarlyCSEPass on _ZN57_$LT$$u5b$u8$u3b$$u20$1$u5d$$u20$as$u20$simple..Clone$GT$5clone17hfbbe4e8d0c1471c4E
[...]
BISECT: NOT running pass (233) X86 LEA Fixup on function (_ZN36_$LT$u8$u20$as$u20$simple..Clone$GT$5clone17h3411880f7ff41262E)
huge alignment values are unsupported
  %2 = load i8, ptr %0, align 4611686018427387904
in function _ZN57_$LT$$u5b$u8$u3b$$u20$1$u5d$$u20$as$u20$simple..Clone$GT$5clone17hfbbe4e8d0c1471c4E
LLVM ERROR: Broken function found, compilation aborted!

@veera-sivarajan
Copy link
Contributor

veera-sivarajan commented Dec 20, 2023

Running into this on commit f704f3b93b1543cf504ecca0052f9f8531b1f61f as well.

@nikic
Copy link
Contributor

nikic commented Dec 20, 2023

Per https://pkgs.org/search/?q=libstdc%2B%2B it looks like Amazon Linux 2 uses libstdc++ 7, which is ABI incompatible with the libLLVM.so for download-ci-llvm. I believe you need at least libstdc++ 8.

Possibly the build system should check the version.

@onur-ozkan
Copy link
Member

Possibly the build system should check the version.

#125411 would catch this problem.

@onur-ozkan
Copy link
Member

Per https://pkgs.org/search/?q=libstdc%2B%2B it looks like Amazon Linux 2 uses libstdc++ 7, which is ABI incompatible with the libLLVM.so for download-ci-llvm. I believe you need at least libstdc++ 8.

Possibly the build system should check the version.

Closing this as #125411 is merged and now the build system is capable of checking libstdc++ version. Feel free to re-open if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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.
Projects
None yet
Development

No branches or pull requests

5 participants