This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

cin/cout as reference objects [Re: AIX I/O failures]


On Thu, 25 Jan 2001, Mark Mitchell wrote:
> The reference approach has a performance cost that
> the array-of-chars approach does not.

The array-of-chars approach has a performance and hidden abi cost that
the reference approach does not.

Consider libstdc++ used as a shared library on e.g. i686:

Normal application code is not PIC, and so does not use the .got, and
so any reference to a data variable is hard-coded by the linker to a
specific address.  If the symbol against which the reference was resolved
came from a shared library, in order to avoid a dynamic relocation 
against the read-only .text section, the linker reserves space in a
section called .dynbss, which is merged with the normal .bss.  The
linker then emits a dynamic relocation called R_386_COPY to have ld.so
copy the contents of the symbol at load time from the shared library
to the space reserved in the main application.

Note that space for the object is reserved at link time.  This means
that the size of the object, even if the API for that object only uses
its address, is now part of the ABI for that shared library.  You can't
add new stuff to the end of the object and remain compatible, since
there will not be room in the main application.

You should therefore be *extremely* cautious in exporting anything
from a shared library that isn't a function or a built-in type such
as a pointer.


r~

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]