Skip to content

Commit d7cc759

Browse files
committed
geninfo: Fix gcov version detection for XCode 8.0
The LLVM gcov version included in XCode 8.0 reports its version in a format that is not understood by geninfo, resulting in the wrong format of coverage data files being expected. Fix this by reworking gcov version detection in geninfo to be more robust. Signed-off-by: Peter Oberparleiter <[email protected]>
1 parent 68320d9 commit d7cc759

File tree

1 file changed

+64
-42
lines changed

1 file changed

+64
-42
lines changed

bin/geninfo

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ sub solve_relative_path($$);
160160
sub read_gcov_header($);
161161
sub read_gcov_file($);
162162
sub info(@);
163+
sub map_llvm_version($);
164+
sub version_to_str($);
163165
sub get_gcov_version();
164166
sub system_no_output($@);
165167
sub read_config($);
@@ -1901,6 +1903,36 @@ sub read_gcov_file($)
19011903
}
19021904

19031905

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+
19041936
#
19051937
# Get the GCOV tool version. Return an integer number which represents the
19061938
# GCOV version. Version numbers can be compared using standard integer
@@ -1912,58 +1944,48 @@ sub get_gcov_version()
19121944
local *HANDLE;
19131945
my $version_string;
19141946
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
19161962

19171963
open(GCOV_PIPE, "-|", "$gcov_tool --version")
19181964
or die("ERROR: cannot retrieve gcov version!\n");
1965+
local $/;
19191966
$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/);
19311967
close(GCOV_PIPE);
19321968

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
19361970
$version_string =~ s/\([^\)]*\)//g;
19371971

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");
19511978
}
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");
19661987
}
1988+
19671989
return ($result, $version_string);
19681990
}
19691991

0 commit comments

Comments
 (0)