gcc path?

Linux specific questions.
Post Reply
watchdogtimer
Posts: 4
Joined: Jul 20, 2016 10:14

gcc path?

Post by watchdogtimer »

I am attempting to compile the Great Cow BASIC compiler, which has FreeBASIC as a dependency.

On my Raspberry Pi 2, it compiles successfully:

Code: Select all

Compiling GCBASIC Version 0.95.007, Release 2016-06-26

FreeBASIC Compiler - Version 1.06.0 (04-30-2016), built for linux-arm (32bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
target:       linux-arm, armv7-a, 32bit
compiling:    gcbasic.bas -o gcbasic.c (main module)
compiling C:  gcc -march=native -S -nostdlib -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables "gcbasic.c" -o "gcbasic.asm"
assembling:   as --strip-local-absolute "gcbasic.asm" -o "gcbasic.o"
linking:      ld -m armelf_linux_eabi -o "gcbasic" -dynamic-linker /lib/ld-linux-armhf.so.3 "/usr/local/bin/../lib/freebasic/linux-arm/fbextra.x" -s -L "/usr/local/bin/../lib/freebasic/linux-arm" -L "." -L "/usr/lib/gcc/arm-linux-gnueabihf/4.9" "/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/crt1.o" "/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/crti.o" "/usr/lib/gcc/arm-linux-gnueabihf/4.9/crtbegin.o" "/usr/local/bin/../lib/freebasic/linux-arm/fbrt0.o" "gcbasic.o" "-(" -lfb -ltinfo -lm -ldl -lpthread -lgcc -lgcc_eh -lc "-)" "/usr/lib/gcc/arm-linux-gnueabihf/4.9/crtend.o" "/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/crtn.o" 
-e 
Compiled successfully.
On my Raspberry Pi 3, it does not:

Code: Select all

Compiling GCBASIC Version 0.95.007, Release 2016-06-26

FreeBASIC Compiler - Version 1.06.0 (06-03-2016), built for linux-arm (32bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
target:       linux-arm, armv7-a, 32bit
compiling:    gcbasic.bas -o gcbasic.c (main module)
compiling C:  /usr/bin/../bin/gcc -march=native -S -nostdlib -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables "gcbasic.c" -o "gcbasic.asm"
*** Error in `/usr/bin/../bin/gcc': double free or corruption (top): 0x00a6a060 ***
gcbasic.bas() error 90: Executable not found: "/usr/bin/../bin/gcc"
The only differences I can determine are the date of the FreeBASIC compiler releases and how 'gcc' is called.

Why does FreeBASIC use 'gcc' on the 'compiling C' step on the Raspberry Pi 2, but '/usr/bin/../bin/gcc' on the Raspberry Pi 3? Would this be the cause of the problem? How can I get the compiler to only call gcc using 'gcc'? On both computers, gcc is at /usr/bin/gcc. TIA,

-Jim
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: gcc path?

Post by dkl »

Hi,

fbc will use the absolute path to gcc if gcc is found next to the fbc executable (e.g. /usr/bin/fbc and /usr/bin/gcc). In other words, if gcc is found inside fbc's installation directory.

On the other hand, fbc will fallback to just "gcc" without path prefix if it couldn't find the gcc executable. In this case gcc will be searched in the PATH environment variable (e.g. /usr/local/bin/fbc and /usr/bin/gcc).

---

This message looks like a bug in that gcc though:
*** Error in `/usr/bin/../bin/gcc': double free or corruption (top): 0x00a6a060 ***
You could try invoking fbc with -R to get the intermediate .c file, then compile that manually to an .o with gcc using the same options, and check whether that causes the same error message from gcc.

I think the "executable not found" message from fbc following after the gcc error is a false-positive caused by weird exit code when trying to run gcc (because gcc failed with that error).
watchdogtimer
Posts: 4
Joined: Jul 20, 2016 10:14

Re: gcc path?

Post by watchdogtimer »

I tried your suggestion of invoking gcc with the -R option, then compiling the .c file with gcc. I got the same error, only a different address:

Code: Select all

pi@rpi3: fbc -R -exx -v -arch native -R gcbasic.bas
FreeBASIC Compiler - Version 1.06.0 (07-19-2016), built for linux-arm (32bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
target:       linux-arm, armv7-a, 32bit
compiling:    gcbasic.bas -o gcbasic.c (main module)
compiling C:  gcc -march=native -S -nostdlib -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables "gcbasic.c" -o "gcbasic.asm"
*** Error in `gcc': double free or corruption (top): 0x00605060 ***
gcbasic.bas() error 90: Executable not found: "gcc"

Code: Select all

pi@rpi3: gcc -march=native -S -nostdlib -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables "gcbasic.c" -o "gcbasic.asm"
*** Error in `gcc': double free or corruption (top): 0x008c0060 ***
Any suggestion of where to go from here? I've tried uninstalling and reinstalling both fbc (from source) and GCC (from the Debian repository).

This install script has worked for me on both a Raspberry Pi 2 and an Orange Pi Plus 2, but not a Raspberry Pi 3. All are ARMv7 devices.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: gcc path?

Post by dkl »

Can that gcc compile a hello world C program? I'd hope that that works, at least. Similar to that, does it work if you compile a hello world FB program?

Maybe it just doesn't like some of the command line options used by fbc, or some of the code in the .c file... Does it work if you just compile with less command line options? For example:

Code: Select all

gcc -S "gcbasic.c" -o "gcbasic.asm"
In any case it would be helpful to try and figure out what makes gcc crash here. Or if it's an old gcc, try to upgrade to a new version.
watchdogtimer
Posts: 4
Joined: Jul 20, 2016 10:14

Re: gcc path?

Post by watchdogtimer »

Thanks for all your help. I was finally able to get it to compile correctly by remove the '-arch native' flag.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: gcc path?

Post by counting_pine »

It might be helpful to gcc if we can find a reproducable bug in a version of their compiler.

What does each version say when you pass it the --version flag?

Also, what version of Linux is each Pi running? (I think 'cat /etc/*elease' tends to find it for most common distros.)
Post Reply