[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: dpkg-buildflags: add HIPFLAGS to supported flags



Hello,

I've attached a patch with first rough attempt at specifying which flags apply to HIPFLAGS. I have not tested this patch, but I have tested the flags themselves. I'm trying to set all CXXFLAGS as HIPFLAGS except -Werror=clobbered and all the LTO flags. I've also prepended -Xarch_host to all fsanitize flags [1], -fstack-protector-strong, and -fcf-protection.

Sincerely,
Cory Bloor

[1]: The -fsanitize=address flag works for some GPU targets, but it's not clear to me how to limit it to supported GPU targets when dpkg doesn't know what GPU targets are to be built. For this reason, I'm limiting this flag to the host.
From e254584f72023c762880aa334b828650c37b932a Mon Sep 17 00:00:00 2001
From: Cordell Bloor <cgmb@debian.org>
Date: Sun, 27 Jul 2025 22:19:14 +0000
Subject: [PATCH] Dpkg::Vendor::Debian: Add HIPFLAGS

Add support for the HIP language. Most HIPFLAGS are the same as
CXXFLAGS, but a few need to be guarded with -Xarch_host so that they
are not applied to device code.
---
 scripts/Dpkg/Vendor/Debian.pm | 38 ++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/scripts/Dpkg/Vendor/Debian.pm b/scripts/Dpkg/Vendor/Debian.pm
index 8aaa178cc..8e570c236 100644
--- a/scripts/Dpkg/Vendor/Debian.pm
+++ b/scripts/Dpkg/Vendor/Debian.pm
@@ -451,6 +451,7 @@ sub add_build_flags {
         OBJCXXFLAGS
         FFLAGS
         FCFLAGS
+        HIPFLAGS
     );
 
     my $default_flags;
@@ -499,13 +500,21 @@ sub add_build_flags {
     if ($flags->use_feature('qa', 'bug')) {
         # C/C++ flags
         my @cfamilyflags = qw(
-            array-bounds
             clobbered
+        );
+        foreach my $warnflag (@cfamilyflags) {
+            $flags->append('CFLAGS', "-Werror=$warnflag");
+            $flags->append('CXXFLAGS', "-Werror=$warnflag");
+        }
+        # C/C++/HIP flags
+        my @cfamilyflags = qw(
+            array-bounds
             volatile-register-var
         );
         foreach my $warnflag (@cfamilyflags) {
             $flags->append('CFLAGS', "-Werror=$warnflag");
             $flags->append('CXXFLAGS', "-Werror=$warnflag");
+            $flags->append('HIPFLAGS', "-Werror=$warnflag");
         }
     }
 
@@ -514,7 +523,7 @@ sub add_build_flags {
         require Digest::MD5;
         my $id = Digest::MD5::md5_hex(int rand 4096);
 
-        foreach my $flag (qw(CPPFLAGS CFLAGS OBJCFLAGS CXXFLAGS OBJCXXFLAGS)) {
+        foreach my $flag (qw(CPPFLAGS CFLAGS OBJCFLAGS CXXFLAGS OBJCXXFLAGS HIPFLAGS)) {
             $flags->append($flag, "-D__DEB_CANARY_${flag}_${id}__");
         }
         $flags->append('LDFLAGS', "-Wl,-z,deb-canary-${id}");
@@ -548,7 +557,10 @@ sub add_build_flags {
 
     if ($flags->use_feature('optimize', 'lto')) {
         my $flag = '-flto=auto -ffat-lto-objects';
-        $flags->append($_, $flag) foreach (@compile_flags, 'LDFLAGS');
+        foreach my $flagvar (@compile_flags, 'LDFLAGS') {
+            next if($flagvar == 'HIPFLAGS');
+            $flags->append($flagvar, $flag);
+        }
     }
 
     ## Area: sanitize
@@ -557,6 +569,7 @@ sub add_build_flags {
         my $flag = '-fsanitize=address -fno-omit-frame-pointer';
         $flags->append('CFLAGS', $flag);
         $flags->append('CXXFLAGS', $flag);
+        $flags->append('HIPFLAGS','-Xarch_host -fsanitize=address -Xarch_host -fno-omit-frame-pointer');
         $flags->append('LDFLAGS', '-fsanitize=address');
     }
 
@@ -564,6 +577,7 @@ sub add_build_flags {
         my $flag = '-fsanitize=thread';
         $flags->append('CFLAGS', $flag);
         $flags->append('CXXFLAGS', $flag);
+        $flags->append('HIPFLAGS', "-Xarch_host $flag");
         $flags->append('LDFLAGS', $flag);
     }
 
@@ -575,6 +589,7 @@ sub add_build_flags {
         my $flag = '-fsanitize=undefined';
         $flags->append('CFLAGS', $flag);
         $flags->append('CXXFLAGS', $flag);
+        $flags->append('HIPFLAGS', "-Xarch_host $flag");
         $flags->append('LDFLAGS', $flag);
     }
 
@@ -596,7 +611,13 @@ sub add_build_flags {
     # Stack protector
     if ($flags->use_feature('hardening', 'stackprotectorstrong')) {
 	my $flag = '-fstack-protector-strong';
-        $flags->append($_, $flag) foreach @compile_flags;
+        foreach my $flagvar (@compile_flags) {
+            if($flagvar == 'HIPFLAGS') {
+                 $flags->append($flagvar, "-Xarch_host $flag");
+            } else {
+                $flags->append($flagvar, $flag);
+            }
+        }
     } elsif ($flags->use_feature('hardening', 'stackprotector')) {
 	my $flag = '-fstack-protector --param=ssp-buffer-size=4';
         $flags->append($_, $flag) foreach @compile_flags;
@@ -621,6 +642,7 @@ sub add_build_flags {
 	$flags->append('CXXFLAGS', $flag);
 	$flags->append('OBJCFLAGS', $flag);
 	$flags->append('OBJCXXFLAGS', $flag);
+	$flags->append('HIPFLAGS', $flag);
     }
 
     # Read-only Relocations
@@ -645,7 +667,13 @@ sub add_build_flags {
         # The following should always be true on Debian, but it might not
         # be on derivatives.
         if (defined $flag) {
-            $flags->append($_, $flag) foreach @compile_flags;
+            foreach my $flagvar (@compile_flags) {
+                if($flagvar == 'HIPFLAGS') {
+                    $flags->append($flagvar, "-Xarch_host $flag");
+		} else {
+                    $flags->append($flagvar, $flag);
+		}
+            }
         }
     }
 
-- 
2.50.0


Reply to: