Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
c8619b90
Commit
c8619b90
authored
Jun 23, 2004
by
Nathan Sidwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* doc/extend.texi (Function Attributes): Alphabetize.
From-SVN: r83543
parent
a52a0a7f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
474 additions
and
457 deletions
+474
-457
gcc/ChangeLog
+5
-0
gcc/doc/extend.texi
+469
-457
No files found.
gcc/ChangeLog
View file @
c8619b90
2004-06-23 Nathan Sidwell <nathan@codesourcery.com>
* doc/extend.texi (Function Attributes): Alphabetize.
2004-06-23 Richard Henderson <rth@redhat.com>
2004-06-23 Richard Henderson <rth@redhat.com>
* c-gimplify.c (gimplify_decl_stmt): Update gimplify_type_sizes call.
* c-gimplify.c (gimplify_decl_stmt): Update gimplify_type_sizes call.
...
@@ -3107,6 +3111,7 @@
...
@@ -3107,6 +3111,7 @@
(expand_return): Don't check for possible tail recursion.
(expand_return): Don't check for possible tail recursion.
* tree.h (optimize_tail_recursion): Remove prototype.
* tree.h (optimize_tail_recursion): Remove prototype.
>>>>>>> 2.4079
2004-06-02 Jan Hubicka <jh@suse.cz>
2004-06-02 Jan Hubicka <jh@suse.cz>
* tree-cfg.c (tree_find_edge_insert_loc): Allow inserting before
* tree-cfg.c (tree_find_edge_insert_loc): Allow inserting before
...
...
gcc/doc/extend.texi
View file @
c8619b90
...
@@ -1913,90 +1913,39 @@ you may use @code{__noreturn__} instead of @code{noreturn}.
...
@@ -1913,90 +1913,39 @@ you may use @code{__noreturn__} instead of @code{noreturn}.
attributes.
attributes.
@table @code
@table @code
@cindex @code{noreturn} function attribute
@c Keep this table alphabetized by attribute name. Treat _ as space.
@item noreturn
A few standard library functions, such as @code{abort} and @code{exit},
cannot return. GCC knows this automatically. Some programs define
their own functions that never return. You can declare them
@code{noreturn} to tell the compiler this fact. For example,
@smallexample
@group
void fatal () __attribute__ ((noreturn));
void
fatal (/* @r{@dots{}} */)
@{
/* @r{@dots{}} */ /* @r{Print error message.} */ /* @r{@dots{}} */
exit (1);
@}
@end group
@end smallexample
The @code{noreturn} keyword tells the compiler to assume that
@code{fatal} cannot return. It can then optimize without regard to what
would happen if @code{fatal} ever did return. This makes slightly
better code. More importantly, it helps avoid spurious warnings of
uninitialized variables.
The @code{noreturn} keyword does not affect the exceptional path when that
applies: a @code{noreturn}-marked function may still return to the caller
by throwing an exception.
Do not assume that registers saved by the calling function are
restored before calling the @code{noreturn} function.
It does not make sense for a @code{noreturn} function to have a return
@item alias ("@var{target}")
type other than @code{void}.
@cindex @code{alias} attribute
The @code{alias} attribute causes the declaration to be emitted as an
The attribute @code{noreturn} is not implemented in GCC versions
alias for another symbol, which must be specified. For instance,
earlier than 2.5. An alternative way to declare that a function does
not return, which works in the current version and in some older
versions, is as follows:
@smallexample
@smallexample
typedef void voidfn ();
void __f () @{ /* @r{Do something.} */; @}
void f () __attribute__ ((weak, alias ("__f")));
volatile voidfn fatal;
@end smallexample
@end smallexample
@cindex @code{noinline} function attribut
e
declares @samp{f} to be a weak alias for @samp{__f}. In C++, th
e
@item noinline
mangled name for the target must be used.
This function attribute prevents a function from being considered for
inlining
.
Not all target machines support this attribute
.
@cindex @code{always_inline} function attribute
@item always_inline
@item always_inline
@cindex @code{always_inline} function attribute
Generally, functions are not inlined unless optimization is specified.
Generally, functions are not inlined unless optimization is specified.
For functions declared inline, this attribute inlines the function even
For functions declared inline, this attribute inlines the function even
if no optimization level was specified.
if no optimization level was specified.
@cindex @code{pure} function attribute
@item cdecl
@item pure
@cindex functions that do pop the argument stack on the 386
Many functions have no effects except the return value and their
@opindex mrtd
return value depends only on the parameters and/or global variables.
On the Intel 386, the @code{cdecl} attribute causes the compiler to
Such a function can be subject
assume that the calling function will pop off the stack space used to
to common subexpression elimination and loop optimization just as an
pass arguments. This is
arithmetic operator would be. These functions should be declared
useful to override the effects of the @option{-mrtd} switch.
with the attribute @code{pure}. For example,
@smallexample
int square (int) __attribute__ ((pure));
@end smallexample
@noindent
says that the hypothetical function @code{square} is safe to call
fewer times than the program says.
Some of common examples of pure functions are @code{strlen} or @code{memcmp}.
Interesting non-pure functions are functions with infinite loops or those
depending on volatile memory or other system resource, that may change between
two consecutive calls (such as @code{feof} in a multithreading environment).
The attribute @code{pure} is not implemented in GCC versions earlier
than 2.96.
@cindex @code{const} function attribute
@item const
@item const
@cindex @code{const} function attribute
Many functions do not examine any values except their arguments, and
Many functions do not examine any values except their arguments, and
have no effects except the return value. Basically this is just slightly
have no effects except the return value. Basically this is just slightly
more strict class than the @code{pure} attribute above, since function is not
more strict class than the @code{pure} attribute above, since function is not
...
@@ -2023,14 +1972,137 @@ extern const intfn square;
...
@@ -2023,14 +1972,137 @@ extern const intfn square;
This approach does not work in GNU C++ from 2.6.0 on, since the language
This approach does not work in GNU C++ from 2.6.0 on, since the language
specifies that the @samp{const} must be attached to the return value.
specifies that the @samp{const} must be attached to the return value.
@cindex @code{nothrow} function attribute
@item constructor
@item nothrow
@itemx destructor
The @code{nothrow} attribute is used to inform the compiler that a
@cindex @code{constructor} function attribute
function cannot throw an exception. For example, most functions in
@cindex @code{destructor} function attribute
the standard C library can be guaranteed not to throw an exception
The @code{constructor} attribute causes the function to be called
with the notable exceptions of @code{qsort} and @code{bsearch} that
automatically before execution enters @code{main ()}. Similarly, the
take function pointer arguments. The @code{nothrow} attribute is not
@code{destructor} attribute causes the function to be called
implemented in GCC versions earlier than 3.2.
automatically after @code{main ()} has completed or @code{exit ()} has
been called. Functions with these attributes are useful for
initializing data that will be used implicitly during the execution of
the program.
These attributes are not currently implemented for Objective-C@.
@item deprecated
@cindex @code{deprecated} attribute.
The @code{deprecated} attribute results in a warning if the function
is used anywhere in the source file. This is useful when identifying
functions that are expected to be removed in a future version of a
program. The warning also includes the location of the declaration
of the deprecated function, to enable users to easily find further
information about why the function is deprecated, or what they should
do instead. Note that the warnings only occurs for uses:
@smallexample
int old_fn () __attribute__ ((deprecated));
int old_fn ();
int (*fn_ptr)() = old_fn;
@end smallexample
results in a warning on line 3 but not line 2.
The @code{deprecated} attribute can also be used for variables and
types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
@item dllexport
@cindex @code{__declspec(dllexport)}
On Microsoft Windows targets the @code{dllexport} attribute causes the
compiler to provide a global pointer to a pointer in a dll, so that it
can be referenced with the @code{dllimport} attribute. The pointer name
is formed by combining @code{_imp__} and the function or variable name.
Currently, the @code{dllexport}attribute is ignored for inlined
functions, but export can be forced by using the
@option{-fkeep-inline-functions} flag. The attribute is also ignored for
undefined symbols.
When applied to C++ classes. the attribute marks defined non-inlined
member functions and static data members as exports. Static consts
initialized in-class are not marked unless they are also defined
out-of-class.
On cygwin, mingw and arm-pe targets, @code{__declspec(dllexport)} is
recognized as a synonym for @code{__attribute__ ((dllexport))} for
compatibility with other Microsoft Windows compilers.
Alternative methods for including the symbol in the dll'
s
export
table
are
to
use
a
.
def
file
with
an
@
code
{
EXPORTS
}
section
or
,
with
GNU
ld
,
using
the
@
option
{--
export
-
all
}
linker
flag
.
@
item
dllimport
@
cindex
@
code
{
__declspec
(
dllimport
)}
On
Microsoft
Windows
targets
,
the
@
code
{
dllimport
}
attribute
causes
the
compiler
to
reference
a
function
or
variable
via
a
global
pointer
to
a
pointer
that
is
set
up
by
the
Microsoft
Windows
dll
library
.
The
pointer
name
is
formed
by
combining
@
code
{
_imp__
}
and
the
function
or
variable
name
.
The
attribute
implies
@
code
{
extern
}
storage
.
Currently
,
the
attribute
is
ignored
for
inlined
functions
.
If
the
attribute
is
applied
to
a
symbol
@
emph
{
definition
},
an
error
is
reported
.
If
a
symbol
previously
declared
@
code
{
dllimport
}
is
later
defined
,
the
attribute
is
ignored
in
subsequent
references
,
and
a
warning
is
emitted
.
The
attribute
is
also
overridden
by
a
subsequent
declaration
as
@
code
{
dllexport
}.
When
applied
to
C
++
classes
,
the
attribute
marks
non
-
inlined
member
functions
and
static
data
members
as
imports
.
However
,
the
attribute
is
ignored
for
virtual
methods
to
allow
creation
of
vtables
using
thunks
.
On
cygwin
,
mingw
and
arm
-
pe
targets
,
@
code
{
__declspec
(
dllimport
)}
is
recognized
as
a
synonym
for
@
code
{
__attribute__
((
dllimport
))}
for
compatibility
with
other
Microsoft
Windows
compilers
.
The
use
of
the
@
code
{
dllimport
}
attribute
on
functions
is
not
necessary
,
but
provides
a
small
performance
benefit
by
eliminating
a
thunk
in
the
dll
.
The
use
of
the
@
code
{
dllimport
}
attribute
on
imported
variables
was
required
on
older
versions
of
GNU
ld
,
but
can
now
be
avoided
by
passing
the
@
option
{--
enable
-
auto
-
import
}
switch
to
ld
.
As
with
functions
,
using
the
attribute
for
a
variable
eliminates
a
thunk
in
the
dll
.
One
drawback
to
using
this
attribute
is
that
a
pointer
to
a
function
or
variable
marked
as
dllimport
cannot
be
used
as
a
constant
address
.
The
attribute
can
be
disabled
for
functions
by
setting
the
@
option
{-
mnop
-
fun
-
dllimport
}
flag
.
@
item
eightbit_data
@
cindex
eight
bit
data
on
the
H8
/
300
,
H8
/
300
H
,
and
H8S
Use
this
attribute
on
the
H8
/
300
,
H8
/
300
H
,
and
H8S
to
indicate
that
the
specified
variable
should
be
placed
into
the
eight
bit
data
section
.
The
compiler
will
generate
more
efficient
code
for
certain
operations
on
data
in
the
eight
bit
data
area
.
Note
the
eight
bit
data
area
is
limited
to
256
bytes
of
data
.
You
must
use
GAS
and
GLD
from
GNU
binutils
version
2.7
or
later
for
this
attribute
to
work
correctly
.
@
item
far
@
cindex
functions
which
handle
memory
bank
switching
On
68
HC11
and
68
HC12
the
@
code
{
far
}
attribute
causes
the
compiler
to
use
a
calling
convention
that
takes
care
of
switching
memory
banks
when
entering
and
leaving
a
function
.
This
calling
convention
is
also
the
default
when
using
the
@
option
{-
mlong
-
calls
}
option
.
On
68
HC12
the
compiler
will
use
the
@
code
{
call
}
and
@
code
{
rtc
}
instructions
to
call
and
return
from
a
function
.
On
68
HC11
the
compiler
will
generate
a
sequence
of
instructions
to
invoke
a
board
-
specific
routine
to
switch
the
memory
bank
and
call
the
real
function
.
The
board
-
specific
routine
simulates
a
@
code
{
call
}.
At
the
end
of
a
function
,
it
will
jump
to
a
board
-
specific
routine
instead
of
using
@
code
{
rts
}.
The
board
-
specific
return
routine
simulates
the
@
code
{
rtc
}.
@
item
fastcall
@
cindex
functions
that
pop
the
argument
stack
on
the
386
On
the
Intel
386
,
the
@
code
{
fastcall
}
attribute
causes
the
compiler
to
pass
the
first
two
arguments
in
the
registers
ECX
and
EDX
.
Subsequent
arguments
are
passed
on
the
stack
.
The
called
function
will
pop
the
arguments
off
the
stack
.
If
the
number
of
arguments
is
variable
all
arguments
are
pushed
on
the
stack
.
@
item
format
(@
var
{
archetype
},
@
var
{
string
-
index
},
@
var
{
first
-
to
-
check
})
@
item
format
(@
var
{
archetype
},
@
var
{
string
-
index
},
@
var
{
first
-
to
-
check
})
@
cindex
@
code
{
format
}
function
attribute
@
cindex
@
code
{
format
}
function
attribute
...
@@ -2131,138 +2203,67 @@ requested by @option{-ansi} or an appropriate @option{-std} option, or
...
@@ -2131,138 +2203,67 @@ requested by @option{-ansi} or an appropriate @option{-std} option, or
@
option
{-
ffreestanding
}
is
used
.
@
xref
{
C
Dialect
Options
,,
Options
@
option
{-
ffreestanding
}
is
used
.
@
xref
{
C
Dialect
Options
,,
Options
Controlling
C
Dialect
}.
Controlling
C
Dialect
}.
@item nonnull (@var{arg-index}, @dots{})
@
item
function_vector
@cindex @code{nonnull} function attribute
@
cindex
calling
functions
through
the
function
vector
on
the
H8
/
300
processors
The @code{nonnull} attribute specifies that some function parameters should
Use
this
attribute
on
the
H8
/
300
,
H8
/
300
H
,
and
H8S
to
indicate
that
the
specified
be non-null pointers. For instance, the declaration:
function
should
be
called
through
the
function
vector
.
Calling
a
function
through
the
function
vector
will
reduce
code
size
,
however
;
the
function
vector
has
a
limited
size
(
maximum
128
entries
on
the
H8
/
300
and
64
entries
on
the
H8
/
300
H
and
H8S
)
and
shares
space
with
the
interrupt
vector
.
@smallexample
You
must
use
GAS
and
GLD
from
GNU
binutils
version
2.7
or
later
for
extern void *
this
attribute
to
work
correctly
.
my_memcpy (void *dest, const void *src, size_t len)
__attribute__((nonnull (1, 2)));
@end smallexample
@noindent
@
item
interrupt
causes the compiler to check that, in calls to @code{my_memcpy},
@
cindex
interrupt
handler
functions
arguments @var{dest} and @var{src} are non-null. If the compiler
Use
this
attribute
on
the
ARM
,
AVR
,
C4x
,
M32R
/
D
and
Xstormy16
ports
to
indicate
determines that a null pointer is passed in an argument slot marked
that
the
specified
function
is
an
interrupt
handler
.
The
compiler
will
as non-null, and the @option{-Wnonnull} option is enabled, a warning
generate
function
entry
and
exit
sequences
suitable
for
use
in
an
is issued. The compiler may also choose to make optimizations based
interrupt
handler
when
this
attribute
is
present
.
on the knowledge that certain function arguments will not be null.
If no argument index list is given to the @code{nonnull} attribute,
Note
,
interrupt
handlers
for
the
m68k
,
H8
/
300
,
H8
/
300
H
,
H8S
,
and
SH
processors
all pointer arguments are marked as non-null. To illustrate, the
can
be
specified
via
the
@
code
{
interrupt_handler
}
attribute
.
following declaration is equivalent to the previous example:
@smallexample
Note
,
on
the
AVR
,
interrupts
will
be
enabled
inside
the
function
.
extern void *
my_memcpy (void *dest, const void *src, size_t len)
__attribute__((nonnull));
@end smallexample
@item no_instrument_function
@cindex @code{no_instrument_function} function attribute
@opindex finstrument-functions
If @option{-finstrument-functions} is given, profiling function calls will
be generated at entry and exit of most user-compiled functions.
Functions with this attribute will not be so instrumented.
@item section ("@var{section-name}")
@cindex @code{section} function attribute
Normally, the compiler places the code it generates in the @code{text} section.
Sometimes, however, you need additional sections, or you need certain
particular functions to appear in special sections. The @code{section}
attribute specifies that a function lives in a particular section.
For example, the declaration:
@smallexample
extern void foobar (void) __attribute__ ((section ("bar")));
@end smallexample
@noindent
puts the function @code{foobar} in the @code{bar} section.
Some file formats do not support arbitrary sections so the @code{section}
attribute is not available on all platforms.
If you need to map the entire contents of a module to a particular
section, consider using the facilities of the linker instead.
@item constructor
@itemx destructor
@cindex @code{constructor} function attribute
@cindex @code{destructor} function attribute
The @code{constructor} attribute causes the function to be called
automatically before execution enters @code{main ()}. Similarly, the
@code{destructor} attribute causes the function to be called
automatically after @code{main ()} has completed or @code{exit ()} has
been called. Functions with these attributes are useful for
initializing data that will be used implicitly during the execution of
the program.
These attributes are not currently implemented for Objective-C@.
@cindex @code{unused} attribute.
@item unused
This attribute, attached to a function, means that the function is meant
to be possibly unused. GCC will not produce a warning for this
function.
@cindex @code{used} attribute.
@item 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.
@cindex @code{deprecated} attribute.
Note
,
for
the
ARM
,
you
can
specify
the
kind
of
interrupt
to
be
handled
by
@item deprecated
adding
an
optional
parameter
to
the
interrupt
attribute
like
this
:
The @code{deprecated} attribute results in a warning if the function
is used anywhere in the source file. This is useful when identifying
functions that are expected to be removed in a future version of a
program. The warning also includes the location of the declaration
of the deprecated function, to enable users to easily find further
information about why the function is deprecated, or what they should
do instead. Note that the warnings only occurs for uses:
@
smallexample
@
smallexample
int old_fn () __attribute__ ((deprecated));
void
f
()
__attribute__
((
interrupt
(
"IRQ"
)));
int old_fn ();
int (*fn_ptr)() = old_fn;
@
end
smallexample
@
end
smallexample
results in a warning on line 3 but not line 2.
Permissible
values
for
this
parameter
are
:
IRQ
,
FIQ
,
SWI
,
ABORT
and
UNDEF
@.
The @code{deprecated} attribute can also be used for variables and
types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
@item warn_unused_result
@
item
interrupt_handler
@cindex @code{warn_unused_result} attribute
@
cindex
interrupt
handler
functions
on
the
m68k
,
H8
/
300
and
SH
processors
The @code{warn_unused_result} attribute causes a warning to be emitted
Use
this
attribute
on
the
m68k
,
H8
/
300
,
H8
/
300
H
,
H8S
,
and
SH
to
indicate
that
if a caller of the function with this attribute does not use its
the
specified
function
is
an
interrupt
handler
.
The
compiler
will
generate
return value. This is useful for functions where not checking
function
entry
and
exit
sequences
suitable
for
use
in
an
interrupt
the result is either a security problem or always a bug, such as
handler
when
this
attribute
is
present
.
@code{realloc}.
@smallexample
@
item
long_call
/
short_call
int fn () __attribute__ ((warn_unused_result));
@
cindex
indirect
calls
on
ARM
int foo ()
This
attribute
specifies
how
a
particular
function
is
called
on
@{
ARM
@.
Both
attributes
override
the
@
option
{-
mlong
-
calls
}
(@
pxref
{
ARM
Options
})
if (fn () < 0) return -1;
command
line
switch
and
@
code
{#
pragma
long_calls
}
settings
.
The
fn ();
@
code
{
long_call
}
attribute
causes
the
compiler
to
always
call
the
return 0;
function
by
first
loading
its
address
into
a
register
and
then
using
the
@}
contents
of
that
register
.
The
@
code
{
short_call
}
attribute
always
places
@end smallexample
the
offset
to
the
function
from
the
call
site
into
the
@
samp
{
BL
}
instruction
directly
.
results in warning on line 5.
@
item
longcall
/
shortcall
@
cindex
functions
called
via
pointer
on
the
RS
/
6000
and
PowerPC
On
the
RS
/
6000
and
PowerPC
,
the
@
code
{
longcall
}
attribute
causes
the
compiler
to
always
call
this
function
via
a
pointer
,
just
as
it
would
if
the
@
option
{-
mlongcall
}
option
had
been
specified
.
The
@
code
{
shortcall
}
attribute
causes
the
compiler
not
to
do
this
.
These
attributes
override
both
the
@
option
{-
mlongcall
}
switch
and
the
@
code
{#
pragma
longcall
}
setting
.
@item weak
@
xref
{
RS
/
6000
and
PowerPC
Options
},
for
more
information
on
whether
long
@cindex @code{weak} attribute
calls
are
necessary
.
The @code{weak} attribute causes the declaration to be emitted as a weak
symbol rather than a global. This is primarily useful in defining
library functions which can be overridden in user code, though it can
also be used with non-function declarations. Weak symbols are supported
for ELF targets, and also for a.out targets when using the GNU assembler
and linker.
@
item
malloc
@
item
malloc
@
cindex
@
code
{
malloc
}
attribute
@
cindex
@
code
{
malloc
}
attribute
...
@@ -2276,166 +2277,228 @@ long as the old pointer is never referred to (including comparing it
...
@@ -2276,166 +2277,228 @@ long as the old pointer is never referred to (including comparing it
to
the
new
pointer
)
after
the
function
returns
a
non
-@
code
{
NULL
}
to
the
new
pointer
)
after
the
function
returns
a
non
-@
code
{
NULL
}
value
.
value
.
@item alias ("@var{target}")
@
item
model
(@
var
{
model
-
name
})
@cindex @code{alias} attribute
@
cindex
function
addressability
on
the
M32R
/
D
The @code{alias} attribute causes the declaration to be emitted as an
@
cindex
variable
addressability
on
the
IA
-
64
alias for another symbol, which must be specified. For instance,
On
the
M32R
/
D
,
use
this
attribute
to
set
the
addressability
of
an
object
,
and
of
the
code
generated
for
a
function
.
The
identifier
@
var
{
model
-
name
}
is
one
of
@
code
{
small
},
@
code
{
medium
},
or
@
code
{
large
},
representing
each
of
the
code
models
.
Small
model
objects
live
in
the
lower
16
MB
of
memory
(
so
that
their
addresses
can
be
loaded
with
the
@
code
{
ld24
}
instruction
),
and
are
callable
with
the
@
code
{
bl
}
instruction
.
Medium
model
objects
may
live
anywhere
in
the
32
-
bit
address
space
(
the
compiler
will
generate
@
code
{
seth
/
add3
}
instructions
to
load
their
addresses
),
and
are
callable
with
the
@
code
{
bl
}
instruction
.
Large
model
objects
may
live
anywhere
in
the
32
-
bit
address
space
(
the
compiler
will
generate
@
code
{
seth
/
add3
}
instructions
to
load
their
addresses
),
and
may
not
be
reachable
with
the
@
code
{
bl
}
instruction
(
the
compiler
will
generate
the
much
slower
@
code
{
seth
/
add3
/
jl
}
instruction
sequence
).
On
IA
-
64
,
use
this
attribute
to
set
the
addressability
of
an
object
.
At
present
,
the
only
supported
identifier
for
@
var
{
model
-
name
}
is
@
code
{
small
},
indicating
addressability
via
``
small
''
(
22
-
bit
)
addresses
(
so
that
their
addresses
can
be
loaded
with
the
@
code
{
addl
}
instruction
).
Caveat
:
such
addressing
is
by
definition
not
position
independent
and
hence
this
attribute
must
not
be
used
for
objects
defined
by
shared
libraries
.
@
item
naked
@
cindex
function
without
a
prologue
/
epilogue
code
Use
this
attribute
on
the
ARM
,
AVR
,
C4x
and
IP2K
ports
to
indicate
that
the
specified
function
does
not
need
prologue
/
epilogue
sequences
generated
by
the
compiler
.
It
is
up
to
the
programmer
to
provide
these
sequences
.
@
item
near
@
cindex
functions
which
do
not
handle
memory
bank
switching
on
68
HC11
/
68
HC12
On
68
HC11
and
68
HC12
the
@
code
{
near
}
attribute
causes
the
compiler
to
use
the
normal
calling
convention
based
on
@
code
{
jsr
}
and
@
code
{
rts
}.
This
attribute
can
be
used
to
cancel
the
effect
of
the
@
option
{-
mlong
-
calls
}
option
.
@
item
no_instrument_function
@
cindex
@
code
{
no_instrument_function
}
function
attribute
@
opindex
finstrument
-
functions
If
@
option
{-
finstrument
-
functions
}
is
given
,
profiling
function
calls
will
be
generated
at
entry
and
exit
of
most
user
-
compiled
functions
.
Functions
with
this
attribute
will
not
be
so
instrumented
.
@
item
noinline
@
cindex
@
code
{
noinline
}
function
attribute
This
function
attribute
prevents
a
function
from
being
considered
for
inlining
.
@
item
nonnull
(@
var
{
arg
-
index
},
@
dots
{})
@
cindex
@
code
{
nonnull
}
function
attribute
The
@
code
{
nonnull
}
attribute
specifies
that
some
function
parameters
should
be
non
-
null
pointers
.
For
instance
,
the
declaration
:
@
smallexample
@
smallexample
void __f () @{ /* @r{Do something.} */; @}
extern
void
*
void f () __attribute__ ((weak, alias ("__f")));
my_memcpy
(
void
*
dest
,
const
void
*
src
,
size_t
len
)
__attribute__
((
nonnull
(
1
,
2
)));
@
end
smallexample
@
end
smallexample
declares @samp{f} to be a weak alias for @samp{__f}. In C++, the
@
noindent
mangled name for the target must be used.
causes
the
compiler
to
check
that
,
in
calls
to
@
code
{
my_memcpy
},
arguments
@
var
{
dest
}
and
@
var
{
src
}
are
non
-
null
.
If
the
compiler
Not all target machines support this attribute.
determines
that
a
null
pointer
is
passed
in
an
argument
slot
marked
as
non
-
null
,
and
the
@
option
{-
Wnonnull
}
option
is
enabled
,
a
warning
is
issued
.
The
compiler
may
also
choose
to
make
optimizations
based
on
the
knowledge
that
certain
function
arguments
will
not
be
null
.
@item visibility ("@var{visibility_type}")
If
no
argument
index
list
is
given
to
the
@
code
{
nonnull
}
attribute
,
@cindex @code{visibility} attribute
all
pointer
arguments
are
marked
as
non
-
null
.
To
illustrate
,
the
The @code{visibility} attribute on ELF targets causes the declaration
following
declaration
is
equivalent
to
the
previous
example
:
to be emitted with default, hidden, protected or internal visibility.
@
smallexample
@
smallexample
void __attribute__ ((visibility ("protected")))
extern
void
*
f () @{ /* @r{Do something.} */; @}
my_memcpy
(
void
*
dest
,
const
void
*
src
,
size_t
len
)
int i __attribute__ ((visibility ("hidden")
));
__attribute__
((
nonnull
));
@
end
smallexample
@
end
smallexample
See the ELF gABI for complete details, but the short story is:
@
item
noreturn
@
cindex
@
code
{
noreturn
}
function
attribute
A
few
standard
library
functions
,
such
as
@
code
{
abort
}
and
@
code
{
exit
},
cannot
return
.
GCC
knows
this
automatically
.
Some
programs
define
their
own
functions
that
never
return
.
You
can
declare
them
@
code
{
noreturn
}
to
tell
the
compiler
this
fact
.
For
example
,
@table @dfn
@
smallexample
@item default
@
group
Default visibility is the normal case for ELF. This value is
void
fatal
()
__attribute__
((
noreturn
));
available for the visibility attribute to override other options
that may change the assumed visibility of symbols.
@item hidden
void
Hidden visibility indicates that the symbol will not be placed into
fatal
(/*
@
r
{@
dots
{}}
*/)
the dynamic symbol table, so no other @dfn{module} (executable or
@{
shared library) can reference it directly.
/*
@
r
{@
dots
{}}
*/
/*
@
r
{
Print
error
message
.}
*/
/*
@
r
{@
dots
{}}
*/
exit
(
1
);
@}
@
end
group
@
end
smallexample
@item protected
The
@
code
{
noreturn
}
keyword
tells
the
compiler
to
assume
that
Protected visibility indicates that the symbol will be placed in the
@
code
{
fatal
}
cannot
return
.
It
can
then
optimize
without
regard
to
what
dynamic symbol table, but that references within the defining module
would
happen
if
@
code
{
fatal
}
ever
did
return
.
This
makes
slightly
will bind to the local symbol. That is, the symbol cannot be overridden
better
code
.
More
importantly
,
it
helps
avoid
spurious
warnings
of
by another module
.
uninitialized
variables
.
@item internal
The
@
code
{
noreturn
}
keyword
does
not
affect
the
exceptional
path
when
that
Internal visibility is like hidden visibility, but with additional
applies
:
a
@
code
{
noreturn
}-
marked
function
may
still
return
to
the
caller
processor specific semantics. Unless otherwise specified by the psABI,
by
throwing
an
exception
.
GCC defines internal visibility to mean that the function is @emph{never}
called from another module. Note that hidden symbols, while they cannot
be referenced directly by other modules, can be referenced indirectly via
function pointers. By indicating that a symbol cannot be called from
outside the module, GCC may for instance omit the load of a PIC register
since it is known that the calling function loaded the correct value.
@end table
Not all ELF targets support this attribute.
Do
not
assume
that
registers
saved
by
the
calling
function
are
restored
before
calling
the
@
code
{
noreturn
}
function
.
@item regparm (@var{number})
It
does
not
make
sense
for
a
@
code
{
noreturn
}
function
to
have
a
return
@cindex @code{regparm} attribute
type
other
than
@
code
{
void
}.
@cindex functions that are passed arguments in registers on the 386
On the Intel 386, the @code{regparm} attribute causes the compiler to
pass up to @var{number} integer arguments in registers EAX,
EDX, and ECX instead of on the stack. Functions that take a
variable number of arguments will continue to be passed all of their
arguments on the stack.
Beware that on some ELF systems this attribute is unsuitable for
The
attribute
@
code
{
noreturn
}
is
not
implemented
in
GCC
versions
global functions in shared libraries with lazy binding (which is the
earlier
than
2.5
.
An
alternative
way
to
declare
that
a
function
does
default). Lazy binding will send the first call via resolving code in
not
return
,
which
works
in
the
current
version
and
in
some
older
the loader, which might assume EAX, EDX and ECX can be clobbered, as
versions
,
is
as
follows
:
per the standard calling conventions. Solaris 8 is affected by this.
GNU systems with GLIBC 2.1 or higher, and FreeBSD, are believed to be
safe since the loaders there save all registers. (Lazy binding can be
disabled with the linker or the loader if desired, to avoid the
problem.)
@item stdcall
@
smallexample
@cindex functions that pop the argument stack on the 386
typedef
void
voidfn
();
On the Intel 386, the @code{stdcall} attribute causes the compiler to
assume that the called function will pop off the stack space used to
pass arguments, unless it takes a variable number of arguments.
@item fastcall
volatile
voidfn
fatal
;
@cindex functions that pop the argument stack on the 386
@
end
smallexample
On the Intel 386, the @code{fastcall} attribute causes the compiler to
pass the first two arguments in the registers ECX and EDX. Subsequent
arguments are passed on the stack. The called function will pop the
arguments off the stack. If the number of arguments is variable all
arguments are pushed on the stack.
@item cdecl
@
item
nothrow
@cindex functions that do pop the argument stack on the 386
@
cindex
@
code
{
nothrow
}
function
attribute
@opindex mrtd
The
@
code
{
nothrow
}
attribute
is
used
to
inform
the
compiler
that
a
On the Intel 386, the @code{cdecl} attribute causes the compiler to
function
cannot
throw
an
exception
.
For
example
,
most
functions
in
assume that the calling function will pop off the stack space used to
the
standard
C
library
can
be
guaranteed
not
to
throw
an
exception
pass arguments. This is
with
the
notable
exceptions
of
@
code
{
qsort
}
and
@
code
{
bsearch
}
that
useful to override the effects of the @option{-mrtd} switch.
take
function
pointer
arguments
.
The
@
code
{
nothrow
}
attribute
is
not
implemented
in
GCC
versions
earlier
than
3.2
.
@item
longcall/shortcall
@
item
pure
@cindex
functions called via pointer on the RS/6000 and PowerPC
@
cindex
@
code
{
pure
}
function
attribute
On the RS/6000 and PowerPC, the @code{longcall} attribute causes the
Many
functions
have
no
effects
except
the
return
value
and
their
compiler to always call this function via a pointer, just as it would if
return
value
depends
only
on
the
parameters
and
/
or
global
variables
.
the @option{-mlongcall} option had been specified. The @code{shortcall}
Such
a
function
can
be
subject
attribute causes the compiler not to do this. These attributes override
to
common
subexpression
elimination
and
loop
optimization
just
as
an
both the @option{-mlongcall} switch and the @code{#pragma longcall}
arithmetic
operator
would
be
.
These
functions
should
be
declared
setting.
with
the
attribute
@
code
{
pure
}.
For
example
,
@xref{RS/6000 and PowerPC Options}, for more information on whether long
@
smallexample
calls are necessary.
int
square
(
int
)
__attribute__
((
pure
));
@
end
smallexample
@item long_call/short_call
@
noindent
@cindex indirect calls on ARM
says
that
the
hypothetical
function
@
code
{
square
}
is
safe
to
call
This attribute specifies how a particular function is called on
fewer
times
than
the
program
says
.
ARM@. Both attributes override the @option{-mlong-calls} (@pxref{ARM Options})
command line switch and @code{#pragma long_calls} settings. The
@code{long_call} attribute causes the compiler to always call the
function by first loading its address into a register and then using the
contents of that register. The @code{short_call} attribute always places
the offset to the function from the call site into the @samp{BL}
instruction directly.
@item function_vector
Some
of
common
examples
of
pure
functions
are
@
code
{
strlen
}
or
@
code
{
memcmp
}.
@cindex calling functions through the function vector on the H8/300 processors
Interesting
non
-
pure
functions
are
functions
with
infinite
loops
or
those
Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
depending
on
volatile
memory
or
other
system
resource
,
that
may
change
between
function should be called through the function vector. Calling a
two
consecutive
calls
(
such
as
@
code
{
feof
}
in
a
multithreading
environment
).
function through the function vector will reduce code size, however;
the function vector has a limited size (maximum 128 entries on the H8/300
and 64 entries on the H8/300H and H8S) and shares space with the interrupt vector.
You must use GAS and GLD from GNU binutils version 2.7 or later fo
r
The
attribute
@
code
{
pure
}
is
not
implemented
in
GCC
versions
earlie
r
th
is attribute to work correctly
.
th
an
2.96
.
@item interrupt
@
item
regparm
(@
var
{
number
})
@cindex interrupt handler functions
@
cindex
@
code
{
regparm
}
attribute
Use this attribute on the ARM, AVR, C4x, M32R/D and Xstormy16 ports to indicate
@
cindex
functions
that
are
passed
arguments
in
registers
on
the
386
that the specified function is an interrupt handler. The compiler will
On
the
Intel
386
,
the
@
code
{
regparm
}
attribute
causes
the
compiler
to
generate function entry and exit sequences suitable for use in an
pass
up
to
@
var
{
number
}
integer
arguments
in
registers
EAX
,
interrupt handler when this attribute is present.
EDX
,
and
ECX
instead
of
on
the
stack
.
Functions
that
take
a
variable
number
of
arguments
will
continue
to
be
passed
all
of
their
arguments
on
the
stack
.
Note, interrupt handlers for the m68k, H8/300, H8/300H, H8S, and SH processors
Beware
that
on
some
ELF
systems
this
attribute
is
unsuitable
for
can be specified via the @code{interrupt_handler} attribute.
global
functions
in
shared
libraries
with
lazy
binding
(
which
is
the
default
).
Lazy
binding
will
send
the
first
call
via
resolving
code
in
the
loader
,
which
might
assume
EAX
,
EDX
and
ECX
can
be
clobbered
,
as
per
the
standard
calling
conventions
.
Solaris
8
is
affected
by
this
.
GNU
systems
with
GLIBC
2.1
or
higher
,
and
FreeBSD
,
are
believed
to
be
safe
since
the
loaders
there
save
all
registers
.
(
Lazy
binding
can
be
disabled
with
the
linker
or
the
loader
if
desired
,
to
avoid
the
problem
.)
Note, on the AVR, interrupts will be enabled inside the function.
@
item
saveall
@
cindex
save
all
registers
on
the
H8
/
300
,
H8
/
300
H
,
and
H8S
Use
this
attribute
on
the
H8
/
300
,
H8
/
300
H
,
and
H8S
to
indicate
that
all
registers
except
the
stack
pointer
should
be
saved
in
the
prologue
regardless
of
whether
they
are
used
or
not
.
Note, for the ARM, you can specify the kind of interrupt to be handled by
@
item
section
(
"@var{section-name}"
)
adding an optional parameter to the interrupt attribute like this:
@
cindex
@
code
{
section
}
function
attribute
Normally
,
the
compiler
places
the
code
it
generates
in
the
@
code
{
text
}
section
.
Sometimes
,
however
,
you
need
additional
sections
,
or
you
need
certain
particular
functions
to
appear
in
special
sections
.
The
@
code
{
section
}
attribute
specifies
that
a
function
lives
in
a
particular
section
.
For
example
,
the
declaration
:
@
smallexample
@
smallexample
void f () __attribute__ ((interrupt ("IRQ
")));
extern
void
foobar
(
void
)
__attribute__
((
section
(
"bar
"
)));
@
end
smallexample
@
end
smallexample
Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF@.
@
noindent
puts
the
function
@
code
{
foobar
}
in
the
@
code
{
bar
}
section
.
@item interrupt_handler
Some
file
formats
do
not
support
arbitrary
sections
so
the
@
code
{
section
}
@cindex interrupt handler functions on the m68k, H8/300 and SH processors
attribute
is
not
available
on
all
platforms
.
Use this attribute on the m68k, H8/300, H8/300H, H8S, and SH to indicate that
If
you
need
to
map
the
entire
contents
of
a
module
to
a
particular
the specified function is an interrupt handler. The compiler will generate
section
,
consider
using
the
facilities
of
the
linker
instead
.
function entry and exit sequences suitable for use in an interrupt
handler when this attribute is present.
@
item
short_call
See
long_call
/
short_call
.
@
item
shortcall
See
longcall
/
shortcall
.
@
item
signal
@
cindex
signal
handler
functions
on
the
AVR
processors
Use
this
attribute
on
the
AVR
to
indicate
that
the
specified
function
is
a
signal
handler
.
The
compiler
will
generate
function
entry
and
exit
sequences
suitable
for
use
in
a
signal
handler
when
this
attribute
is
present
.
Interrupts
will
be
disabled
inside
the
function
.
@
item
sp_switch
@
item
sp_switch
Use
this
attribute
on
the
SH
to
indicate
an
@
code
{
interrupt_handler
}
Use
this
attribute
on
the
SH
to
indicate
an
@
code
{
interrupt_handler
}
...
@@ -2449,21 +2512,11 @@ void f () __attribute__ ((interrupt_handler,
...
@@ -2449,21 +2512,11 @@ void f () __attribute__ ((interrupt_handler,
sp_switch
(
"alt_stack"
)));
sp_switch
(
"alt_stack"
)));
@
end
smallexample
@
end
smallexample
@item trap_exit
@
item
stdcall
Use this attribute on the SH for an @code{interrupt_handler} to return using
@
cindex
functions
that
pop
the
argument
stack
on
the
386
@code{trapa} instead of @code{rte}. This attribute expects an integer
On
the
Intel
386
,
the
@
code
{
stdcall
}
attribute
causes
the
compiler
to
argument specifying the trap number to be used.
assume
that
the
called
function
will
pop
off
the
stack
space
used
to
pass
arguments
,
unless
it
takes
a
variable
number
of
arguments
.
@item eightbit_data
@cindex eight bit data on the H8/300, H8/300H, and H8S
Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
variable should be placed into the eight bit data section.
The compiler will generate more efficient code for certain operations
on data in the eight bit data area. Note the eight bit data area is limited to
256 bytes of data.
You must use GAS and GLD from GNU binutils version 2.7 or later for
this attribute to work correctly.
@
item
tiny_data
@
item
tiny_data
@
cindex
tiny
data
section
on
the
H8
/
300
H
and
H8S
@
cindex
tiny
data
section
on
the
H8
/
300
H
and
H8S
...
@@ -2473,139 +2526,98 @@ The compiler will generate more efficient code for loads and stores
...
@@ -2473,139 +2526,98 @@ The compiler will generate more efficient code for loads and stores
on
data
in
the
tiny
data
section
.
Note
the
tiny
data
area
is
limited
to
on
data
in
the
tiny
data
section
.
Note
the
tiny
data
area
is
limited
to
slightly
under
32
kbytes
of
data
.
slightly
under
32
kbytes
of
data
.
@item saveall
@
item
trap_exit
@cindex save all registers on the H8/300, H8/300H, and H8S
Use
this
attribute
on
the
SH
for
an
@
code
{
interrupt_handler
}
to
return
using
Use this attribute on the H8/300, H8/300H, and H8S to indicate that
@
code
{
trapa
}
instead
of
@
code
{
rte
}.
This
attribute
expects
an
integer
all registers except the stack pointer should be saved in the prologue
argument
specifying
the
trap
number
to
be
used
.
regardless of whether they are used or not.
@item signal
@cindex signal handler functions on the AVR processors
Use this attribute on the AVR to indicate that the specified
function is a signal handler. The compiler will generate function
entry and exit sequences suitable for use in a signal handler when this
attribute is present. Interrupts will be disabled inside the function.
@item naked
@cindex function without a prologue/epilogue code
Use this attribute on the ARM, AVR, C4x and IP2K ports to indicate that the
specified function does not need prologue/epilogue sequences generated by
the compiler. It is up to the programmer to provide these sequences.
@item model (@var{model-name})
@cindex function addressability on the M32R/D
@cindex variable addressability on the IA-64
On the M32R/D, use this attribute to set the addressability of an
object, and of the code generated for a function. The identifier
@var{model-name} is one of @code{small}, @code{medium}, or
@code{large}, representing each of the code models.
Small model objects live in the lower 16MB of memory (so that their
addresses can be loaded with the @code{ld24} instruction), and are
callable with the @code{bl} instruction.
Medium model objects may live anywhere in the 32-bit address space (the
compiler will generate @code{seth/add3} instructions to load their addresses),
and are callable with the @code{bl} instruction.
Large model objects may live anywhere in the 32-bit address space (the
compiler will generate @code{seth/add3} instructions to load their addresses),
and may not be reachable with the @code{bl} instruction (the compiler will
generate the much slower @code{seth/add3/jl} instruction sequence).
On IA-64, use this attribute to set the addressability of an object.
@
item
unused
At present, the only supported identifier for @var{model-name} is
@
cindex
@
code
{
unused
}
attribute
.
@code{small}, indicating addressability via ``small'' (22-bit)
This
attribute
,
attached
to
a
function
,
means
that
the
function
is
meant
addresses (so that their addresses can be loaded with the @code{addl}
to
be
possibly
unused
.
GCC
will
not
produce
a
warning
for
this
instruction). Caveat: such addressing is by definition not position
function
.
independent and hence this attribute must not be used for objects
defined by shared libraries.
@item
far
@
item
used
@cindex
functions which handle memory bank switching
@
cindex
@
code
{
used
}
attribute
.
On 68HC11 and 68HC12 the @code{far} attribute causes the compiler to
This
attribute
,
attached
to
a
function
,
means
that
code
must
be
emitted
use a calling convention that takes care of switching memory banks when
for
the
function
even
if
it
appears
that
the
function
is
not
referenced
.
entering and leaving a function. This calling convention is also the
This
is
useful
,
for
example
,
when
the
function
is
referenced
only
in
default when using the @option{-mlong-calls} option
.
inline
assembly
.
On 68HC12 the compiler will use the @code{call} and @code{rtc} instructions
@
item
visibility
(
"@var{visibility_type}"
)
to call and return from a function.
@
cindex
@
code
{
visibility
}
attribute
The
@
code
{
visibility
}
attribute
on
ELF
targets
causes
the
declaration
to
be
emitted
with
default
,
hidden
,
protected
or
internal
visibility
.
On 68HC11 the compiler will generate a sequence of instructions
@
smallexample
to invoke a board-specific routine to switch the memory bank and call the
void
__attribute__
((
visibility
(
"protected"
)))
real function. The board-specific routine simulates a @code{call}.
f
()
@{
/*
@
r
{
Do
something
.}
*/;
@}
At the end of a function, it will jump to a board-specific routine
int
i
__attribute__
((
visibility
(
"hidden"
)));
instead of using @code{rts}. The board-specific return routine simulates
@
end
smallexample
the @code{rtc}.
@item near
See
the
ELF
gABI
for
complete
details
,
but
the
short
story
is
:
@cindex functions which do not handle memory bank switching on 68HC11/68HC12
On 68HC11 and 68HC12 the @code{near} attribute causes the compiler to
use the normal calling convention based on @code{jsr} and @code{rts}.
This attribute can be used to cancel the effect of the @option{-mlong-calls}
option.
@item dllimport
@
table
@
dfn
@cindex @code{__declspec(dllimport)}
@
c
keep
this
list
of
visibilies
in
alphabetical
order
.
On Microsoft Windows targets, the @code{dllimport} attribute causes the compiler
to reference a function or variable via a global pointer to a pointer
that is set up by the Microsoft Windows dll library. The pointer name is formed by
combining @code{_imp__} and the function or variable name. The attribute
implies @code{extern} storage.
Currently, the attribute is ignored for inlined functions. If the
@
item
default
attribute is applied to a symbol @emph{definition}, an error is reported.
Default
visibility
is
the
normal
case
for
ELF
.
This
value
is
If a symbol previously declared @code{dllimport} is later defined, the
available
for
the
visibility
attribute
to
override
other
options
attribute is ignored in subsequent references, and a warning is emitted.
that
may
change
the
assumed
visibility
of
symbols
.
The attribute is also overridden by a subsequent declaration as
@code{dllexport}.
When applied to C++ classes, the attribute marks non-inlined
@
item
hidden
member functions and static data members as imports. However, the
Hidden
visibility
indicates
that
the
symbol
will
not
be
placed
into
attribute is ignored for virtual methods to allow creation of vtables
the
dynamic
symbol
table
,
so
no
other
@
dfn
{
module
}
(
executable
or
using thunks
.
shared
library
)
can
reference
it
directly
.
On cygwin, mingw and arm-pe targets, @code{__declspec(dllimport)} is
@
item
internal
recognized as a synonym for @code{__attribute__ ((dllimport))} for
Internal
visibility
is
like
hidden
visibility
,
but
with
additional
compatibility with other Microsoft Windows compilers.
processor
specific
semantics
.
Unless
otherwise
specified
by
the
psABI
,
GCC
defines
internal
visibility
to
mean
that
the
function
is
@
emph
{
never
}
called
from
another
module
.
Note
that
hidden
symbols
,
while
they
cannot
be
referenced
directly
by
other
modules
,
can
be
referenced
indirectly
via
function
pointers
.
By
indicating
that
a
symbol
cannot
be
called
from
outside
the
module
,
GCC
may
for
instance
omit
the
load
of
a
PIC
register
since
it
is
known
that
the
calling
function
loaded
the
correct
value
.
The use of the @code{dllimport} attribute on functions is not necessary,
@
item
protected
but provides a small performance benefit by eliminating a thunk in the
Protected
visibility
indicates
that
the
symbol
will
be
placed
in
the
dll. The use of the @code{dllimport} attribute on imported variables was
dynamic
symbol
table
,
but
that
references
within
the
defining
module
required on older versions of GNU ld, but can now be avoided by passing
will
bind
to
the
local
symbol
.
That
is
,
the
symbol
cannot
be
overridden
the @option{--enable-auto-import} switch to ld. As with functions, using
by
another
module
.
the attribute for a variable eliminates a thunk in the dll.
One drawback to using this attribute is that a pointer to a function or
@
end
table
variable marked as dllimport cannot be used as a constant address. The
attribute can be disabled for functions by setting the
@option{-mnop-fun-dllimport} flag.
@item dllexport
Not
all
ELF
targets
support
this
attribute
.
@cindex @code{__declspec(dllexport)}
On Microsoft Windows targets the @code{dllexport} attribute causes the compiler to
provide a global pointer to a pointer in a dll, so that it can be
referenced with the @code{dllimport} attribute. The pointer name is
formed by combining @code{_imp__} and the function or variable name.
Currently, the @code{dllexport}attribute is ignored for inlined
@
item
warn_unused_result
functions, but export can be forced by using the
@
cindex
@
code
{
warn_unused_result
}
attribute
@option{-fkeep-inline-functions} flag. The attribute is also ignored for
The
@
code
{
warn_unused_result
}
attribute
causes
a
warning
to
be
emitted
undefined symbols.
if
a
caller
of
the
function
with
this
attribute
does
not
use
its
return
value
.
This
is
useful
for
functions
where
not
checking
the
result
is
either
a
security
problem
or
always
a
bug
,
such
as
@
code
{
realloc
}.
When applied to C++ classes. the attribute marks defined non-inlined
@
smallexample
member functions and static data members as exports. Static consts
int
fn
()
__attribute__
((
warn_unused_result
));
initialized in-class are not marked unless they are also defined
int
foo
()
out-of-class.
@{
if
(
fn
()
<
0
)
return
-
1
;
fn
();
return
0
;
@}
@
end
smallexample
On cygwin, mingw and arm-pe targets, @code{__declspec(dllexport)} is
results
in
warning
on
line
5.
recognized as a synonym for @code{__attribute__ ((dllexport))} for
compatibility with other Microsoft Windows compilers.
Alternative methods for including the symbol in the dll'
s
export
table
@
item
weak
are
to
use
a
.
def
file
with
an
@
code
{
EXPORTS
}
section
or
,
with
GNU
ld
,
@
cindex
@
code
{
weak
}
attribute
using
the
@
option
{--
export
-
all
}
linker
flag
.
The
@
code
{
weak
}
attribute
causes
the
declaration
to
be
emitted
as
a
weak
symbol
rather
than
a
global
.
This
is
primarily
useful
in
defining
library
functions
which
can
be
overridden
in
user
code
,
though
it
can
also
be
used
with
non
-
function
declarations
.
Weak
symbols
are
supported
for
ELF
targets
,
and
also
for
a
.
out
targets
when
using
the
GNU
assembler
and
linker
.
@
end
table
@
end
table
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment