Skip to content

Commit a4d8549

Browse files
authored
[HIP] fix stack marking for -fgpu-rdc (#72782)
HIP toolchain uses llvm-mc to generate a host object embedding device binary for -fgpu-rdc. Due to lack of .note.GNU-stack section, the generated relocatable has executable stack marking, which disables protection from executable stack for any HIP programs compiled with -fgpu-rdc. This patch adds .note.GNU-stack section to the input to llvm-mc to fix the executable stack marking. Fixes: #71711
1 parent ed22bf6 commit a4d8549

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

clang/lib/Driver/ToolChains/HIPUtility.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ void HIP::constructGenerateObjFileFromHIPFatBinary(
150150
ObjStream << " .incbin ";
151151
llvm::sys::printArg(ObjStream, BundleFile, /*Quote=*/true);
152152
ObjStream << "\n";
153+
if (HostTriple.isOSLinux() && HostTriple.isOSBinFormatELF())
154+
ObjStream << " .section .note.GNU-stack, \"\", @progbits\n";
153155
ObjStream.flush();
154156

155157
// Dump the contents of the temp object file gen if the user requested that.

clang/test/Driver/hip-toolchain-rdc.hip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
// CHECK: .p2align 12
3333
// CHECK: __hip_fatbin:
3434
// CHECK: .incbin "[[BUNDLE:.*hipfb]]"
35+
// LNX: .section .note.GNU-stack, "", @progbits
36+
// MSVC-NOT: .note.GNU-stack
3537

3638
// emit objects for host side path
3739
// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" [[HOST:"x86_64-[^"]+"]]

0 commit comments

Comments
 (0)