-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[clang] fix uefi target for aarch64 & x86_64 #120632
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
base: main
Are you sure you want to change the base?
Changes from all commits
e0d525f
6d242b0
dfcd456
3177fc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -722,8 +722,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { | |
X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) | ||
: X86TargetInfo(Triple, Opts) { | ||
const bool IsX32 = getTriple().isX32(); | ||
bool IsWinCOFF = | ||
getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); | ||
bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && | ||
getTriple().isOSBinFormatCOFF(); | ||
LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While debugging some of our EFI workloads noticed that the integer type definitions set here are not correct for UEFI X86_64. I have a local patch which overrides the values set here to fix the problem. I am simplifying the code and pasting it here:
I am starting lean towards retaining the UEFIX86_64TargetInfo to not "pollute" the X86_64TargetInfo with too many conditional overrides for UEFI. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, doesn't sound right that the various types and stuff aren't right for x86. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that some of these are things we'll eventually want command-line switch flexibility for. Matching Windows all around is the right default. But structurally, keep in mind that these are no things intrinsic to the UEFI target per se but to a particular set of C/C++ API expectations that future users (i.e. me) will want to have the option of configuring to be consistent with other norms rather than Windows norms. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @frobtech Yeah, that's kinda why I am unsure of the changes suggested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here AFAICT It seems to be called IMHO it would be wisest not to go around making lots of things write out Just in this same file there are other local variables called |
||
LongDoubleWidth = 128; | ||
LongDoubleAlign = 128; | ||
|
@@ -829,38 +829,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { | |
} | ||
}; | ||
|
||
// x86-64 UEFI target | ||
class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo | ||
: public UEFITargetInfo<X86_64TargetInfo> { | ||
public: | ||
UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) | ||
: UEFITargetInfo<X86_64TargetInfo>(Triple, Opts) { | ||
this->TheCXXABI.set(TargetCXXABI::Microsoft); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guessing we don't need this or the CC check code below? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, verify that the behavior before and after this is the same to be on the safe side. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what the behavior even is. Looking at the UEFI spec, it doesn't mention C++ ABI stuff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though I couldn't find it in the actual UEFI spec, Microsoft CXX ABI seems to be the norm for EFI. EDK2 toolchain if I am not mistaken assumes Microsoft ABI so is the existing target triples in Clang (e.g. X86_64-windows-msvc) also set the ABI to Microsoft. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UEFI has nothing to say about C++. It is an ABI spec that is described in terms of C. It says nothing about what code not directly interacting with UEFI ABIs might do. That said, heretofore the only way to compile code directly for the UEFI ABI is to use the Windows target. Thus, the expectations for existing source code that targets UEFI directly via Clang is to get all the ABI and API details of whatever language as the Windows target does them (except of course for the actual OS-specific aspects per se). So for all "ABI choice" things, the sensible default for UEFI target on $ARCH is what the Windows target for $ARCH does. This goes for what type long is, what C++ ABI to use, alignment quirks, etc. It also goes for language API details/extensions that are not directly related to Windows per se, such as the various pragmas for PECOFF-specific features or Windows spellings of generic extensions (e.g. Once we have the UEFI targets on their feet, we'll want to look into offering flexibility to make non-default choices (i.e. choices different from Windows) for various ABI and API things. But we can get to that later. |
||
this->MaxTLSAlign = 8192u * this->getCharWidth(); | ||
this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" | ||
"i64:64-i128:128-f80:128-n8:16:32:64-S128"); | ||
} | ||
|
||
BuiltinVaListKind getBuiltinVaListKind() const override { | ||
return TargetInfo::CharPtrBuiltinVaList; | ||
} | ||
|
||
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { | ||
switch (CC) { | ||
case CC_C: | ||
case CC_Win64: | ||
return CCCR_OK; | ||
default: | ||
return CCCR_Warning; | ||
} | ||
} | ||
|
||
TargetInfo::CallingConvKind | ||
getCallingConvKind(bool ClangABICompat4) const override { | ||
return CCK_MicrosoftWin64; | ||
} | ||
}; | ||
|
||
// x86-64 Windows target | ||
class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo | ||
: public WindowsTargetInfo<X86_64TargetInfo> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This could simply be
getTriple().isUEFI() || (getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF()) as isOSBinFormatCOFF will always be true for UEFI.