Skip to content

Conversation

@nicholasbishop
Copy link
Contributor

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.

Fix by not using int_util.c if target_os == uefi.

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

`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.

Fix by not using `int_util.c` if `target_os == uefi`.
@Amanieu
Copy link
Member

Amanieu commented Nov 16, 2022

Are you sure this actually works? This file defines __compilerrt_abort_impl which is used by many other files in compiler-rt. Could we fix the clang target instead so it doesn't define _WIN32?

@nicholasbishop
Copy link
Contributor Author

Are you sure this actually works? This file defines __compilerrt_abort_impl which is used by many other files in compiler-rt.

Ah, you're right. I didn't see an error but it's just that my test case didn't call anything that depends on that function.

Could we fix the clang target instead so it doesn't define _WIN32

That target we're passing into clang is x86_64-unknown-windows-gnu (or similar for the other UEFI targets), so it's not doing anything wrong by defining _WIN32. The best long-term solution would probably be to add real UEFI targets to clang. For now, maybe it would be best to just add UEFI to the list of targets that shouldn't use the C code?

@nicholasbishop
Copy link
Contributor Author

Closing in favor of #506

@nicholasbishop nicholasbishop deleted the bishop-no-int-util-uefi branch November 16, 2022 23:09
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