@@ -160,6 +160,8 @@ sub solve_relative_path($$);
160
160
sub read_gcov_header ($);
161
161
sub read_gcov_file ($);
162
162
sub info (@);
163
+ sub map_llvm_version ($);
164
+ sub version_to_str ($);
163
165
sub get_gcov_version ();
164
166
sub system_no_output ($@);
165
167
sub read_config ($);
@@ -1901,6 +1903,36 @@ sub read_gcov_file($)
1901
1903
}
1902
1904
1903
1905
1906
+ # Map LLVM versions to the version of GCC gcov which they emulate.
1907
+
1908
+ sub map_llvm_version ($)
1909
+ {
1910
+ my ($ver ) = @_ ;
1911
+
1912
+ return 0x040200 if ($ver >= 0x030400);
1913
+
1914
+ warn (" WARNING: This version of LLVM's gcov is unknown. " .
1915
+ " Assuming it emulates GCC gcov version 4.2.\n " );
1916
+
1917
+ return 0x040200;
1918
+ }
1919
+
1920
+
1921
+ # Return a readable version of encoded gcov version.
1922
+
1923
+ sub version_to_str ($)
1924
+ {
1925
+ my ($ver ) = @_ ;
1926
+ my ($a , $b , $c );
1927
+
1928
+ $a = $ver >> 16 & 0xff;
1929
+ $b = $ver >> 8 & 0xff;
1930
+ $c = $ver & 0xff;
1931
+
1932
+ return " $a .$b .$c " ;
1933
+ }
1934
+
1935
+
1904
1936
#
1905
1937
# Get the GCOV tool version. Return an integer number which represents the
1906
1938
# GCOV version. Version numbers can be compared using standard integer
@@ -1912,58 +1944,48 @@ sub get_gcov_version()
1912
1944
local *HANDLE;
1913
1945
my $version_string ;
1914
1946
my $result ;
1915
- my $pipe_next_line ;
1947
+ my ($a , $b , $c ) = (4, 2, 0); # Fallback version
1948
+
1949
+ # Examples for gcov version output:
1950
+ #
1951
+ # gcov (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
1952
+ #
1953
+ # gcov (crosstool-NG 1.18.0) 4.7.2
1954
+ #
1955
+ # LLVM (http://llvm.org/):
1956
+ # LLVM version 3.4svn
1957
+ #
1958
+ # Apple LLVM version 8.0.0 (clang-800.0.38)
1959
+ # Optimized build.
1960
+ # Default target: x86_64-apple-darwin16.0.0
1961
+ # Host CPU: haswell
1916
1962
1917
1963
open (GCOV_PIPE, " -|" , " $gcov_tool --version" )
1918
1964
or die (" ERROR: cannot retrieve gcov version!\n " );
1965
+ local $/ ;
1919
1966
$version_string = <GCOV_PIPE>;
1920
- # LLVM gcov keeps version information on the second line.
1921
- # For example, gcov --version yields:
1922
- # LLVM (http://llvm.org/):
1923
- # LLVM version 3.4svn
1924
-
1925
- $pipe_next_line = <GCOV_PIPE>;
1926
- # In case version information is on first line.
1927
- # For example, with Xcode 7.0 gcov --version yields:
1928
- # Apple LLVM 7.0.0 (clang-700.0.65)
1929
-
1930
- $version_string = $pipe_next_line if ($pipe_next_line && $version_string =~ / LLVM/ );
1931
1967
close (GCOV_PIPE);
1932
1968
1933
- # Remove version information in parenthesis to cope with the following:
1934
- # - gcov (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
1935
- # - gcov (crosstool-NG 1.18.0) 4.7.2
1969
+ # Remove all bracketed information
1936
1970
$version_string =~ s /\( [^\) ]*\) // g ;
1937
1971
1938
- $result = 0;
1939
- if ($version_string =~ / (\d +)\. (\d +)(\. (\d +))?/ )
1940
- {
1941
- if (defined ($4 ))
1942
- {
1943
- info(" Found gcov version: $1 .$2 .$4 \n " );
1944
- $result = $1 << 16 | $2 << 8 | $4 ;
1945
- }
1946
- else
1947
- {
1948
- info(" Found gcov version: $1 .$2 \n " );
1949
- $result = $1 << 16 | $2 << 8;
1950
- }
1972
+ if ($version_string =~ / (\d +)\. (\d +)(\. (\d +))?/ ) {
1973
+ ($a , $b , $c ) = ($1 , $2 , $4 );
1974
+ $c = 0 if (!defined ($c ));
1975
+ } else {
1976
+ warn (" WARNING: cannot determine gcov version - " .
1977
+ " assuming $a .$b .$c \n " );
1951
1978
}
1952
- if ($version_string =~ / LLVM/ )
1953
- {
1954
- # Map LLVM versions to the version of GCC gcov which
1955
- # they emulate
1956
- if ($result >= 0x030400)
1957
- {
1958
- info(" Found LLVM gcov version 3.4, which emulates gcov version 4.2\n " );
1959
- $result = 0x040200;
1960
- }
1961
- else
1962
- {
1963
- warn (" This version of LLVM's gcov is unknown. Assuming it emulates GCC gcov version 4.2.\n " );
1964
- $result = 0x040200;
1965
- }
1979
+ $result = $a << 16 | $b << 8 | $c ;
1980
+
1981
+ if ($version_string =~ / LLVM/ ) {
1982
+ $result = map_llvm_version($result );
1983
+ info(" Found LLVM gcov version $a .$b .$c , which emulates gcov " .
1984
+ " version " .version_to_str($result )." \n " );
1985
+ } else {
1986
+ info(" Found gcov version: " .version_to_str($result )." \n " );
1966
1987
}
1988
+
1967
1989
return ($result , $version_string );
1968
1990
}
1969
1991
0 commit comments