Hi Tamar, > -----Original Message----- > From: Tamar Christina <tamar.christ...@arm.com> > Sent: 09 July 2020 10:54 > To: gcc-patches@gcc.gnu.org > Cc: nd <n...@arm.com>; Richard Earnshaw <richard.earns...@arm.com>; > Marcus Shawcroft <marcus.shawcr...@arm.com>; Kyrylo Tkachov > <kyrylo.tkac...@arm.com>; Richard Sandiford > <richard.sandif...@arm.com> > Subject: [PATCH 1/6] AArch64: Fix bugs in -mcpu=native detection. > > Hi All, > > This patch fixes a couple of issues in AArch64's -mcpu=native processing: > > The buffer used to read the lines from /proc/cpuinfo is 128 bytes long. While > this was enough in the past with the increase in architecture extensions it is > no longer enough. It results in two bugs: > > 1) No option string longer than 127 characters is correctly parsed. Features > that are supported are silently ignored. > > 2) It incorrectly enables features that are not present on the machine: > a) It checks for substring matching instead of full word matching. This > makes > it incorrectly detect sb support when ssbs is provided instead. > b) Due to the truncation at the 127 char border it also incorrectly enables > features due to the full feature being cut off and the part that is left > accidentally enables something else. > > This breaks -mcpu=native detection on some of our newer system. > > The patch fixes these issues by reading full lines up to the \n in a string. > This gives us the full feature line. Secondly it creates a set from this > string > to: > > 1) Reduce matching complexity from O(n*m) to O(n*logm). > 2) Perform whole word matching instead of substring matching. > > To make this code somewhat cleaner I also changed from using char* to > using > std::string and std::set. > > Note that I have intentionally avoided the use of ifstream and stringstream > to make it easier to backport. I have also not change the substring matching > for the initial line classification as I cannot find a documented cpuinfo > format > which leads me to believe there may be kernels out there that require this > which > may be why the original code does this. > > I also do not want this to break if the kernel adds a new line that is long > and > indents the file by two tabs to keep everything aligned. In short I think an > imprecise match is the right thing here. > > Test for this is added as the last thing in this series as it requires some > changes to be made to be able to test this. > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > Ok for master, GCC 10, 9 and 8?
Ok. Note that GCC 10.2 release is coming soon (next week). Please make sure this is tested well on GCC 10 (not that I doubt your testing). Thanks, Kyrill > > Thanks, > Tamar > > gcc/ChangeLog: > > * config/aarch64/driver-aarch64.c (INCLUDE_SET): New. > (parse_field): Use std::string. > (split_words, readline): New. > (host_detect_local_cpu): Fix truncation issues. > > --