Skip to content

Commit d3876c5

Browse files
authored
[ELFDumper] Always read AMD Code Object notes as little-endian (#70775)
Should avoid 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
1 parent acdf7c8 commit d3876c5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

llvm/tools/llvm-readobj/ELFDumper.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -5450,8 +5450,8 @@ static AMDNote getAMDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
54505450
return {"", ""};
54515451
case ELF::NT_AMD_HSA_CODE_OBJECT_VERSION: {
54525452
struct CodeObjectVersion {
5453-
uint32_t MajorVersion;
5454-
uint32_t MinorVersion;
5453+
support::aligned_ulittle32_t MajorVersion;
5454+
support::aligned_ulittle32_t MinorVersion;
54555455
};
54565456
if (Desc.size() != sizeof(CodeObjectVersion))
54575457
return {"AMD HSA Code Object Version",
@@ -5465,8 +5465,8 @@ static AMDNote getAMDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
54655465
}
54665466
case ELF::NT_AMD_HSA_HSAIL: {
54675467
struct HSAILProperties {
5468-
uint32_t HSAILMajorVersion;
5469-
uint32_t HSAILMinorVersion;
5468+
support::aligned_ulittle32_t HSAILMajorVersion;
5469+
support::aligned_ulittle32_t HSAILMinorVersion;
54705470
uint8_t Profile;
54715471
uint8_t MachineModel;
54725472
uint8_t DefaultFloatRound;
@@ -5486,11 +5486,11 @@ static AMDNote getAMDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
54865486
}
54875487
case ELF::NT_AMD_HSA_ISA_VERSION: {
54885488
struct IsaVersion {
5489-
uint16_t VendorNameSize;
5490-
uint16_t ArchitectureNameSize;
5491-
uint32_t Major;
5492-
uint32_t Minor;
5493-
uint32_t Stepping;
5489+
support::aligned_ulittle16_t VendorNameSize;
5490+
support::aligned_ulittle16_t ArchitectureNameSize;
5491+
support::aligned_ulittle32_t Major;
5492+
support::aligned_ulittle32_t Minor;
5493+
support::aligned_ulittle32_t Stepping;
54945494
};
54955495
if (Desc.size() < sizeof(IsaVersion))
54965496
return {"AMD HSA ISA Version", "Invalid AMD HSA ISA Version"};
@@ -5526,8 +5526,8 @@ static AMDNote getAMDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
55265526
}
55275527
case ELF::NT_AMD_PAL_METADATA: {
55285528
struct PALMetadata {
5529-
uint32_t Key;
5530-
uint32_t Value;
5529+
support::aligned_ulittle32_t Key;
5530+
support::aligned_ulittle32_t Value;
55315531
};
55325532
if (Desc.size() % sizeof(PALMetadata) != 0)
55335533
return {"AMD PAL Metadata", "Invalid AMD PAL Metadata"};

0 commit comments

Comments
 (0)