Ubuntu 16.04 / gcc 5.4.0 - errors generated inside system include files

I'm hitting unexpected problems building some old-ish code (UCB Logo 6, after hearing Seymour Papert went PENUP last week). gcc seems to be choking on its own header file, mathcalls.h: gcc -g -O -O0 -DUSE_OLD_TTY -c -o coms.o coms.c In file included from coms.c:30:0: /usr/include/x86_64-linux-gnu/bits/mathcalls.h:100:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’ __MATHCALL_VEC (exp,, (_Mdouble_ __x)); ^ /usr/include/x86_64-linux-gnu/bits/mathcalls.h:100:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’ __MATHCALL_VEC (exp,, (_Mdouble_ __x)); ^ /usr/include/x86_64-linux-gnu/bits/mathcalls.h:100:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’ __MATHCALL_VEC (exp,, (_Mdouble_ __x)); ^ <builtin>: recipe for target 'coms.o' failed make: *** [coms.o] Error 1 (this on Ubuntu 16.04, gcc 5.4.0, x86_64) I can build other code that includes math.h, the source of the mathcalls.h inclusion. The package builds fine on a Raspberry Pi (Raspbian, gcc 4.9.2, armv7l). The package even built on x86_64 under Ubuntu 15.10. Is this just Canonical mucking about with the compiler settings again? cheers, Stewart

On 16-08-06 10:02 AM, Stewart C. Russell via talk wrote:
gcc seems to be choking on its own header file, mathcalls.h:
The first step is a search to see if you have the mathcalls.h file on the machine. Under Linux Mint (based on Ubuntu) it is in the libc6-dev package. If that isn't the problem there may be something included by mathcalls.h that is missing. -- Cheers! Kevin. http://www.ve3syb.ca/ |"Nerds make the shiny things that distract Owner of Elecraft K2 #2172 | the mouth-breathers, and that's why we're | powerful!" #include <disclaimer/favourite> | --Chris Hardwick

On 2016-08-06 10:53 AM, Kevin Cozens via talk wrote:
The first step is a search to see if you have the mathcalls.h file on the machine.
Yes, it's in /usr/include/x86_64-linux-gnu/bits/mathcalls.h Those error lines are from mathcalls.h
If that isn't the problem there may be something included by mathcalls.h that is missing.
It has no #include lines. Running with -M or -E throws up no unexpected missing files. cheers, Stewart

Look at bottom answer http://stackoverflow.com/questions/10293202/c-error-expected-asm-or-attribut... On Sat, Aug 06, 2016 at 10:02 AM, Stewart C. Russell via talk < talk@gtalug.org [talk@gtalug.org] > wrote: I'm hitting unexpected problems building some old-ish code (UCB Logo 6, after hearing Seymour Papert went PENUP last week). gcc seems to be choking on its own header file, mathcalls.h: gcc -g -O -O0 -DUSE_OLD_TTY -c -o coms.o coms.c In file included from coms.c:30:0: /usr/include/x86_64-linux-gnu/bits/mathcalls.h:100:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’ __MATHCALL_VEC (exp,, (_Mdouble_ __x)); ^ /usr/include/x86_64-linux-gnu/bits/mathcalls.h:100:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’ __MATHCALL_VEC (exp,, (_Mdouble_ __x)); ^ /usr/include/x86_64-linux-gnu/bits/mathcalls.h:100:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’ __MATHCALL_VEC (exp,, (_Mdouble_ __x)); ^ <builtin>: recipe for target 'coms.o' failed make: *** [coms.o] Error 1 (this on Ubuntu 16.04, gcc 5.4.0, x86_64) I can build other code that includes math.h, the source of the mathcalls.h inclusion. The package builds fine on a Raspberry Pi (Raspbian, gcc 4.9.2, armv7l). The package even built on x86_64 under Ubuntu 15.10. Is this just Canonical mucking about with the compiler settings again? cheers, Stewart --- Talk Mailing List talk@gtalug.org https://gtalug.org/mailman/listinfo/talk

| From: Stewart C. Russell via talk <talk@gtalug.org> [Sorry, I've ascii-fied GCC's UNICODE diagnostics since I'm still in the 1980s.] | I'm hitting unexpected problems building some old-ish code (UCB Logo 6, | after hearing Seymour Papert went PENUP last week). gcc seems to be | choking on its own header file, mathcalls.h: Sad about Papert. UCB Logo, last I looked, wasn't really maintained any longer. It was last updated in 2008. But it seems to still work. Brian Harvey, the author, is an interesting guy too. He wrote a series of Logo books published by MIT press. | gcc -g -O -O0 -DUSE_OLD_TTY -c -o coms.o coms.c | In file included from coms.c:30:0: | /usr/include/x86_64-linux-gnu/bits/mathcalls.h:100:1: error: expected | `=', `,', `;', `asm' or `__attribute__' before `extern' | __MATHCALL_VEC (exp,, (_Mdouble_ __x)); | ^ | /usr/include/x86_64-linux-gnu/bits/mathcalls.h:100:1: error: expected | `=', `,', `;', `asm' or `__attribute__' before `extern' | __MATHCALL_VEC (exp,, (_Mdouble_ __x)); | ^ | /usr/include/x86_64-linux-gnu/bits/mathcalls.h:100:1: error: expected | `=', `,', `;', `asm' or `__attribute__' before `extern' | __MATHCALL_VEC (exp,, (_Mdouble_ __x)); | ^ Odd that you got three identical error messages. They look like they are out of the C parser. It is saying that this token isn't expected before "extern". But I don't see extern as the next token. So I'm not sure. __MATHCALL_VEC is supposed to be a C preprocessor macro. One that does tricky C preprocessor operations. With the leading __, it is in the namespace reserved for the system (i.e. glib) UCB Logo surely makes no (direct?) use of any SIMD instructions (the point of __MATHCALL_VEC). If you look at the -E output, has __MATHCALL_VEC been replaced or is it still there? - if it is replaced, what's the resulting pure C declaration look like? - if it isn't replaced, the problem is that the macro definition is somehow missing in the compilation process. | (this on Ubuntu 16.04, gcc 5.4.0, x86_64) Good to know. | I can build other code that includes math.h, the source of the | mathcalls.h inclusion. The package builds fine on a Raspberry Pi | (Raspbian, gcc 4.9.2, armv7l). The package even built on x86_64 under | Ubuntu 15.10. | | Is this just Canonical mucking about with the compiler settings again? Dunno. As an experiment, I compiled a file that contained only an include of math.h on an AMD64 Ubuntu 16.04 LTS (I happened to update our kitchen computer, an ancient Atom-based system to 16.04 earlier today). There was no error message. So the problem is probably interference between headers or compilation flags and the header. What comes before the include of math.h? What flags are used? You could copy the file and then iteratively pare it down until the error goes away. (Also: pare down the gcc flags.) Looking around line 30 of coms.c, I see: #ifdef HAVE_WX #define fgets wx_fgets extern int check_wx_stop(int force_yield); #endif #define WANT_EVAL_REGS 1 #include "logo.h" #include "globals.h" #include <math.h> The only suspicious thing is that there are two headers included before math.h. Try permuting these includes to see if that makes a difference. As a general rule, it is good to include system headers before program headers because then you know that the system header isn't being interfered with. Of course sometimes you wish to interfere with a system header, but that has dangers. The header logo.h is meant to make the code portable. That sometime causes problems as systems evolve. Remember THINK_C (for 68k-based Macs)? Or __TURBOC__ (Borland)? Or __ZTC__ (Zortech C)? I maintain Jove, a portable C program written in the early 1980s. Once in a while, names that are in the programmer's namespace get co-opted by some system. Maybe that is what has happened. I just noticed that I exchanged email with Brian Harvey about UCB Logo last year. I think he uses or has used Jove as his editor -- UCB Logo knows about it. I thought I found documentation bugs about this in UCB Logo but he didn't think so. It seems that on Unix, UCB Logo defaults to emacs, not jove, contrary to the documentation. Fedora has a package "ucblogo" (which has an emacs dependency, dammit). Ubuntu 14.04 also has a ucblogo package. I didn't try 16.04.

I installed AMD64 Ubuntu 16.04 LTS on another computer so that I could play. But it turns out that the same problem is in Fedora 24 so I needn't have bothered. Aside: I learned that the best description of my Canadian Bilingual Keyboard is under French(Canada) ; English-something-or-other. I'm still playing with this, but here are my preliminary observations. So here's the fundamental problem. "exp" is kind of like a reserved word in C. It is the exponential function and is declared in math.h. logo.h has #define exp expresn This screws up math.h. [language lawyer mode] The C standard as of N1548 (draft from 2010 December 2) says: 7.1.2 Reserved identifiers ... - All identifiers with external linkage in any of the following subclauses (including the future library directions) and errno are always reserved for use as identifiers with external linkage. 184) ... A following subclause includes a definition of exp. As I understand it, as an identifier with external linkage. As I read that, logo.h is NOT impinging since it is using exp as a macro name, something that gets "washed out" by the preprocessor, long before external linkages are understood. But the definition of exp affects the tricky code in /usr/include/x86_64-linux-gnu/bits/mathcalls.h __MATHCALL_VEC (exp,, (_Mdouble_ __x)); => __MATHCALL_VEC (expresn,, (_Mdouble_ __x)); which then malfunctions. Math.h: /* The file <bits/mathcalls.h> contains the prototypes for all the actual math functions. These macros are used for those prototypes, so we can easily declare each function as both `name' and `__name', and can declare the float versions `namef' and `__namef'. */ #define __SIMD_DECL(function) __CONCAT (__DECL_SIMD_, function) #define __MATHCALL_VEC(function, suffix, args) \ __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \ __MATHCALL (function, suffix, args) and so on. I *think* that this is a bug in glibc (i.e. a "contract violation" of the C Standard), but I'm not 100% sure. Why does ucblogo have this definition? Here's my guess. UCB Logo uses a global variable with the name "exp" pervasively. Then it turned out that this was the (external linkage) name of the exp function. So there was a clash, even though the exp function isn't used by ucblogo. The #define was a simple way of renaming the global variable's external name without editing the source code. An effective hack. Fix? Several, but untested. 1. Brutish of brute force: Replace every #include <math.h> with #undef exp #include <math.h> #define exp expresn 2. Better fix: fix glibc to not take names that don't belong to it. 3. Blame the victim fix: in UCB Logo, replace every "exp" with "expresn" (or some other apt short name). 4. Simpler UCB Logo fix: Move the <> includes before the "" includes. Generally considered good style anyway. There is a chance that logo.h includes things that intentionally modify system headers. In that case, this fix will break these modifications.

On 2016-08-07 03:34 PM, D. Hugh Redelmeier via talk wrote:
I'm still playing with this, but here are my preliminary observations.
Wow, thanks, Hugh - this is definitely the definition of going above and beyond!
So here's the fundamental problem.
"exp" is kind of like a reserved word in C. It is the exponential function and is declared in math.h.
logo.h has #define exp expresn
This screws up math.h.
I initially thought “How can C possibly allow that?” — then I remember that C basically allows everything. So what we have here is a kind of internal bitrot: the code doesn't change, but the standards of the language do, so it won't build.
Fix? Several, but untested. …
Thank you. I'll definitely try the simpler ones. Don't think the glibc ones are within my grasp. You'd previously asked why I wasn't using the distro-supplied versions. True enough: Ubuntu has a packaged UCB Logo 5.5 archive that installs and runs easily enough. Unfortunately, it's not fit for my purposes. I'm using Logo to generate construction frameworks for decorative patterns*. I dunno what 5.5 is built on top of, but its PostScript output is a mess of unnecessary nodes. The newer interpreter has a completely rewritten graphics system on top of wxWidgets, and its output is very clean. Yeah, I should probably do this using Python's turtle module, as it makes some nice output and is actually maintained. Logo, however, encourages a much more interactive development style. cheers, Stewart *: like this - cs pd repeat 10 [ rt 54 fd 43.865 lt 90 fd 45.002 lt 108 fd 45.002 lt 90 fd 43.865 lt 90 ] pu ht

| From: Stewart C. Russell via talk <talk@gtalug.org> | So what we have here is a kind of | internal bitrot: the code doesn't change, but the standards of the | language do, so it won't build. Perhaps not in this case. exp(3) has always been in <math.h>. But if a simple declaration in that header looked like this: double exp(); and it got attacked by the logo.h #define to turn it into double expresn(); the resulting error message ought to be a lot clearer. I don't know why there would not have been an error (a clash with the programs's external variable exp / expresn). But glibc started doing odd preprocessor tricks (token pasting I think, but I didn't look closely) and then weird things happen. So the actual behaviour rotted whereas the language status didn't change. I think. | Thank you. I'll definitely try the simpler ones. Don't think the glibc | ones are within my grasp. It turns out that there are other compiler error messages that I haven't sorted through. But since 6.0 is in Fedora, you might have a look at what the source RPM does to patch them up. (Fedora RPMs include an unchanged upstream tar.gz and a bunch of patches and a recipe for building the package. Even if it doesn't directly apply to Ubuntu/debian, it should be quite helpful.) | You'd previously asked why I wasn't using the distro-supplied versions. | True enough: Ubuntu has a packaged UCB Logo 5.5 archive that installs | and runs easily enough. Unfortunately, it's not fit for my purposes. That's sad. 6.0 seems to date back to 2008. Maybe you could package 6.0 for debian or Ubuntu if you figure this out. | Yeah, I should probably do this using Python's turtle module, as it | makes some nice output and is actually maintained. Logo, however, | encourages a much more interactive development style. I have a soft spot for Logo. I've described some of my experience with it on this list. | cs pd repeat 10 [ | rt 54 fd 43.865 | lt 90 fd 45.002 | lt 108 fd 45.002 | lt 90 fd 43.865 | lt 90 | ] pu ht Nice. Reminds me of some things that we came up with when my kids and I were playing with logo. (We were using Atari 8-bit Logo, a product of LCSI, a company with which Seymour Papert was involved.) I had no trouble running it using Fedora's package. Some of those lengths look a bit, uhh, empirical. It's more fun if you don't start with cs and end with ht. Then you can iterate and get interesting effects. cs repeat 6 [load "stewarts-pattern.logo2 fd 30] cs repeat 2 [load "stewarts-pattern.logo2 fd 45.002] cs repeat 3 [load "stewarts-pattern.logo2 rt 10]
participants (4)
-
D. Hugh Redelmeier
-
Kevin Cozens
-
Stewart C. Russell
-
ted leslie