Bug 85635 - typo in link.c for BSD platforms
Summary: typo in link.c for BSD platforms
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 8.1.0
: P3 normal
Target Milestone: 8.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-03 17:51 UTC by John Marino
Modified: 2018-05-04 16:02 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-05-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Marino 2018-05-03 17:51:58 UTC
There was a bug introduced at trunk@254573 on (2017-11-09 Pascal Obry <obry@adacore.com>)

Specifically, a macro condition was modified improperly, resulting in a broken build on gcc release 8.1 and trunk.

The following (obvious) patch needs to be applied to fix it:

--- gcc/ada/link.c.orig 2018-05-03 17:24:27 UTC
+++ gcc/ada/link.c
@@ -104,7 +104,7 @@ unsigned char __gnat_separate_run_path_o
 const char *__gnat_default_libgcc_subdir = "lib";

 #elif defined (__FreeBSD__) || defined (__DragonFly__) \
-   || defined (__NetBSD__) || defined (__OpenBSD__)
+   || defined (__NetBSD__) || defined (__OpenBSD__) \
    || defined (__QNX__)
 const char *__gnat_object_file_option = "-Wl,@";
 const char *__gnat_run_path_option = "-Wl,-rpath,";
Comment 1 Jakub Jelinek 2018-05-03 17:56:53 UTC
To be precise, only {Free,Net,Open}BSD, QNX and DragonFly ada is broken.
Comment 2 John Marino 2018-05-03 18:07:30 UTC
I would think every condition after (e.g. __APPLE__, __linux__, _AIX) would fail as well.  Wouldn't cpp abort on QNX before the __APPLE__ condition is evaluated?
Comment 3 Eric Botcazou 2018-05-04 07:23:00 UTC
> To be precise, only {Free,Net,Open}BSD, QNX and DragonFly ada is broken.

Yes, the subject doesn't make any sense, people build & test Ada regularly...
Comment 4 Eric Botcazou 2018-05-04 07:33:08 UTC
Author: ebotcazou
Date: Fri May  4 07:32:36 2018
New Revision: 259925

URL: https://gcc.gnu.org/viewcvs?rev=259925&root=gcc&view=rev
Log:
	PR ada/85635
	* link.c (BSD platforms): Add missing backslash.

Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/link.c
Comment 5 Eric Botcazou 2018-05-04 07:33:20 UTC
Author: ebotcazou
Date: Fri May  4 07:32:48 2018
New Revision: 259926

URL: https://gcc.gnu.org/viewcvs?rev=259926&root=gcc&view=rev
Log:
	PR ada/85635
	* link.c (BSD platforms): Add missing backslash.

Modified:
    branches/gcc-8-branch/gcc/ada/ChangeLog
    branches/gcc-8-branch/gcc/ada/link.c
Comment 6 Eric Botcazou 2018-05-04 07:34:50 UTC
Thanks for reporting the problem.
Comment 7 John Marino 2018-05-04 12:23:46 UTC
It's a condition ladder.
The windows and hpux conditions are first on the ladder.  The cpp bug would have been short-circuited on those platforms.  For any platform that has the condition test fall to BSD first would be broken.  E.g. __APPLE__, __linux__, etc. which come afterwards.

All those conditions have to pass the BSD check; they would fail too.  The subject should not be confusing once the code is seen.

Thanks for fixing it though.
Comment 8 Jakub Jelinek 2018-05-04 12:38:23 UTC
No, for non-BSD the preprocessor sees:
#elif defined (__FreeBSD__) || defined (__DragonFly__) \
   || defined (__NetBSD__) || defined (__OpenBSD__)
and if not one of these 4, it skips all the tokens until the next #elif, so
the || defined (__QNX__) tokens are skipped too.

Several linux targets are tested daily by many people, if Ada would not bootstrap, it wouldn't go unnoticed.
Comment 9 John Marino 2018-05-04 12:47:00 UTC
Those "many" people don't build gnat.  Very few people do according to the testsuite results page.

link.c code was:

#if defined (__WIN32)
(block 1)
#elif defined (__hpux__)
(block 2)
#elif defined (__FreeBSD__) || defined (__DragonFly__) \
   || defined (__NetBSD__) || defined (__OpenBSD__)
   || defined (__QNX__)
(block 3)
#elif defined (__APPLE__)
(block 4)
#elif defined (__linux__) || defined (__GLIBC__)
(block 5)
#elif defined (_AIX)
(block 6)
#elif (HAVE_GNU_LD)
(block 7)
#elif defined (VMS)
(block 8)
#elif defined (__sun__)
(block 9)
#elif defined (__svr4__) && defined (__i386__)
(block 10)
#else
(block 11)
#endif


I don't see how it would have compiled on linux.  The cpp would have chocked on __QNX__ check on the __linux__ platform just as it would for any of the BSDs.  It wasn't a BSD-only issue.
Comment 10 John Marino 2018-05-04 12:51:51 UTC
ah, i see you explained what technically happened in the comment above.  I missed that at first.
That's how the QNX line was visibly limited to the BSD platforms then.  cpp didn't consider it a macro.  got it.
Comment 11 Jakub Jelinek 2018-05-04 12:55:20 UTC
Those many people do build gnat.  I do it in all my bootstraps, many other people working on gcc do.
And if you don't know how the C preprocessor works in this case, why don't you just try that out?
#if defined (A)
int a;
#elif defined (B) || defined (C) \
      || defined (D) || defined (E)
      || defined (F)
int b;
#elif defined (G)
int c;
#else
int d;
#endif
$ gcc -P -E -DA /tmp/j.c
int a;
$ gcc -P -E -DB /tmp/j.c
      || defined (F)
int b;
This preprocesses fine, but is not valid C.
$ gcc -P -E -DG /tmp/j.c
int c;
$ gcc -P -E -DH /tmp/j.c
int d;
Comment 12 John Marino 2018-05-04 13:19:44 UTC
yeah, my problem is that I was thinking cpp was complaining this whole time, but it was actually the c compiler.  Once I realized that, the misconception cleared up.  My fault, should've known better.

And I should have been building gcc trunk more frequently so it would've been caught before release.
Comment 13 Eric Botcazou 2018-05-04 16:02:59 UTC
> Those "many" people don't build gnat.  Very few people do according to the
> testsuite results page.

That's a clear misconception.  The Ada compiler is regularly built and tested on Linux, Darwin, Solaris and Windows.  The story is indeed different for BSDs but they are not representative of the native platforms here.