Issue 127712 - Allow building when gcc -dumpversion does not use the canonical x.y.z format
Summary: Allow building when gcc -dumpversion does not use the canonical x.y.z format
Status: CLOSED FIXED
Alias: None
Product: Build Tools
Classification: Code
Component: solenv (show other issues)
Version: 4.2.0-dev
Hardware: All All
: P5 (lowest) Normal (vote)
Target Milestone: 4.1.6
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-18 21:22 UTC by Andrea Pescetti
Modified: 2022-10-28 12:54 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---
petko: 4.1.6_release_blocker+


Attachments
possible solution for gcc -dumpversion (75.90 KB, image/png)
2018-03-06 19:13 UTC, Ash
no flags Details
gcc version for both old and new (971 bytes, patch)
2018-03-13 20:36 UTC, Ash
no flags Details | Diff
Patch to configure.ac that calls gcc with both version dump parameters (526 bytes, patch)
2018-11-11 22:26 UTC, Arrigo Marchiori
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description Andrea Pescetti 2018-02-18 21:22:26 UTC
Code in main/solenv/inc/tg_compv.mk and main/solenv/bin/getcompver.awk assumes that "gcc -dumpversion" will return a canonical version number in the form x.y.z.

Unfortunately, recent GCC versions no longer guarantee this convention:

https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html#index-dumpversion

"Print the compiler version (for example, 3.0, 6.3.0 or 7)—and don’t do anything else. This is the compiler version used in filesystem paths, specs, can be depending on how the compiler has been configured just a single number (major version), two numbers separated by dot (major and minor version) or three numbers separated by dots (major, minor and patchlevel version)."

The right one to use would be -dumpfullversion (same URL):

"Print the full compiler version, always 3 numbers separated by dots, major, minor and patchlevel version."

Unfortunately, it seems (but I haven't checked yet) that old gcc versions do not support -dumpfullversion.

Note: "6.3" does not mean "6.3.0"; you can get "6.3" for "6.3.0" or "6.3.1", and you can get "7" for "7.0.0", "7.3.0", "7.3.1"... the version is simply truncated, and configuration depends on the distribution.

When the output is in the form "x.y", we already expand it to "x.y.0", which is wrong (see above).

The following patch to main/solenv/bin/getcompver.awk extends it to expand "7" to "7.0.0" and is equally wrong, but it allows the build to continue.

---
@@ -46,6 +46,13 @@
     x = match( $0, /[0-9]*\.[0-9]*\.[0-9]*/ )
     CCversion = substr( $0, RSTART, RLENGTH)
 }
+/^[0-9]*\x0d*$/ {
+    if ( compiler_matched == 0 ) {
+    # Comparison assumes the compiler version is reported as x.y.z.
+    # For GCC one should use -dumpfullversion but it won't work on old versions.
+    	CCversion = $0 ".0.0"
+    }
+}
 /^[0-9]*[.][0-9]*\x0d*$/ {
     if ( compiler_matched == 0 ) {
 # need to blow to x.xx.xx for comparing
---

The proper solution is: test if -dumpfullversion is supported and use its output in case, otherwise revert to -dumpversion and go through all current hacks.

Note that the awk file is not specific to gcc, so changes must go in main/solenv/inc/tg_compv.mk
Comment 1 Ash 2018-03-06 19:11:41 UTC
Found one nice way of solving this without having to implement any complex logic.
Please see attached pic for solution.
Comment 2 Ash 2018-03-06 19:13:46 UTC
Created attachment 86360 [details]
possible solution for gcc -dumpversion
Comment 3 Andrea Pescetti 2018-03-06 23:11:28 UTC
Very nice solution! If old gcc versions indeed behave like this and simply ignore the option they don't support (when given both), then please feel free to turn this into a patch against trunk, attach it here, and I will commit it for you.
Comment 4 Ash 2018-03-13 20:36:04 UTC
Created attachment 86364 [details]
gcc version for both old and new
Comment 5 Matthias Seidel 2018-03-21 20:23:32 UTC
Note:

main/solenv/inc/tg_compv.mk has been deleted from trunk with r1826296.

Logic was moved to configure.
Comment 6 Andrea Pescetti 2018-08-31 06:58:17 UTC
Apparently I can't set a flag for this component, but I'd like to suggest this for 4.1.6: it allows building (or at least getting past the configure stage) when GCC reports its version in an unusual way.

Note: no immediate port from/to trunk is foreseen since as Matthias noted we do things differently in trunk.
Comment 7 Peter 2018-09-16 09:22:38 UTC
Accepted for 4.1.6
Comment 8 Andrea Pescetti 2018-10-15 21:10:03 UTC
This is now committed to AOO416 with r1843953 since we already had the necessary approval from Peter above.

Thank you Ash for your contribution!

(this is NOT committed to trunk due to the changes outlined by Matthias above)
Comment 9 Arrigo Marchiori 2018-11-11 22:26:57 UTC
Created attachment 86542 [details]
Patch to configure.ac that calls gcc with both version dump parameters

This patch applies the same logic to the configure.ac file, and therefore should be applicable to trunk.
Comment 10 SVN Robot 2018-11-12 12:03:06 UTC
"mseidel" committed SVN revision 1846401 into trunk:
i127712 - Allow building when gcc -dumpversion does not use the canonical x.y...