diff options
| author | Joseph Huber <huberjn@outlook.com> | 2024-01-05 10:24:30 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-05 10:24:30 -0600 |
| commit | 3b337bbc811002d088d3ae6fcae869a8d5682bc1 (patch) | |
| tree | 260bc7345b8946d8dcec4337283d36cb87c744fa /llvm/lib/Object/ObjectFile.cpp | |
| parent | 5352ce32fccd37c54aff2b3a2b0e3ca5115bb8a9 (diff) | |
[ELF] Attempt to set the OS when using 'makeTriple()' (#76992)
Summary:
This patch fixes up the `makeTriple()` interface to emit append the
operating system information when it is readily avaialble from the ELF.
The main motivation for this is so the GPU architectures can be easily
identified correctly when given and ELF. E.g. we want
`amdgpu-amd-amdhsa` as the output and not `amdgpu--`.
This required adding support for the CUDA OS/ABI, which is easily found
to be `0x33` when using `readelf`.
Diffstat (limited to 'llvm/lib/Object/ObjectFile.cpp')
| -rw-r--r-- | llvm/lib/Object/ObjectFile.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp index ca921836b7f6..c05eb0a0468e 100644 --- a/llvm/lib/Object/ObjectFile.cpp +++ b/llvm/lib/Object/ObjectFile.cpp @@ -111,6 +111,10 @@ Triple ObjectFile::makeTriple() const { auto Arch = getArch(); TheTriple.setArch(Triple::ArchType(Arch)); + auto OS = getOS(); + if (OS != Triple::UnknownOS) + TheTriple.setOS(OS); + // For ARM targets, try to use the build attributes to build determine // the build target. Target features are also added, but later during // disassembly. @@ -129,10 +133,13 @@ Triple ObjectFile::makeTriple() const { // XCOFF implies AIX. TheTriple.setOS(Triple::AIX); TheTriple.setObjectFormat(Triple::XCOFF); - } - else if (isGOFF()) { + } else if (isGOFF()) { TheTriple.setOS(Triple::ZOS); TheTriple.setObjectFormat(Triple::GOFF); + } else if (TheTriple.isAMDGPU()) { + TheTriple.setVendor(Triple::AMD); + } else if (TheTriple.isNVPTX()) { + TheTriple.setVendor(Triple::NVIDIA); } return TheTriple; |
