0

I was trying to get the fbounds checking to work, but I did not succeed. I get a following error:

/tmp/cczxKZzn.s: Assembler messages:

/tmp/cczxKZzn.s:48: Error: invalid instruction suffix for `push'

/tmp/cc9xD8T3.s:125: Error: invalid instruction suffix for `pop'

while my makefile looks like this (with simple makefile everything is compiling properly):

all: error check

error: error.c
    /usr/local/gcc-4.0.2/bin/gcc -fbounds-checking -g -Wall -pedantic $< -o $@

.PHONY: clean check

clean:
    -rm error

check:  error
    ./error

Since that code has nothing to do with assembler, I don't know what to do. Assembler problems are the only ones I can see in my google search on that topic.


Can You propose other solutions checking for example for being outside an array? Such as (this is my error.c):

#include <stdio.h>
#include <stdlib.h>
int main()
{
  int a[1][10];
  a[0][11]=42;
  return 0;
}

EDIT. Can it be a version incompatibility; gcc 4.4+ is installed and I'm doing that with path to a little modified gcc 4.0.2 ?

Community
  • 1
  • 1
Peter Cerba
  • 806
  • 4
  • 14
  • 26
  • There's no such thing as "fbounds". -f means "flag", so it's the bounds-check flag. – Jim Balter Aug 22 '12 at 22:01
  • @JimBalter after changing to "-bounds-check" it doesn't work as well. – Peter Cerba Aug 23 '12 at 08:56
  • I didn't say anything about changing it to "-bounds-check". Please read what I wrote again. It's "-f" + "bounds-check" = "-fbounds-check". The point is, as I said, that there's no such thing as "fbounds checking", which is what it says in your title. – Jim Balter Aug 23 '12 at 19:15

2 Answers2

1

Since that code has nothing to do with assembler, I don't know what to do. Assembler problems are the only ones I can see in my google search on that topic.

Looks like you're invoking the wrong assembler - a 32 bit one, trying to compile a 64bit object code. Check your PATHs and flags.

UPDATE: I never looked into how exactly gcc invokes its components. It's still not very clear to me. Anyway, it looks like it doesn't rely on PATH as I believed, but rather on its ./configure settings (--prefix, --build and so on).

Mine, with --prefix=/usr, --build=x86_64-suse-linux, --program-suffix=-4.6, looks for its components in (with respect to the directory where thegcc` binary resides: - ../lib64/gcc/x86_64-suse-linux/4.6 - ../lib64/gcc/ - ../lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/x86_64-suse-linux/4.6/ - ../lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/

(checked with strace).

Were a binary from another gcc present in one of those directories, it would get invoked instead of the 'correct' one.

Try checking with gcc -v (or with strace) to see which as is being run.

LSerni
  • 55,617
  • 10
  • 65
  • 107
  • The path shown in makefile is the one to the installed package (as it should be). What other paths to check? And how to check 'flags' ? Thanks in advance! – Peter Cerba Aug 22 '12 at 21:51
  • Seeing your edit, flags are probably OK, but I'm afraid that the invocation of the various "pieces" of the compiler might go to the wrong instance of `as`. Check the value of the PATH environment variable. In a pinch, temporarily place the bin directory of the desired gcc before anything else in your PATH. – LSerni Aug 22 '12 at 21:57
  • @Iserni None of my PATHs has any reference to gcc or assembly (I used printenv command) – Peter Cerba Aug 23 '12 at 08:58
  • I see. What is the result using the other, gcc 4.0? – LSerni Aug 23 '12 at 12:37
  • That is a long log from strace. I went directly to gcc 4.0.2 directory in /usr/local/ Providing [link](http://pastebin.com/uFbGmL14) – Peter Cerba Aug 23 '12 at 13:31
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15719/discussion-between-lserni-and-peter-kowalski) – LSerni Aug 23 '12 at 14:03
0

If someone still needs to run bounds checking with this ancient gcc version: The best you can do is to tell it to pass the relevant argument to the assembler with -Wa,--32, so you would need this:

error: error.c
    /usr/local/gcc-4.0.2/bin/gcc -fbounds-checking -Wa,--32 -g -Wall -pedantic $< -o $@

Background info: your ancient gcc generates 32 bit assembly while your modern assembler defaults to 64 bit. This is not a problem for most of the instructions as generally the 32 bit register operations are there in 64 bit mode, push and pop are exceptions: they do not support 32 bit operands in 64 bit mode.

dabadab
  • 388
  • 1
  • 10