[ECOS] Use of "__attribute__"

Bart Veer bartv@redhat.com
Wed Jun 13 03:00:00 GMT 2001


>>>>> "Stanley" == Ho Shui Choy Stanley PS03B NCS <scho@ncs.com.sg> writes:

    Stanley> I have a question on the usage of "__attribute__". So far
    Stanley> I am able to specify which section certain functions
    Stanley> reside in, using __attribute__ ((section
    Stanley> (".my_section"))). But I can't do the same for classes,
    Stanley> why?

A class is just a language abstraction. By itself it does not cause
anything to appear in the final executable.

A member function of a class does result in code, so you should be
able to use attributes on individual member functions to place those
functions in specific sections. 

Similarly, static member variables of a class end up in a data
section in the executable and it should be possible to use a section
attribute for this. The same applies for static instances of a class,
i.e. objects.

Because a typical class involves both code and data, it does not
really make sense to put an entire class into a single section.
Consider a ROM-booting system. The member functions should end up in
ROM, but any data should be in RAM. If they are all in the same
section then the linker has no way of knowing which should go where.

Note that I have not actually tried the above and it is possible that
there are lurking problems somewhere in the g++ front-end, but if you
are encountering difficulties putting e.g. a C++ member function into
a specific section I would need more details.

Bart



More information about the Ecos-discuss mailing list