diff --git a/projects/hip/bin/hipcc b/projects/hip/bin/hipcc index 9df3459fd1..c277fc42aa 100755 --- a/projects/hip/bin/hipcc +++ b/projects/hip/bin/hipcc @@ -455,6 +455,53 @@ foreach $arg (@ARGV) close $in; close $out; $arg = "$new_arg -Wl,\@$new_file"; + } elsif (($arg =~ m/\.a$/ || $arg =~ m/\.lo$/) && + $HIP_PLATFORM eq 'clang') { + ## process static library for hip-clang + ## extract object files from static library and pass them directly to + ## hip-clang. + ## ToDo: Remove this after hip-clang switch to lto and lld is able to + ## handle clang-offload-bundler bundles. + + my $new_arg = ""; + my $tmpdir = get_temp_dir (); + my $libFile = $arg; + my $path = abs_path($arg); + my @objs = split ('\n', `cd $tmpdir; ar xv $path`); + ## Check if all files in .a are object files. + my $allIsObj = 1; + my $realObjs = ""; + foreach my $obj (@objs) { + chomp $obj; + $obj =~ s/^x - //; + $obj = "$tmpdir/$obj"; + my $fileType = `file $obj`; + my $isObj = ($fileType =~ m/ELF/ or $fileType =~ m/COFF/); + $allIsObj = ($allIsObj and $isObj); + if ($isObj) { + $realObjs = ($realObjs . " " . $obj); + } else { + push (@inputs, $obj); + if ($new_arg ne "") { + $new_arg .= " "; + } + $new_arg .= "$obj"; + } + } + chomp $realObjs; + if ($allIsObj) { + $new_arg = $arg; + } elsif ($realObjs) { + my($libBaseName, $libDir, $libExt) = fileparse($libFile); + $libBaseName = mktemp($libBaseName . "XXXX") . $libExt; + system("cd $tmpdir; ar c $libBaseName $realObjs"); + $new_arg .= " $tmpdir/$libBaseName"; + } + $arg = "$new_arg"; + if ($toolArgs =~ m/-Xlinker$/) { + $toolArgs = substr $toolArgs, 0, -8; + chomp $toolArgs; + } } elsif ($arg =~ m/^-/) { # options start with -