Bug 14911 - static const symbols lost when referred in asm
Summary: static const symbols lost when referred in asm
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 15421 15517 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-04-10 12:52 UTC by Maurizio Monge
Modified: 2005-07-23 17:19 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maurizio Monge 2004-04-10 12:52:43 UTC
could not compile MPlayer with 3.4 prerelease :-( 
 
gcc -v : 
 Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.0/specs 
Configured with: ../configure --prefix=/usr --program-suffix=-3.4 --with-gnu-as 
--with-gnu-ld --with-cpu=i686 --enable-__cxa_atexit --enable-languages=c,c++ 
Thread model: posix 
gcc version 3.4.0 20040407 (prerelease) 
 
the follwing code: 
 
//------------BEGIN--------------- 
static const int hello = 56; 
int main() 
{ 
	asm( 
	"mov hello, %eax\n" 
	); 
	return 0; 
} 
//------------END----------------- 
 
compiles with  
 
gcc code.c 
 
but fails with 
 
gcc -O2 code.c 
/tmp/ccgUsUmb.o(.text+0xd): In function `main': 
: undefined reference to `hello' 
collect2: ld returned 1 exit status 
 
gcc 3.2.3 always works. 
 
Thanx
Comment 1 Andrew Pinski 2004-04-10 12:57:04 UTC
Invalid, you have to mark the static const as used if you are going to use it in asm.
Do the following:
static const int hello __attribute__((used)) = 56; 
Comment 2 Andrew Pinski 2004-04-22 11:50:48 UTC
Just to let you know that I hear that mplayer has not accepted a patch to fix this yet, here is a way to 
use the attribute for both 3.4.0 and above and 2.95.3:
#define ATTRIBUTE_USED
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >=4)
#undef ATTRIBUTE_USED
#define ATTRIBUTE_USED __attribute__((used))
#endif
static const int hello ATTRIBUTE_USED  = 56;
int main()
{
        asm(
        "mov hello, %eax\n"
        );
        return 0;
}
Comment 3 Andrew Pinski 2004-05-13 09:19:14 UTC
*** Bug 15421 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2004-05-18 08:26:32 UTC
*** Bug 15517 has been marked as a duplicate of this bug. ***