Discussion:
Changing the definition of -no-stl
Thiago Macieira
2011-08-21 12:37:02 UTC
Permalink
Hi everyone

I'd like to propose a change in the definition of the -no-stl flag in Qt 5,
which should still be present and not be the default.

Today's definition is:
"YO COMPILA' is so old that it can't deal with C++98"

and it's technically a lot of NIH and aversion to STL. I'd like to change it
to a more modern and embedded-friendly definition, based upon the G++
separation of its two C++ libraries:

if you use -no-stl and your system has a separate libsupc++ from
libstdc++, then neither Qt nor your application will not require linking
to libstdc++

(how you accomplish the linking is your business, you'll probably need to
change the mkspec, but once you do, it will link properly)

GCC's libsupc++ contains the C++ support functions and symbols, such as:

- the base typeinfos (e.g., typeid(int) and typeid(void *))
- operator new, operator new[], operator delete, operator delete[]
- hidden support functions like __cxa_throw, __cxa_guard_acquire,
__cxa_vec_new, __dynamic_cast, etc.
- a few types specified in the C++ language as a result of using the language
constructs, like std::bad_exception and std::bad_cast

Implications:

1) [remains] -fno-rtti -fno-exception are orthogonal concepts to STL. Using
them or not has no impact on the use or not of STL.

2) [remains] The current requirement that STL be used in Qt inline code only
remains: you must be able to link a QT_STL application with a QT_NO_STL Qt.

3) [remains but clarified] Using C++ headers that are C++ language headers is
fine, like #include <new>, but also #include <limits>

4) [changed] Using STL features that expand to inline-only code or no code
(like empty tag structs and typedefs) at all is also permitted without checks.
I'm thinking especially of #include <iterator>. That means you may need to
have the full C++ headers anyway, even if you have an embedded system where
you do separate the language support library from the rest.

5) [new] No support for compilers that don't support C++98. I'm looking at
you, Sun CC (without -stlport).

6) [new] Certain Qt inline features are allowed to be disabled if STL support
is disabled too. I'm thinking especially of the QtAlgorithms header: the
template algorithmic functions can be completely implemented in terms of
wrappers around the uglier STL functions. That said, certain more useful
algorithms might need non-STL implementations too, such as qStableSort.

7) [remains] Use of C++11 features is also limited by the -no-stl definition
the same way that C++98 features are: if the use of the feature requires code
not in libsupc++, it needs to be disabled under -no-stl.

8) [remains, corollary] Qt front-end API cannot require the use of STL. It can
and should provide STL compatibility, however.

Clarifying 2+4: use of C++98 STL features that are not functions, or are
inline functions that only call other inline functions is permitted anywhere,
under any circumstances. Use of STL features that result in non-inline
function calls is allowed only in Qt inline code, such that the call ends up
in the user application, not Qt. C++03, C++11 and TR1 features require extra
checks.

I'm just in doubt about the implications of that and 6: if we use qStableSort
internally, qStableSort is implemented on top of STL and that implementation
makes function calls.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
l***@nokia.com
2011-08-23 08:41:42 UTC
Permalink
Hi Thiago,

I like this. It clarifies what -no-stl means and actually makes it
realistic to use it for certain systems.

On 8/21/11 2:37 PM, "ext Thiago Macieira" <***@kde.org> wrote:
[snip]
Post by Thiago Macieira
I'm just in doubt about the implications of that and 6: if we use qStableSort
internally, qStableSort is implemented on top of STL and that
implementation
makes function calls.
I don't see this as a problem. We can simply have (actually: keep) our own
implementation of qStableSort that is being used when -no-stl is being set
at configure time. If STL support is enabled, we can use the STL algorithm
instead.

Lars
Thiago Macieira
2011-08-23 08:58:41 UTC
Permalink
Post by l***@nokia.com
Post by Thiago Macieira
I'm just in doubt about the implications of that and 6: if we use qStableSort
internally, qStableSort is implemented on top of STL and that
implementation
makes function calls.
I don't see this as a problem. We can simply have (actually: keep) our own
implementation of qStableSort that is being used when -no-stl is being set
at configure time. If STL support is enabled, we can use the STL algorithm
instead.
Hmm.... you're right. After rethinking a bit, I think I was making some
confusion on my own requirements, when I wrote the 2+4 clarification. When I
wrote that, I said that non-inline Qt code cannot ever call non-inline STL
code -- meaning that Qt libs would never link to libstdc++ if libsupc++ is
there.

But rereading what I proposed gives me now a different conclusion: if you don't
choose -no-stl (that is, if you choose QT_STL), then Qt is allowed to link to
libstdc++, the same way that a QT_STL application can link to it. The
requirement is that a -no-stl Qt doesn't link to it.

And the other requirement is that QT_STL be binary compatible with QT_NO_STL.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
Konstantin Tokarev
2011-08-23 09:00:51 UTC
Permalink
Post by Thiago Macieira
And the other requirement is that QT_STL be binary compatible with QT_NO_STL.
Could you explain why this requirement is needed?
--
Regards,
Konstantin
Thiago Macieira
2011-08-23 09:10:47 UTC
Permalink
Post by Konstantin Tokarev
Post by Thiago Macieira
And the other requirement is that QT_STL be binary compatible with QT_NO_STL.
Could you explain why this requirement is needed?
I think I could ask back: why not require it?

It's not difficult to have Qt be binary compatible in those two versions. All it
requires is that the Qt non-inline API never have anything that is disabled by
QT_NO_STL. That means all functions must be present if that is defined, which
in turn means no function can carry a non-inline STL type in their signature.

Tag types might be permitted, but in most cases tags exist for template and
inline code, so I don't think it's a problem.

The reason I personally want this is that I'd like to compile Qt without
#include'ing the STL headers everywhere. Nothing wrong with them -- they're
just non-trivial in size, meaning the compilation time is bigger. For someone
who needs to compile Qt several times a day and no longer has access to a nice
compile farm, this could come in very handy.

Moreover, imagine an embedded device that wants to save space in the minimal
base system: they could choose to compile Qt and all of their applications
without STL, thus saving a few hundred kilobytes of libstdc++. But user
applications could still use STL if they wanted and interoperate with Qt, only
triggering the install of that lib.

Finally, I've been reading the C++ ABI mailing list and there are several
teams there, from different compilers. They are cooperating to make the same
ABI between their compilers. That doesn't mean, however, that one compiler's
STL implementation works on another.

So a hypothetical scenario is that a device maker chooses to use a different
compiler for the base system, like RVCT for ARM devices, than the free
compiler that is offered to third-party users in the SDKs (normally GCC). The
STL implementations are incompatible, so they build the base system without
STL support, but GCC-built 3rd-party applications can use STL and interoperate
with Qt.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
l***@nokia.com
2011-08-23 09:18:57 UTC
Permalink
Agree with Thiago here. We can still drop the requirement later if it
turns out we can't easily do it for some reason.

Lars
Post by Thiago Macieira
Post by Konstantin Tokarev
Post by Thiago Macieira
And the other requirement is that QT_STL be binary compatible with QT_NO_STL.
Could you explain why this requirement is needed?
I think I could ask back: why not require it?
It's not difficult to have Qt be binary compatible in those two versions. All it
requires is that the Qt non-inline API never have anything that is disabled by
QT_NO_STL. That means all functions must be present if that is defined, which
in turn means no function can carry a non-inline STL type in their signature.
Tag types might be permitted, but in most cases tags exist for template and
inline code, so I don't think it's a problem.
The reason I personally want this is that I'd like to compile Qt without
#include'ing the STL headers everywhere. Nothing wrong with them -- they're
just non-trivial in size, meaning the compilation time is bigger. For someone
who needs to compile Qt several times a day and no longer has access to a nice
compile farm, this could come in very handy.
Moreover, imagine an embedded device that wants to save space in the minimal
base system: they could choose to compile Qt and all of their
applications
without STL, thus saving a few hundred kilobytes of libstdc++. But user
applications could still use STL if they wanted and interoperate with Qt, only
triggering the install of that lib.
Finally, I've been reading the C++ ABI mailing list and there are several
teams there, from different compilers. They are cooperating to make the same
ABI between their compilers. That doesn't mean, however, that one compiler's
STL implementation works on another.
So a hypothetical scenario is that a device maker chooses to use a different
compiler for the base system, like RVCT for ARM devices, than the free
compiler that is offered to third-party users in the SDKs (normally GCC). The
STL implementations are incompatible, so they build the base system without
STL support, but GCC-built 3rd-party applications can use STL and interoperate
with Qt.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
Marc Mutz
2011-09-22 07:08:02 UTC
Permalink
Hi Thiago,
Post by Thiago Macieira
Moreover, imagine an embedded device that wants to save space in the
minimal base system: they could choose to compile Qt and all of their
applications without STL, thus saving a few hundred kilobytes of libstdc++.
But user applications could still use STL if they wanted and interoperate
with Qt, only triggering the install of that lib.
I wonder: have you measured that the size wouldn't be _smaller_ if Qt used the
STL instead of its own container classes? :)

Here's an idea:
1. Make the QTL name-compatible with the STL (let's call this QtSTL)
2. Use the std::names instead of the QNames everywhere
(or make the namespace configurable).

Then users had an actual choice:
- If you want binary compatibility guarantees, and you don't trust your system
STL to maintain it, go with the QtSTL.
- Otherwise, pick any of the portable STLs that fit your needs:
- minimal code expansion (promised, at least): QtSTL, miniSTL (from MICO)
- maximum speed: system STL, EASTL, STLport,...

That way, you'd allow competition between the QtSTL and any other STL. And the
user would pick the one that best fit their needs instead of being forced to
always carry the QtSTL with them, even if the rest of the application uses
another STL.

You could even lay back and support only compilation against QtSTL officially,
I'm sure others would pick up the other STLs, if only you would add that
flexibility.

What do you think?

Thanks,
Marc
--
Marc Mutz <***@kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-Independent Software Solutions
Thiago Macieira
2011-09-22 08:08:46 UTC
Permalink
Post by l***@nokia.com
Hi Thiago,
Post by Thiago Macieira
Moreover, imagine an embedded device that wants to save space in the
minimal base system: they could choose to compile Qt and all of their
applications without STL, thus saving a few hundred kilobytes of libstdc++.
But user applications could still use STL if they wanted and interoperate
with Qt, only triggering the install of that lib.
I wonder: have you measured that the size wouldn't be _smaller_ if Qt used
the STL instead of its own container classes? :)
No, I haven't, because no one has volunteered so far to rewrite the containers
using STL.
Post by l***@nokia.com
1. Make the QTL name-compatible with the STL (let's call this QtSTL)
2. Use the std::names instead of the QNames everywhere
(or make the namespace configurable).
Here's another:
- rewrite the current Qt containers, using their current names, on top of
STL, keeping full source and behaviour compatibility (including reference
counting)
Post by l***@nokia.com
That way, you'd allow competition between the QtSTL and any other STL. And
the user would pick the one that best fit their needs instead of being
forced to always carry the QtSTL with them, even if the rest of the
application uses another STL.
I don't think we're interested in following STL requirements. At least, I am
not and I want to spend my time in things that aren't working, instead of
rewriting what is.

Your blog on the containers was very well written and pointed out many issues
that could be improved, sure. Rewriting the Qt containers with their current
API and behaviour as a reference-counting layer on top of STL could be the
best of both worlds.

Maybe for Qt 6.
Post by l***@nokia.com
What do you think?
Two STLs would never work. You have to pick one for the entire stack -- just
ask the Solaris / OpenSolaris / Nevada people.

Besides, we're under a guideline to keep source compatibility. Changing
*everything* to use STL, including STL behaviour, is a conversation non-
starter.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
André Pönitz
2011-09-22 08:09:57 UTC
Permalink
Post by l***@nokia.com
Hi Thiago,
Post by Thiago Macieira
Moreover, imagine an embedded device that wants to save space in the
minimal base system: they could choose to compile Qt and all of their
applications without STL, thus saving a few hundred kilobytes of libstdc++.
But user applications could still use STL if they wanted and interoperate
with Qt, only triggering the install of that lib.
I wonder: have you measured that the size wouldn't be _smaller_ if Qt used the
STL instead of its own container classes? :)
1. Make the QTL name-compatible with the STL (let's call this QtSTL)
2. Use the std::names instead of the QNames everywhere
(or make the namespace configurable).
[...]
Having the names in sync with the rest of Qt and "incompatible" convenience
functions like "contains()" are advantages of the Qt Containers. If you don't
need or want that, just use the Standard Library containers directly, today.

Andre'

Loading...