Repository: rust
Issue: LLVM build failures on Windows/Mac
Labels: O-windows,O-macos,T-bootstrap,C-bug,E-needs-bisection,E-needs-investigation

<!--
Thank you for submitting a bootstrap report! Please provide detailed information to help us reproduce and diagnose the issue.
-->

### 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:

```toml
[llvm]
download-ci-llvm = false
```

Then run:


```sh
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:

```toml
[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

bcd0683e5dce1945b5d940714742e7502883bb5c and 6a64e3b89724395d87a394ed9ebd954c474b080a 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) 


<!--
Include the complete build log in the section below.
Enable backtrace and verbose mode if possible for more detailed information e.g., with `RUST_BACKTRACE=1 ./x build -v`.
-->
(Build logs excluded as they are longer than the Github Issues limit)

[windows-log.txt](https://github.com/user-attachments/files/18480761/windows-log.txt)

[mac-log.txt](https://github.com/user-attachments/files/18480762/mac-log.txt)