Bug 143391 - "undefined reference to `a" is shown, when we run gcc with "-O2".
Summary: "undefined reference to `a" is shown, when we run gcc with "-O2".
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: gcc
Version: 4.0
Hardware: ia64
OS: Linux
medium
medium
Target Milestone: ---
: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-12-20 10:52 UTC by L3support
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-12-20 11:38:48 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description L3support 2004-12-20 10:52:09 UTC
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 11:38:48 UTC
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.