From e4a9e4ef554a90637c53d4f10326c262df69b76c Mon Sep 17 00:00:00 2001 From: Scott Linder Date: Mon, 5 Oct 2020 22:45:35 +0000 Subject: [PATCH] [AMDGPU] Emit correct kernel descriptor on big-endian hosts Previously we wrote multi-byte values out as-is from host memory. Use the `emitIntN` helpers in `MCStreamer` to produce a valid descriptor irrespective of the host endianness. Reviewed By: arsenm, rochauha Differential Revision: https://reviews.llvm.org/D88858 --- .../AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp | 22 ++++++++++++---------- llvm/test/MC/AMDGPU/hsa-sgpr-init-bug-v3.s | 3 --- llvm/test/MC/AMDGPU/hsa-v3.s | 3 --- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp index 344f22d..9d662ec 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp @@ -656,9 +656,10 @@ void AMDGPUTargetELFStreamer::EmitAmdhsaKernelDescriptor( KernelCodeSymbol->setVisibility(ELF::STV_PROTECTED); Streamer.emitLabel(KernelDescriptorSymbol); - Streamer.emitBytes(StringRef( - (const char*)&(KernelDescriptor), - offsetof(amdhsa::kernel_descriptor_t, kernel_code_entry_byte_offset))); + Streamer.emitInt32(KernelDescriptor.group_segment_fixed_size); + Streamer.emitInt32(KernelDescriptor.private_segment_fixed_size); + for (uint8_t Res : KernelDescriptor.reserved0) + Streamer.emitInt8(Res); // FIXME: Remove the use of VK_AMDGPU_REL64 in the expression below. The // expression being created is: // (start of kernel code) - (start of kernel descriptor) @@ -670,11 +671,12 @@ void AMDGPUTargetELFStreamer::EmitAmdhsaKernelDescriptor( KernelDescriptorSymbol, MCSymbolRefExpr::VK_None, Context), Context), sizeof(KernelDescriptor.kernel_code_entry_byte_offset)); - Streamer.emitBytes(StringRef( - (const char*)&(KernelDescriptor) + - offsetof(amdhsa::kernel_descriptor_t, kernel_code_entry_byte_offset) + - sizeof(KernelDescriptor.kernel_code_entry_byte_offset), - sizeof(KernelDescriptor) - - offsetof(amdhsa::kernel_descriptor_t, kernel_code_entry_byte_offset) - - sizeof(KernelDescriptor.kernel_code_entry_byte_offset))); + for (uint8_t Res : KernelDescriptor.reserved1) + Streamer.emitInt8(Res); + Streamer.emitInt32(KernelDescriptor.compute_pgm_rsrc3); + Streamer.emitInt32(KernelDescriptor.compute_pgm_rsrc1); + Streamer.emitInt32(KernelDescriptor.compute_pgm_rsrc2); + Streamer.emitInt16(KernelDescriptor.kernel_code_properties); + for (uint8_t Res : KernelDescriptor.reserved2) + Streamer.emitInt8(Res); } diff --git a/llvm/test/MC/AMDGPU/hsa-sgpr-init-bug-v3.s b/llvm/test/MC/AMDGPU/hsa-sgpr-init-bug-v3.s index 644d957..35237c4 100644 --- a/llvm/test/MC/AMDGPU/hsa-sgpr-init-bug-v3.s +++ b/llvm/test/MC/AMDGPU/hsa-sgpr-init-bug-v3.s @@ -1,9 +1,6 @@ // RUN: llvm-mc -mattr=+code-object-v3 -triple amdgcn-amd-amdhsa -mcpu=gfx802 -filetype=obj < %s > %t // RUN: llvm-objdump -s -j .rodata %t | FileCheck --check-prefix=OBJDUMP %s -// big endian not supported -// XFAIL: host-byteorder-big-endian - // Check that SGPR init bug on gfx803 is corrected by the assembler, setting // GRANULATED_WAVEFRONT_SGPR_COUNT to 11. diff --git a/llvm/test/MC/AMDGPU/hsa-v3.s b/llvm/test/MC/AMDGPU/hsa-v3.s index 3c2ddec..a995b1b 100644 --- a/llvm/test/MC/AMDGPU/hsa-v3.s +++ b/llvm/test/MC/AMDGPU/hsa-v3.s @@ -3,9 +3,6 @@ // RUN: llvm-readelf -sections -symbols -relocations %t | FileCheck --check-prefix=READOBJ %s // RUN: llvm-objdump -s -j .rodata %t | FileCheck --check-prefix=OBJDUMP %s -// big endian not supported -// XFAIL: host-byteorder-big-endian - // READOBJ: Section Headers // READOBJ: .text PROGBITS {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9]+}} AX {{[0-9]+}} {{[0-9]+}} 256 // READOBJ: .rodata PROGBITS {{[0-9a-f]+}} {{[0-9a-f]+}} 000100 {{[0-9]+}} A {{[0-9]+}} {{[0-9]+}} 64 -- 2.7.4