[clang] a4d8549 - [HIP] fix stack marking for -fgpu-rdc (#72782)

via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 1 13:22:22 PST 2023


Author: Yaxun (Sam) Liu
Date: 2023-12-01T16:22:16-05:00
New Revision: a4d85490e029e797d22881b37d476c2050d0d6a2

URL: https://github.com/llvm/llvm-project/commit/a4d85490e029e797d22881b37d476c2050d0d6a2
DIFF: https://github.com/llvm/llvm-project/commit/a4d85490e029e797d22881b37d476c2050d0d6a2.diff

LOG: [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: https://github.com/llvm/llvm-project/issues/71711

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/HIPUtility.cpp
    clang/test/Driver/hip-toolchain-rdc.hip

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 04efdcba20ea740..f692458b775de2b 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -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.

diff  --git a/clang/test/Driver/hip-toolchain-rdc.hip b/clang/test/Driver/hip-toolchain-rdc.hip
index fa30bb8a9f5f576..1827531f9cab7a3 100644
--- a/clang/test/Driver/hip-toolchain-rdc.hip
+++ b/clang/test/Driver/hip-toolchain-rdc.hip
@@ -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-[^"]+"]]


        


More information about the cfe-commits mailing list