From 29c6debccf0d155cb0a0fd14eb6afe077a206f27 Mon Sep 17 00:00:00 2001 From: Tamar Christina Date: Thu, 28 Feb 2019 10:43:41 +0000 Subject: [PATCH] AArch64: Have empty HWCAPs string ignored during native feature detection This patch makes the feature detection code for AArch64 GCC not add features automatically when the feature had no hwcaps string to match against. This means that -mcpu=native no longer adds feature flags such as +profile. The behavior wasn't noticed before because at the time +profile was added a bug was preventing any feature bits from being added by native detections. The loop has also been changed as Jakub specified in order to avoid a memory leak that was present in the existing code and to be slightly more efficient. gcc/ChangeLog: PR target/88530 * config/aarch64/aarch64-option-extensions.def: Document it. * config/aarch64/driver-aarch64.c (host_detect_local_cpu): Skip feature if empty hwcaps. gcc/testsuite/ChangeLog: PR target/88530 * gcc.target/aarch64/options_set_10.c: New test. From-SVN: r269276 --- gcc/ChangeLog | 7 +++++ gcc/config/aarch64/aarch64-option-extensions.def | 3 ++- gcc/config/aarch64/driver-aarch64.c | 32 ++++++++++++++--------- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.target/aarch64/options_set_10.c | 11 ++++++++ 5 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/options_set_10.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f9b7197..e7ca0e4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-02-28 Tamar Christina + + PR target/88530 + * config/aarch64/aarch64-option-extensions.def: Document it. + * config/aarch64/driver-aarch64.c (host_detect_local_cpu): Skip feature + if empty hwcaps. + 2019-02-28 Jakub Jelinek PR c/89520 diff --git a/gcc/config/aarch64/aarch64-option-extensions.def b/gcc/config/aarch64/aarch64-option-extensions.def index 1b2f4ab..7a80b69 100644 --- a/gcc/config/aarch64/aarch64-option-extensions.def +++ b/gcc/config/aarch64/aarch64-option-extensions.def @@ -44,7 +44,8 @@ the extension (for example, the 'crypto' extension depends on four entries: aes, pmull, sha1, sha2 being present). In that case this field should contain a space (" ") separated list of the strings in 'Features' - that are required. Their order is not important. */ + that are required. Their order is not important. An empty string means + do not detect this feature during auto detection. */ /* Enabling "fp" just enables "fp". Disabling "fp" also disables "simd", "crypto", "fp16", "aes", "sha2", diff --git a/gcc/config/aarch64/driver-aarch64.c b/gcc/config/aarch64/driver-aarch64.c index 6051443..6f16775 100644 --- a/gcc/config/aarch64/driver-aarch64.c +++ b/gcc/config/aarch64/driver-aarch64.c @@ -249,27 +249,35 @@ host_detect_local_cpu (int argc, const char **argv) { for (i = 0; i < num_exts; i++) { - char *p = NULL; - char *feat_string - = concat (aarch64_extensions[i].feat_string, NULL); + const char *p = aarch64_extensions[i].feat_string; + + /* If the feature contains no HWCAPS string then ignore it for the + auto detection. */ + if (*p == '\0') + continue; + bool enabled = true; /* This may be a multi-token feature string. We need - to match all parts, which could be in any order. - If this isn't a multi-token feature string, strtok is - just going to return a pointer to feat_string. */ - p = strtok (feat_string, " "); - while (p != NULL) + to match all parts, which could be in any order. */ + size_t len = strlen (buf); + do { - if (strstr (buf, p) == NULL) + const char *end = strchr (p, ' '); + if (end == NULL) + end = strchr (p, '\0'); + if (memmem (buf, len, p, end - p) == NULL) { /* Failed to match this token. Turn off the features we'd otherwise enable. */ enabled = false; break; } - p = strtok (NULL, " "); + if (*end == '\0') + break; + p = end + 1; } + while (1); if (enabled) extension_flags |= aarch64_extensions[i].flag; @@ -360,12 +368,12 @@ host_detect_local_cpu (int argc, const char **argv) not_found: { /* If detection fails we ignore the option. - Clean up and return empty string. */ + Clean up and return NULL. */ if (f) fclose (f); - return ""; + return NULL; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8c80d5e..6795bfc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-02-28 Tamar Christina + + PR target/88530 + * gcc.target/aarch64/options_set_10.c: New test. + 2019-02-28 Paolo Carlini PR c++/89522 diff --git a/gcc/testsuite/gcc.target/aarch64/options_set_10.c b/gcc/testsuite/gcc.target/aarch64/options_set_10.c new file mode 100644 index 0000000..5ffe83c --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/options_set_10.c @@ -0,0 +1,11 @@ +/* { dg-do compile { target "aarch64*-*-linux*" } } */ +/* { dg-additional-options "-mcpu=native" } */ + +int main () +{ + return 0; +} + +/* { dg-final { scan-assembler-not {\.arch .+\+profile.*} } } */ + + /* Check that an empty feature string is not detected during mcpu=native. */ -- 2.7.4