Bug 143391 - "undefined reference to `a" is shown, when we run gcc with "-O2".
"undefined reference to `a" is shown, when we run gcc with "-O2".
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: gcc (Show other bugs)
4.0
ia64 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-12-20 05:52 EST by L3support
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-12-20 06:38:48 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description L3support 2004-12-20 05:52:09 EST
Description of problem:

When we run gcc with "-O2",
the following message is shown. 
------------------------------------
/tmp/ccQQ3lnD.o(.text+0x10): In function `geta':
: undefined reference to `a'
collect2: ld returned 1 exit status
------------------------------------

Our test program is as follows.(smp.c)
------------------------------------
<smp.c>
#include<stdio.h>


typedef unsigned int UINT32;

UINT32 geta(void);


static UINT32 a=3;
/* UINT32 a=5; */


UINT32 geta(void){
  __asm (
       "{alloc r19 = ar.pfs, 0,0,0,0;;\n\t"
       "nop.m 0\n\t"
       "nop.i 0};;\n\t"
       "{addl r18 = @ltoff(a#), r1\n\t"
       "nop.m 0\n\t"
       "nop.i 0};;\n\t"
       "{ld8 r18 = [r18]\n\t"
       "nop.m 0\n\t"
       "nop.i 0};;\n\t"
       "{ld4 r8 = [r18]\n\t"
       "nop.m 0\n\t"
       "nop.i 0};;\n\t"
       "br.ret.sptk.many b0;;\n\t"
       );
}

main(){
   UINT32 out;

   out = geta();
   printf("%08X\n",out);
}
------------------------------------

This compile error is caused by gcc's bug ?
Or it's feature of option "-O2" ? 

Temporarily, we run "# gcc -O2 -fno-unit-at-a-time smp.c", 
in order to avoid the error. 
Our act is right ?

[Having tried]
 (1) When we run gcc without option,
     there is no error.
     (# gcc smp.c)

 (2) We changed
     "static UINT32 a=3" in test program(smp.c) into "UINT32 a=5".
     There is no error.

Version-Release number of selected component (if applicable):
gcc-3.4.2-6.fc3

How reproducible:
Always

Steps to Reproduce:
1. # gcc -O2 smp.c
  
Actual results:

# gcc -O2 smp.c
/tmp/ccQQ3lnD.o(.text+0x10): In function `geta':
: undefined reference to `a'
collect2: ld returned 1 exit status

Expected results:

(1) This compile error is caused by gcc's bug ?
    Or it's feature of option "-O2" ? 
    ("a" is referred to only at inline assembler.)

(2) When is corrected gcc released ? (if gcc is bug) 

(3) Our act is right ?
    (avoid error by option "-fno-unit-at-a-time")

Additional info:
Comment 1 Jakub Jelinek 2004-12-20 06:38:48 EST
This is not a bug, but a new feature of GCC 3.4.x+.
GCC without -fno-unit-at-a-time discards unused static variables and functions.
The compiler doesn't know what inline assembly is doing, so you need to
tell the compiler about it.  There is a new attribute, __attribute__((used))
documented in info gcc:
`used'
     This attribute, attached to a function, means that code must be
     emitted for the function even if it appears that the function is
     not referenced.  This is useful, for example, when the function is
     referenced only in inline assembly.
and the same applies to variables.

Note You need to log in before you can comment on or make changes to this bug.