Merge pull request #505 from ROCm-Developer-Tools/fix-hipcc-linker

Let hipcc handle library in linker response file for hip-clang

[ROCm/clr commit: 359e6609bc]
Este commit está contenido en:
Maneesh Gupta
2018-06-11 12:01:45 +05:30
cometido por GitHub
+58 -3
Ver fichero
@@ -4,6 +4,9 @@
# Need perl > 5.10 to use logic-defined or
use 5.006; use v5.10.1;
use File::Basename;
use File::Temp qw/ :mktemp /;
use Cwd;
use Cwd 'abs_path';
# HIP compiler driver
# Will call NVCC or HCC (depending on target) and pass the appropriate include and library options for
@@ -58,6 +61,27 @@ $DEVICE_LIB_PATH=$ENV{'DEVICE_LIB_PATH'};
my %hipConfig = ();
parse_config_file("$HIP_PATH/lib/.hipInfo", \%hipConfig);
#---
# Temporary directories
my @tmpDirs = ();
#---
# Create a new temporary directory and return it
sub get_temp_dir {
my $tmpdir = mkdtemp("/tmp/hipccXXXXXXXX");
push (@tmpDirs, $tmpdir);
return $tmpdir;
}
#---
# Delete all created temporary directories
sub delete_temp_dirs {
if (@tmpDirs) {
system ('rm -rf ' . join (' ', @tmpDirs));
}
return 0;
}
#---
#HIP_PLATFORM controls whether to use NVCC or HCC for compilation:
$HIP_PLATFORM= `$HIP_PATH/bin/hipconfig --platform` // "hcc";
@@ -338,7 +362,38 @@ foreach $arg (@ARGV)
$setLinkType = 1;
}
if ($arg =~ m/^-/) {
## process linker response file for hip-clang
## extract object files from static library and pass them directly to
## hip-clang in command line.
## ToDo: Remove this after hip-clang switch to lto and lld is able to
## handle clang-offload-bundler bundles.
if ($arg =~ m/^-Wl,@/ and $HIP_PLATFORM eq 'clang') {
my $file = substr $arg, 5;
open my $in, "<:encoding(utf8)", $file or die "$file: $!";
my $new_arg = "";
my $tmpdir = get_temp_dir ();
my $new_file = "$tmpdir/response_file";
open my $out, ">", $new_file or die "$new_file: $!";
while (my $line = <$in>) {
chomp $line;
if ($line =~ m/\.a$/) {
my $path = abs_path($line);
my @objs = split ('\n', `cd $tmpdir; ar xv $path`);
foreach my $obj (@objs) {
chomp $obj;
$obj =~ s/^x - //;
$obj = "$tmpdir/$obj";
push (@inputs, $obj);
$new_arg = "$new_arg $obj";
}
} else {
print $out "$line\n";
}
}
close $in;
close $out;
$arg = "$new_arg -Wl,\@$new_file";
} elsif ($arg =~ m/^-/) {
# options start with -
# Process HIPCC options here:
@@ -351,7 +406,7 @@ foreach $arg (@ARGV)
push (@options, $arg);
}
#print "O: <$arg>\n";
} else {
} else {
# input files and libraries
if (($arg =~ /\.cpp$/) or ($arg =~ /\.c$/) or ($arg =~ /\.cc$/) ) {
$hasC = 1;
@@ -562,7 +617,7 @@ if ($runCmd) {
print ("HIP ($HIP_PATH) was built using hcc $hipConfig{'HCC_VERSION'}, but you are using $HCC_HOME/hcc with version $HCC_VERSION from hipcc. Please rebuild HIP including cmake or update HCC_HOME variable.\n") ;
die unless $ENV{'HIP_IGNORE_HCC_VERSION'};
}
system ("$CMD") and die ();
system ("$CMD") or delete_temp_dirs () and die ();
}
# vim: ts=4:sw=4:expandtab:smartindent