Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Linux] determineArchitecture is not cross-compile aware
https://bugs.webkit.org/show_bug.cgi?id=169886

Reviewed by Michael Catanzaro.

Try to detect the target architecture name from the GCC triplet
when cross-building.

The aarch64 architecture is renamed to arm64 (this is coherent with
the rest of the perl tooling that consults the architecture determined
in determineArchitecture(), the check for this arch is always done
with the arm64 name).

* Scripts/webkitdirs.pm: Remove the isARM() function: its dead code
and not cross-build aware.
(determineArchitecture): When crossbuilding, try to detect the target
architecture name from the GCC triplet.
Remove also the fallback option to run the arch command, because this
command doesn't print the expected on Mac/BSD, and on Linux is the
same than uname -m. See https://bugs.webkit.org/show_bug.cgi?id=152958#c6
(isCrossCompilation): Some cross-compilers (buildroot one for example)
don't define the --host option. Add another option to detect that
we are cross-building by building a dummy program and checking if
we can run it.

Canonical link: https://commits.webkit.org/186879@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214250 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
clopez committed Mar 22, 2017
1 parent bfe80da commit 01e99e5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 24 deletions.
27 changes: 27 additions & 0 deletions Tools/ChangeLog
@@ -1,3 +1,30 @@
2017-03-22 Carlos Alberto Lopez Perez <clopez@igalia.com>

[Linux] determineArchitecture is not cross-compile aware
https://bugs.webkit.org/show_bug.cgi?id=169886

Reviewed by Michael Catanzaro.

Try to detect the target architecture name from the GCC triplet
when cross-building.

The aarch64 architecture is renamed to arm64 (this is coherent with
the rest of the perl tooling that consults the architecture determined
in determineArchitecture(), the check for this arch is always done
with the arm64 name).

* Scripts/webkitdirs.pm: Remove the isARM() function: its dead code
and not cross-build aware.
(determineArchitecture): When crossbuilding, try to detect the target
architecture name from the GCC triplet.
Remove also the fallback option to run the arch command, because this
command doesn't print the expected on Mac/BSD, and on Linux is the
same than uname -m. See https://bugs.webkit.org/show_bug.cgi?id=152958#c6
(isCrossCompilation): Some cross-compilers (buildroot one for example)
don't define the --host option. Add another option to detect that
we are cross-building by building a dummy program and checking if
we can run it.

2017-03-22 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK] Several WPT tests are failing since they were added in the last update in r213882
Expand Down
55 changes: 31 additions & 24 deletions Tools/Scripts/webkitdirs.pm
Expand Up @@ -40,6 +40,7 @@ use File::Basename;
use File::Find;
use File::Path qw(make_path mkpath rmtree);
use File::Spec;
use File::Temp qw(tempdir);
use File::stat;
use List::Util;
use POSIX;
Expand Down Expand Up @@ -343,12 +344,16 @@ sub determineArchitecture
}
}
} elsif (isCMakeBuild()) {
if (open my $cmake_sysinfo, "cmake --system-information |") {
if (isCrossCompilation()) {
my $compiler = "gcc";
$compiler = $ENV{'CC'} if (defined($ENV{'CC'}));
my @compiler_machine = split('-', `$compiler -dumpmachine`);
$architecture = $compiler_machine[0];
} elsif (open my $cmake_sysinfo, "cmake --system-information |") {
while (<$cmake_sysinfo>) {
next unless index($_, 'CMAKE_SYSTEM_PROCESSOR') == 0;
if (/^CMAKE_SYSTEM_PROCESSOR \"([^"]+)\"/) {
$architecture = $1;
$architecture = 'x86_64' if $architecture eq 'amd64';
last;
}
}
Expand All @@ -357,20 +362,15 @@ sub determineArchitecture
}

if (!isAnyWindows()) {
if (!$architecture) {
# Fall back to output of `arch', if it is present.
$architecture = `arch`;
chomp $architecture;
}

if (!$architecture) {
# Fall back to output of `uname -m', if it is present.
$architecture = `uname -m`;
chomp $architecture;
}
}

$architecture = 'x86_64' if ($architecture =~ /amd64/ && isBSD());
$architecture = 'x86_64' if $architecture =~ /amd64/i;
$architecture = 'arm64' if $architecture =~ /aarch64/i;
}

sub determineASanIsEnabled
Expand Down Expand Up @@ -1185,28 +1185,35 @@ sub isBSD()
return ($^O eq "freebsd") || ($^O eq "openbsd") || ($^O eq "netbsd") || 0;
}

sub isARM()
{
return ($Config{archname} =~ /^arm[v\-]/) || ($Config{archname} =~ /^aarch64[v\-]/);
}

sub isX86_64()
{
return (architecture() eq "x86_64") || 0;
}

sub isCrossCompilation()
{
my $compiler = "";
$compiler = $ENV{'CC'} if (defined($ENV{'CC'}));
if ($compiler =~ /gcc/) {
my $compiler_options = `$compiler -v 2>&1`;
my @host = $compiler_options =~ m/--host=(.*?)\s/;
my @target = $compiler_options =~ m/--target=(.*?)\s/;

return ($host[0] ne "" && $target[0] ne "" && $host[0] ne $target[0]);
}
return 0;
my $compiler = "";
$compiler = $ENV{'CC'} if (defined($ENV{'CC'}));
if ($compiler =~ /gcc/) {
my $compilerOptions = `$compiler -v 2>&1`;
my @host = $compilerOptions =~ m/--host=(.*?)\s/;
my @target = $compilerOptions =~ m/--target=(.*?)\s/;
if ($target[0] ne "" && $host[0] ne "") {
return ($host[0] ne $target[0]);
} else {
# $tempDir gets automatically deleted when goes out of scope
my $tempDir = File::Temp->newdir();
my $testProgramSourcePath = File::Spec->catfile($tempDir, "testcross.c");
my $testProgramBinaryPath = File::Spec->catfile($tempDir, "testcross");
open(my $testProgramSourceHandler, ">", $testProgramSourcePath);
print $testProgramSourceHandler "int main() { return 0; }\n";
system("$compiler $testProgramSourcePath -o $testProgramBinaryPath > /dev/null 2>&1") == 0 or return 0;
# Crosscompiling if the program fails to run (because it was built for other arch)
system("$testProgramBinaryPath > /dev/null 2>&1") == 0 or return 1;
return 0;
}
}
return 0;
}

sub isAppleWebKit()
Expand Down

0 comments on commit 01e99e5

Please sign in to comment.