Performance Tools for Software Developers - GNU compatibility: Attribute

Symbols with internal linkage only refer to the same object within a single source file. These symbols have local binding. A weak symbol behaves as does a global symbol, with a few differences. If there are both a weak and a global definition of a name, the global definition takes precedence and any weak definitions are ignored. The Linker will not extract archive members to resolve undefined weak symbols. It is not an error to have unresolved weak references; unresolved weak symbols have the value zero. Prefixing the declarations with the keyword static changes the linkage of external objects to internal linkage. The compiler previously silently applied the "weak" attribute to variables and routines with internal linkage. Now an error is issued in such cases. For example:

static __attribute__((weak)) int g; // Previously accepted. Now an error.

Example:

// main.cpp
//
// The symbol xglobal is vsisible outside module due to its external linkage
int xglobal = 5;
// the xglobal2 is visible only in the file it is defined due its internal linkage
static int xglobal2 = 20;
int __attribute__((weak)) x_weak = 10;

static int internal_g __attribute__((weak));
//foo() is weak symbol reference
extern int foo (void) __attribute__ ((weak));

int main ()
{
if (foo)
{
foo ();
}
int y=x_weak;
}

$ icc -c main.cpp
main.cpp(8): error: the "weak" attribute can only appear on functions and variables with external linkage
static int internal_g __attribute__((weak));
^
compilation aborted for main.cpp (code 2)

Operating System:

Red Hat* Linux, Red Hat* Desktop Linux* 3, Red Hat* Enterprise Linux Desktop 4, Red Hat* Desktop 3 Update 4, Red Hat* Enterprise Linux Desktop 3 Update 3, Red Hat* Enterprise Linux Desktop 3 Update 4, Red Hat* Enterprise Linux Desktop 3 Update 5, Red Hat* Enterprise Linux Desktop 4 Update 1, Red Hat* Enterprise Linux 2.1, SUSE* Linux 9.1, SUSE* Linux Enterprise Server 8.0, SUSE* Linux Enterprise Server 9.0, Red Hat* Enterprise Linux 4.0, Redhat* Desktop 3 Update 5, Redhat* Desktop 3 Update 6, Redhat* Desktop 3 Update 7, Redhat* Desktop 4 Update 2, Redhat* Desktop 4 Update 3, Redhat* Desktop 4 Update 4, SuSE* Linux* Enterprise* Desktop 10, SUSE* Linux Enterprise Server 10, Red Hat* Linux 6.2, Red Hat* Linux 6.2 SBE2, Red Hat* Linux 7.0, Red Hat* Linux 7.1, Red Hat* Linux 7.2, Red Hat* Linux 7.3, SUSE* Linux 7.3, SUSE* Linux 8.0, SUSE* Linux 8.1, Red Hat* Linux 8.0, SUSE* Linux 7.2, SUSE* Linux 7.1, SUSE* Linux 7.0, SUSE* Linux, Red Hat* Linux Advanced Server 2.x, Red Hat* Linux 9.0, Red Hat* Enterprise Linux 3.0, SU SE* Linux* 8.2, Red Hat* Linux Advanced Server 3.x, SUSE* Linux* 9.x
 
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.