Skip to content

Commit

Permalink
[HIP] fix stack marking for -fgpu-rdc (#72782)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yxsamliu committed Dec 1, 2023
1 parent ed22bf6 commit a4d8549
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/HIPUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ void HIP::constructGenerateObjFileFromHIPFatBinary(
ObjStream << " .incbin ";
llvm::sys::printArg(ObjStream, BundleFile, /*Quote=*/true);
ObjStream << "\n";
if (HostTriple.isOSLinux() && HostTriple.isOSBinFormatELF())
ObjStream << " .section .note.GNU-stack, \"\", @progbits\n";
ObjStream.flush();

// Dump the contents of the temp object file gen if the user requested that.
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/hip-toolchain-rdc.hip
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
// CHECK: .p2align 12
// CHECK: __hip_fatbin:
// CHECK: .incbin "[[BUNDLE:.*hipfb]]"
// LNX: .section .note.GNU-stack, "", @progbits
// MSVC-NOT: .note.GNU-stack

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

0 comments on commit a4d8549

Please sign in to comment.