From b8bbc4f1fa74b418aaa24fc158baf0a203b139d7 Mon Sep 17 00:00:00 2001 From: Yaxun Sam Liu Date: Wed, 1 Aug 2018 17:01:39 -0400 Subject: [PATCH] Let hipcc handle static library for hip-clang [ROCm/clr commit: 2ba45a23b8d1866a3e32bffa6e7a4d45a54baf43] --- projects/clr/hipamd/bin/hipcc | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/projects/clr/hipamd/bin/hipcc b/projects/clr/hipamd/bin/hipcc index 9df3459fd1..c277fc42aa 100755 --- a/projects/clr/hipamd/bin/hipcc +++ b/projects/clr/hipamd/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 -