The hipcc script takes arguments and uses this to build up a new
command. Characters which are special to the shell need to be quoted
to prevent them being interpreted.

In particular adding
     --Wl,--enable-new-dtags -Wl,--rpath,'$ORIGIN:$ORIGIN/../lib'
to the command should pass quoted dollar signs into the resulting
string so the shell passes them on, rather than substituting the
values.

The arguments are processed in a conventional loop, but can be altered
during the course of the loop, and also by linker response files.

Tested by running
  HIPCC_VERBOSE=7 HIP_COMPILER=clang hipcc --cxxflags \
      fred.c -Wl,,--rpath,'$ORIGIN:$ORIGIN:/../lib'
and observing "-Wl,--rpath,\$ORIGIN\:\$ORIGIN\:..\/lib" in the
displayed hipcc-cmd output (and ignoring the errors due to rocm not
being installed)

Change-Id: I26b62f09ff3518cceeb85fa8823bb12a95c1c78e
Signed-off-by: Icarus Sparry <icarus.sparry@amd.com>
Этот коммит содержится в:
Icarus Sparry
2020-05-04 16:36:44 -04:00
коммит произвёл Icarus Sparry
родитель 507f6bb0c3
Коммит a4f01ffca6
+13
Просмотреть файл
@@ -401,6 +401,7 @@ if($HIP_PLATFORM eq "nvcc"){
}
}
# TODO: convert toolArgs to an array rather than a string
my $toolArgs = ""; # arguments to pass to the hcc or nvcc tool
my $optArg = ""; # -O args
my $targetOpt = '--amdgpu-target=';
@@ -410,7 +411,11 @@ my $prevArg = ""; # previous argument
foreach $arg (@ARGV)
{
# Save $arg, it can get changed in the loop.
$trimarg = $arg;
# TODO: figure out why this space removal is wanted.
# TODO: If someone has gone to the effort of quoting the spaces to the shell
# TODO: why are we removing it here?
$trimarg =~ s/^\s+|\s+$//g; # Remive whitespace
my $swallowArg = 0;
if ($arg eq '-c' or $arg eq '--genco' or $arg eq '-E') {
@@ -419,6 +424,7 @@ foreach $arg (@ARGV)
}
if ($skipOutputFile) {
# TODO: handle filename with shell metacharacters
$toolArgs .= " $arg";
$prevArg = $arg;
$skipOutputFile = 0;
@@ -667,6 +673,12 @@ foreach $arg (@ARGV)
push (@inputs, $arg);
#print "I: <$arg>\n";
}
# Produce a version of $arg where characters significant to the shell are
# quoted. One could quote everything of course but don't bother for
# common characters such as alphanumerics.
# Do the quoting here because sometimes the $arg is changed in the loop
# Important to have all of '-Xlinker' in the set of unquoted characters.
$arg =~ s/[^-a-zA-Z0-9=+,.]/\\$&/g;
$toolArgs .= " $arg" unless $swallowArg;
$prevArg = $arg;
}
@@ -813,6 +825,7 @@ if ($HIPCC_LINK_FLAGS_APPEND) {
$HIPLDFLAGS .= " $HIPCC_LINK_FLAGS_APPEND";
}
# TODO: convert CMD to an array rather than a string
my $CMD="$HIPCC";
if ($needCFLAGS) {