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

LLVM build failures on Windows/Mac #135782

Open
Hoverbear opened this issue Jan 20, 2025 · 3 comments · May be fixed by #135836
Open

LLVM build failures on Windows/Mac #135782

Hoverbear opened this issue Jan 20, 2025 · 3 comments · May be fixed by #135836
Labels
C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc E-needs-investigation Call for partcipation: This issues needs some investigation to determine current status O-macos Operating system: macOS O-windows Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@Hoverbear
Copy link
Contributor

Summary

On Windows and Mac, x.py build src/llvm-project can fail when download-ci-llvm = false is set in the config.toml.

Command used

Clone the rust repo, then copy the config.example.toml to config.toml and set the following:

[llvm]
download-ci-llvm = false

Then run:

x.py build src/llvm-project

Expected behaviour

A successful build, exiting 0.

Actual behaviour

On Mac, the result is:

-- Installing: /Users/ana/git/ferrocene/ferrocene/build/aarch64-apple-darwin/lld/lib/cmake/lld/LLDConfigVersion.cmake
cargo:root=/Users/ana/git/ferrocene/ferrocene/build/aarch64-apple-darwin/lld
        finished in 31.764 seconds
Building crtbegin.o and crtend.o for aarch64-apple-darwin
cargo:warning=/Users/ana/git/ferrocene/ferrocene/src/llvm-project/compiler-rt/lib/builtins/crtbegin.c:15:28: error: argument to 'section' attribute is not valid for this target: mach-o section specifier requires a segment and section separated by a comma
cargo:warning=   15 |     __attribute__((section(".eh_frame"), aligned(sizeof(void *)))) = {};
cargo:warning=      |                            ^
cargo:warning=/Users/ana/git/ferrocene/ferrocene/src/llvm-project/compiler-rt/lib/builtins/crtbegin.c:49:24: error: argument to 'section' attribute is not valid for this target: mach-o section specifier requires a segment and section separated by a comma
cargo:warning=   49 | __attribute__((section(".init_array"),
cargo:warning=      |                        ^
cargo:warning=/Users/ana/git/ferrocene/ferrocene/src/llvm-project/compiler-rt/lib/builtins/crtbegin.c:106:24: error: argument to 'section' attribute is not valid for this target: mach-o section specifier requires a segment and section separated by a comma
cargo:warning=  106 | __attribute__((section(".fini_array"),
cargo:warning=      |                        ^
cargo:warning=3 errors generated.


error occurred: Command env -u IPHONEOS_DEPLOYMENT_TARGET "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=arm64-apple-macosx15.2" "-std=c11" "-DCRT_HAS_INITFINI_ARRAY" "-DEH_USE_FRAME_REGISTRY" "-o" "/Users/ana/git/ferrocene/ferrocene/build/aarch64-apple-darwin/native/crt/df7af2d07715af86-crtbegin.o" "-c" "/Users/ana/git/ferrocene/ferrocene/src/llvm-project/compiler-rt/lib/builtins/crtbegin.c" with args cc did not execute successfully (status code exit status: 1).

On Windows, the result is:

-- Installing: D:/git/ferrocene/ferrocene/build/x86_64-pc-windows-msvc/llvm/include/llvm/Config/llvm-config.h
-- Installing: D:/git/ferrocene/ferrocene/build/x86_64-pc-windows-msvc/llvm/include/llvm/Support/VCSRevision.h
-- Installing: D:/git/ferrocene/ferrocene/build/x86_64-pc-windows-msvc/llvm/lib/cmake/llvm/LLVMConfigExtensions.cmake

cargo:root=D:\git\ferrocene\ferrocene\build\x86_64-pc-windows-msvc\llvm
        finished in 1242.431 seconds
Building crtbegin.o and crtend.o for x86_64-pc-windows-msvc



cargo:warning=cl : Command line warning D9002 : ignoring unknown option '-std=c11'
crtbegin.c
D:\git\ferrocene\ferrocene\src/llvm-project/compiler-rt/lib/builtins/crtbegin.c(9): fatal error C1034: stddef.h: no include path set


error occurred: Command "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-O2" "-Brepro" "-std=c11" "-DCRT_HAS_INITFINI_ARRAY" "-DEH_USE_FRAME_REGISTRY" "-FoD:\\git\\ferrocene\\ferrocene\\build\\x86_64-pc-windows-msvc\\native\\crt\\89a91fa0b39682bb-crtbegin.o" "-c" "D:\\git\\ferrocene\\ferrocene\\src/llvm-project/compiler-rt/lib/builtins/crtbegin.c" with args cl.exe did not execute successfully (status code exit code: 2).


Build completed unsuccessfully in 0:39:09

Bootstrap configuration (config.toml)

The same as the config.example.toml but:

[llvm]
download-ci-llvm = false

Operating system

This is happening on, as far as I know, all Windows and Mac targets. I tested on Mac 15.2 and Windows 11 24H2.

HEAD

bcd0683 and 6a64e3b both display the issue

Additional context

After discussing with @japaric, I believe that these steps (building crtbegin.o and crtend.o) are unnecessary, bootstrap seems to claim that these steps are for cross compiling to MUSL.

We believe the issue happened sometime between #134839 (where the problem is not present) and #134987 (where the problem is now present)

(Build logs excluded as they are longer than the Github Issues limit)

windows-log.txt

mac-log.txt

@Hoverbear Hoverbear added C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jan 20, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 20, 2025
@onur-ozkan onur-ozkan added O-windows Operating system: Windows O-macos Operating system: macOS and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 20, 2025
@onur-ozkan
Copy link
Member

#132994 might be related.

@jieyouxu jieyouxu added E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc E-needs-investigation Call for partcipation: This issues needs some investigation to determine current status labels Jan 21, 2025
@japaric
Copy link
Member

japaric commented Jan 21, 2025

my observations so far

some recent change in bootstrap made it such that ./x build src/llvm-project now includes the CrtBeginEnd step (which is mapped to path src/llvm-project/compiler-rt/lib/crt). I don't think this change is wrong.

./x build src/llvm-project/compiler-rt/lib/crt will try to compile the CRT objects to the host triple. Those objects are meant to be cross compiled to MUSL as you can see in copy_self_contained_objects where the CrtBeginEnd build is guarded by a target.contains("musl") check. I think this is the part of the logic that's wrong.

I don't think the cc update is the problem because ./x build src/llvm-project/compiler-rt/lib/crt will configure cc::Build to compile to the host triple which then uses the wrong compiler (cl.exe on Windows and a machO-default gcc on macOS). Case in point, that ./x build src/llvm-project/compiler-rt/lib/crt command also tries to do native compilation (+) on revision 6e1c115 which does not include cc update PR

In conclusion, I think ./x build src/llvm-project/compiler-rt/lib/crt has been broken since a while ago and only now that has surfaced in ./x build src/llvm-project because of recent changes. I think that to fix this CrtBeginEnd::make_run should skip the actual build (CrtBeginEnd::run) if the target is not MUSL to match the logic in copy_self_contained_objects.

(+) I should mention that I only have a Linux box around so I can't actually repro the problem seen on macOS and Windows but if I add an assertion like assert!(self.target.triple.contains("musl")) to CrtBeginEnd::run then I can see the panic. self.target.triple is passed to cc::Build in that function and it's set to x86_64-linux (the host triple) when I run ./x build src/llvm-project/compiler-rt/lib/crt.

@Hoverbear
Copy link
Contributor Author

@japaric asked me to repro the issue on Mac from checkout 6e1c11591fc7e98015f8e793a15c8faf0bda67f1. Here is the output of ./x build src/llvm-project/compiler-rt/lib/crt :

Submodule path 'src/llvm-project': checked out '104d0d16c3c7c3fef2435fef6efb2d57b70fff73'
downloading https://static.rust-lang.org/dist/2024-10-16/rustfmt-nightly-aarch64-apple-darwin.tar.xz
################################################################################################################################################################# 100.0%
extracting /Users/ana/git/rust-lang/rust/build/cache/2024-10-16/rustfmt-nightly-aarch64-apple-darwin.tar.xz to /Users/ana/git/rust-lang/rust/build/aarch64-apple-darwin/rustfmt
downloading https://static.rust-lang.org/dist/2024-10-16/rustc-nightly-aarch64-apple-darwin.tar.xz
################################################################################################################################################################# 100.0%
extracting /Users/ana/git/rust-lang/rust/build/cache/2024-10-16/rustc-nightly-aarch64-apple-darwin.tar.xz to /Users/ana/git/rust-lang/rust/build/aarch64-apple-darwin/rustfmt
Building crtbegin.o and crtend.o for aarch64-apple-darwin
cargo:warning=/Users/ana/git/rust-lang/rust/src/llvm-project/compiler-rt/lib/builtins/crtbegin.c:15:28: error: argument to 'section' attribute is not valid for this target: mach-o section specifier requires a segment and section separated by a comma
cargo:warning=   15 |     __attribute__((section(".eh_frame"), aligned(sizeof(void *)))) = {};
cargo:warning=      |                            ^
cargo:warning=/Users/ana/git/rust-lang/rust/src/llvm-project/compiler-rt/lib/builtins/crtbegin.c:49:24: error: argument to 'section' attribute is not valid for this target: mach-o section specifier requires a segment and section separated by a comma
cargo:warning=   49 | __attribute__((section(".init_array"),
cargo:warning=      |                        ^
cargo:warning=/Users/ana/git/rust-lang/rust/src/llvm-project/compiler-rt/lib/builtins/crtbegin.c:106:24: error: argument to 'section' attribute is not valid for this target: mach-o section specifier requires a segment and section separated by a comma
cargo:warning=  106 | __attribute__((section(".fini_array"),
cargo:warning=      |                        ^
cargo:warning=3 errors generated.


error occurred: Command env -u IPHONEOS_DEPLOYMENT_TARGET "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=arm64-apple-darwin" "-mmacosx-version-min=15.2" "-std=c11" "-DCRT_HAS_INITFINI_ARRAY" "-DEH_USE_FRAME_REGISTRY" "-o" "/Users/ana/git/rust-lang/rust/build/aarch64-apple-darwin/native/crt/201e8d6b412081ae-crtbegin.o" "-c" "/Users/ana/git/rust-lang/rust/src/llvm-project/compiler-rt/lib/builtins/crtbegin.c" with args cc did not execute successfully (status code exit status: 1).


Build completed unsuccessfully in 0:01:13
Took 1min 14sec 350ms

japaric added a commit to ferrocene/rust that referenced this issue Jan 21, 2025
japaric added a commit to ferrocene/rust that referenced this issue Jan 21, 2025
only MUSL needs those objects and trying to compile them to other
targets, e.g. Windows or macOS, will produce C compilation errors

check the target before shelling out to the C compiler and tweak
`make_run` to skip the actual C compilation when the target is not MUSL

fixes rust-lang#135782
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-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc E-needs-investigation Call for partcipation: This issues needs some investigation to determine current status O-macos Operating system: macOS O-windows Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants