[llvm] [ELFDumper] Always read AMD Code Object notes as little-endian (PR #70775)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 00:09:04 PDT 2023
https://github.com/Pierre-vh created https://github.com/llvm/llvm-project/pull/70775
Avoids issues on big-endian hosts.
Note that we use aligned types because primitive integers are also aligned. If we don't use aligned types, `HSAILProperties` ends up being 11 bytes instead of 12 (1 byte padding at the end of the struct added by the compiler).
Technically only the first type needs to be aligned, but I just used aligned types everywhere to be consistent.
Fixes #65280
>From 953c24630351064400fd7864c4f6fbf169bcdb39 Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Mon, 30 Oct 2023 14:22:14 +0100
Subject: [PATCH] [ELFDumper] Always read AMD Code Object notes as
little-endian
Avoids issues on big-endian hosts.
Fixes #65280
---
llvm/tools/llvm-readobj/ELFDumper.cpp | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 658c651add3b922..34e31e05cd8527f 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -5451,8 +5451,8 @@ static AMDNote getAMDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
return {"", ""};
case ELF::NT_AMD_HSA_CODE_OBJECT_VERSION: {
struct CodeObjectVersion {
- uint32_t MajorVersion;
- uint32_t MinorVersion;
+ support::aligned_ulittle32_t MajorVersion;
+ support::aligned_ulittle32_t MinorVersion;
};
if (Desc.size() != sizeof(CodeObjectVersion))
return {"AMD HSA Code Object Version",
@@ -5466,8 +5466,8 @@ static AMDNote getAMDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
}
case ELF::NT_AMD_HSA_HSAIL: {
struct HSAILProperties {
- uint32_t HSAILMajorVersion;
- uint32_t HSAILMinorVersion;
+ support::aligned_ulittle32_t HSAILMajorVersion;
+ support::aligned_ulittle32_t HSAILMinorVersion;
uint8_t Profile;
uint8_t MachineModel;
uint8_t DefaultFloatRound;
@@ -5487,11 +5487,11 @@ static AMDNote getAMDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
}
case ELF::NT_AMD_HSA_ISA_VERSION: {
struct IsaVersion {
- uint16_t VendorNameSize;
- uint16_t ArchitectureNameSize;
- uint32_t Major;
- uint32_t Minor;
- uint32_t Stepping;
+ support::aligned_ulittle16_t VendorNameSize;
+ support::aligned_ulittle16_t ArchitectureNameSize;
+ support::aligned_ulittle32_t Major;
+ support::aligned_ulittle32_t Minor;
+ support::aligned_ulittle32_t Stepping;
};
if (Desc.size() < sizeof(IsaVersion))
return {"AMD HSA ISA Version", "Invalid AMD HSA ISA Version"};
@@ -5527,8 +5527,8 @@ static AMDNote getAMDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
}
case ELF::NT_AMD_PAL_METADATA: {
struct PALMetadata {
- uint32_t Key;
- uint32_t Value;
+ support::aligned_ulittle32_t Key;
+ support::aligned_ulittle32_t Value;
};
if (Desc.size() % sizeof(PALMetadata) != 0)
return {"AMD PAL Metadata", "Invalid AMD PAL Metadata"};
More information about the llvm-commits
mailing list