gcc inline keyword & inline assembler bug (FreeBSD i386 c-code)
Kristofer Sandlund
kristofer.sandlund@effnet.com
Fri Oct 5 06:48:00 GMT 2001
I seem to have located some strange bug in gcc 3.0.1, which I'll try to
describe below here.
BUG DESCRIPTION
----------------
The very simple program causing this bug basically just reads the time
stamp counter from a Pentium computer.
The program in question works fine in gcc 2.95.3, but when I switched to
gcc 3.0.1, the program generates segmentation fault during runtime of
the program (at the allocation at the end of the getTSC function
tsc->low = c_low;).
The bug is somehow cause by the use of the 'inline' keyword being used
on a function, even though I am not running the program with any -O
option. If I either remove the inline keyword or run with -O, then the
program works ok.
Seems like a very strange behaviour as the code generated without -O
should not even try to inline this. Possibly this could be a problem
with the inline assembler used, but that code does work with gcc 2.95.3,
so there must be some bug in gcc 3.0.1.
SYSTEM DETAILS:
--------------
Output from running the suggested gcc command:
prompt> /usr/local/bin/gcc -v -save-temps dum_bug.c
Reading specs from
/usr/local/lib/gcc-lib/i386-unknown-freebsd4.3/3.0.1/specs
Configured with: /tmp/gcc3/gcc-3.0.1/configure
Thread model: posix
gcc version 3.0.1
/usr/local/lib/gcc-lib/i386-unknown-freebsd4.3/3.0.1/cpp0 -lang-c -v
-D__GNUC__
=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=1 -D__FreeBSD__=4 -Dunix
-D__ELF__ -
D__FreeBSD__=4 -D__unix__ -D__ELF__ -D__unix -Asystem=unix -Asystem=bsd
-Asystem
=FreeBSD -D__NO_INLINE__ -D__STDC_HOSTED__=1 -Acpu=i386 -Amachine=i386
-Di386 -D
__i386 -D__i386__ -D__tune_i386__ dum_bug.c dum_bug.i
GNU CPP version 3.0.1 (cpplib) (i386 FreeBSD/ELF)
ignoring nonexistent directory
"/usr/local/i386-unknown-freebsd4.3/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/local/lib/gcc-lib/i386-unknown-freebsd4.3/3.0.1/include
/usr/include
End of search list.
/usr/local/lib/gcc-lib/i386-unknown-freebsd4.3/3.0.1/cc1 -fpreprocessed
dum_bug
.i -quiet -dumpbase dum_bug.c -version -o dum_bug.s
GNU CPP version 3.0.1 (cpplib) (i386 FreeBSD/ELF)
GNU C version 3.0.1 (i386-unknown-freebsd4.3)
compiled by GNU C version 3.0.1.
as --traditional-format -V -Qy -o dum_bug.o dum_bug.s
GNU assembler version 2.10.1 (i386-unknown-freebsd4) using BFD version
2.10.1
/usr/local/lib/gcc-lib/i386-unknown-freebsd4.3/3.0.1/collect2 -m
elf_i386 -V -d
ynamic-linker /usr/libexec/ld-elf.so.1 /usr/lib/crt1.o /usr/lib/crti.o
/usr/loca
l/lib/gcc-lib/i386-unknown-freebsd4.3/3.0.1/crtbegin.o
-L/usr/local/lib/gcc-lib/
i386-unknown-freebsd4.3/3.0.1
-L/usr/local/lib/gcc-lib/i386-unknown-freebsd4.3/3
.0.1/../../.. dum_bug.o -lgcc -lc -lgcc
/usr/local/lib/gcc-lib/i386-unknown-free
bsd4.3/3.0.1/crtend.o /usr/lib/crtn.o
GNU ld version 2.10.1 (with BFD 2.10.1)
Supported emulations:
elf_i386
prompt>
NOTE: I have also tried the same things on a debiam linux, with the
exact same results.
COMPILATION DETAILS:
--------------------
The preprocessed file is attached to this mail (dum_bug.i).
Example compilation gives no warnings:
prompt> gcc -o dum_bug dum_bug.c
prompt>
GCC was built with default options (configure, make bootstrap and make
install)
/Kristofer Sandlund, Effnet AB. (sandlund@effnet.com)
# 6 "dum_bug.c"
typedef struct {
unsigned int high;
unsigned int low;
} TSC_t;
inline void
getTSC(TSC_t *tsc) {
unsigned int c_high, c_low;
{
__asm__(
"\tCPUID\n"
"\tRDTSC\n"
:"=d" (c_high), "=a" (c_low)
);
}
tsc->low = c_low;
tsc->high = c_high;
}
int main() {
TSC_t a;
getTSC(&a);
return 0;
}
More information about the Gcc-bugs
mailing list