Skip to content

Conversation

@nicholasbishop
Copy link
Contributor

@nicholasbishop nicholasbishop commented Nov 16, 2022

int_util.c includes stdlib.h if _WIN32 is defined. When compiling the UEFI targets with clang they are treated as Windows targets (e.g. if the Rust target is x86_64-unknown-uefi, the clang target is x86_64-unknown-windows-gnu). So stdlib.h gets included, even though we are compilling with -ffreestanding and don't want stdlib.h to be used. That file may not be present, or an incompatible version might be installed leading to typedef redefinition errors.

The contents of stdlib.h aren't actually needed for these targets anyway (due to __STDC_HOSTED__ being 0), so create an empty stdlib.h in build.rs when target_os == uefi and add it to the include path.

This is a partial fix for rust-lang/rust#104326.

@Amanieu
Copy link
Member

Amanieu commented Nov 18, 2022

The freestanding part of stdlib.h is stddef.h, so it would be better to have a single #include <stddef.h> in the dummy stdlib.h. Although it doesn't matter here, this should be more robust against future changes of compiler-rt.

int_util.c includes stdlib.h if `_WIN32` is defined. When compiling
the UEFI targets with clang they are treated as Windows targets (e.g. if
the Rust target is x86_64-unknown-uefi, the clang target is
x86_64-unknown-windows-gnu). So stdlib.h gets included, even though we
are compilling with `-ffreestanding` and don't want stdlib.h to be
used. That file may not be present, or an incompatible version might be
installed leading to typedef redefinition errors.

The contents of stdlib.h aren't actually needed for these targets anyway
(due to `__STDC_HOSTED__` being 0), so create a minimal stdlib.h in
`build.rs` when `target_os == uefi` and add it to the include path.
@nicholasbishop
Copy link
Contributor Author

Updated the stub header to add the include as suggested.

@Amanieu Amanieu merged commit b1472e7 into rust-lang:master Nov 18, 2022
@nicholasbishop nicholasbishop deleted the bishop-fix-stdlib-inc branch November 18, 2022 02:59
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.

2 participants