Commit Graph

150 Commits

Author SHA1 Message Date
Ed Schouten f4ac884f2b Make the presence of stdin and stdout optional.
The idea behind Nuxi CloudABI is that it is targeted at (but not limited to)
running networked services in a sandboxed environment. The model behind stdin,
stdout and stderr is strongly focused on interactive tools in a command shell.
CloudABI does not support the notion of stdin and stdout, as 'standard
input/output' does not apply to services. The concept of stderr does makes
sense though, as services do need some mechanism to log error messages in a
uniform way.

This patch extends libc++ in such a way that std::cin and std::cout and the
associated <cstdio>/<cwchar> functions can be disabled through the flags
_LIBCPP_HAS_NO_STDIN and _LIBCPP_HAS_NO_STDOUT, respectively. At the same time
it attempts to clean up src/iostream.cpp a bit. Instead of using a single array
of mbstate_t objects and hardcoding the array indices, it creates separate
objects that declared next to the iostream objects and their buffers. The code
is also restructured by interleaving the construction and setup of c* and wc*
objects. That way it is more obvious that this is done identically.

The c* and wc* objects already have separate unit tests. Make use of this fact
by adding XFAILs in case libcpp-has-no-std* is set. That way the tests work in
both directions. If stdin or stdout is disabled, these tests will therefore
test for the absence of c* and wc*.

Differential Revision:	http://reviews.llvm.org/D8340

llvm-svn: 233275
2015-03-26 14:35:46 +00:00
Marshall Clow 2d832d2429 Define a new macro: _LIBCPP_HAS_NO_VARIABLE_TEMPLATES and use it. No functionality change.
llvm-svn: 232493
2015-03-17 15:30:22 +00:00
Ed Schouten 637a6862d6 Also enable the default rune table on CloudABI.
CloudABI does not expose a table on its own.

llvm-svn: 232050
2015-03-12 15:48:06 +00:00
Ed Schouten 97fdea618e Add option to disable access to the global filesystem namespace.
Systems like FreeBSD's Capsicum and Nuxi CloudABI apply the concept of
capability-based security on the way processes can interact with the
filesystem API. It is no longer possible to interact with the VFS
through calls like open(), unlink(), rename(), etc. Instead, processes
are only allowed to interact with files and directories to which they
have been granted access. The *at() functions can be used for this
purpose.

This change adds a new config switch called
_LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE. If set, all functionality
that requires the global filesystem namespace will be disabled. More
concretely:

- fstream's open() function will be removed.
- cstdio will no longer pull in fopen(), rename(), etc.
- The test suite's get_temp_file_name() will be removed. This will cause
  all tests that use the global filesystem namespace to break, but will
  at least make all the other tests run (as get_temp_file_name will not
  build anyway).

It is important to mention that this change will make fstream rather
useless on those systems for now. Still, I'd rather not have fstream
disabled entirely, as it is of course possible to come up with an
extension for fstream that would allow access to local filesystem
namespaces (e.g., by adding an openat() member function).

Differential revision:	http://reviews.llvm.org/D8194
Reviewed by:		jroelofs (thanks!)

llvm-svn: 232049
2015-03-12 15:44:39 +00:00
Ed Schouten 12e0126596 Disable cat*() on CloudABI. Also make tiny cleanups.
On a new platform that I am working on
(https://github.com/NuxiNL/cloudlibc) I am not implementing the
cat{open,close,gets}() API, just like Android, Newlib, etc.

Instead of adding yet another operating system name to the #ifs,
introduce _LIBCPP_HAS_CATOPEN in include/__config. Also adjust the code
to only pull in nl_types.h when _LIBCPP_HAS_CATOPEN is set. We only
needed this header for the cat*() API.

Differential Revision:	http://reviews.llvm.org/D8163
Reviewed by:	marshall

llvm-svn: 231937
2015-03-11 16:39:36 +00:00
Dan Albert 900086de88 Move Android to the builtin rune table.
llvm-svn: 231897
2015-03-11 00:51:06 +00:00
Ed Schouten 510b6ab07c Enable _LIBCPP_LOCALE__L_EXTENSIONS on CloudABI.
CloudABI provides the _l() functions that are part of POSIX.1-2008, but
also the extensions that are available on systems like OS X and *BSD
(scanf_l, printf_l, etc).

llvm-svn: 231777
2015-03-10 09:26:38 +00:00
Ed Schouten 17f5dbef9b Add support for arc4random() to random_device.
Nuxi CloudABI (https://github.com/NuxiNL/cloudlibc) does not allow
processes to access the global filesystem namespace. This breaks
random_device, as it attempts to use /dev/{u,}random. This change adds
support for arc4random(), which is present on CloudABI.

In my opinion it would also make sense to use arc4random() on other
operating systems, such as *BSD and Mac OS X, but I'd rather leave that
to the maintainers of the respective platforms. Switching to
arc4random() does change the ABI.

This change also attempts to make some cleanups to the code. It adds a
single #define for every random interface, instead of testing against
operating systems explicitly.

As discussed, also validate the token argument to be equal to
"/dev/urandom" on all systems that only provide pseudo-random numbers.
This should cause little to no breakage, as "/dev/urandom" is also the
default argument value.

Reviewed by: jfb
Differential Revision: http://reviews.llvm.org/D8134

llvm-svn: 231764
2015-03-10 07:46:06 +00:00
Dimitry Andric b1e78df0fa Fix unused private field warning in stdexcept after r207695.
Add a new _LIBCPP_UNUSED define in __config, which can be used to
indicate explicitly unused items, and apply it to the __imp__ field of
__libcpp_refstring.

Somebody who knows about Microsoft C++ and IBM C++ should fill in the
unused attribute syntax appropriate for those compilers, if there is
any.

Differential Revision: http://reviews.llvm.org/D6836

llvm-svn: 228281
2015-02-05 07:40:48 +00:00
Dan Albert a76dfbd428 [libcxx] Set _LIBCPP_ELAST for mingw.
Reviewers: K-ballo, mclow.lists, EricWF

Reviewed By: EricWF

Subscribers: jfb, jroelofs, majnemer, cfe-commits

Differential Revision: http://reviews.llvm.org/D6558

llvm-svn: 225273
2015-01-06 17:34:51 +00:00
Eric Fiselier 2050bedf03 Improve error message when _LIBCPP_HAS_NO_MONOTONIC_CLOCK is used improperly
llvm-svn: 223590
2014-12-06 20:09:11 +00:00
JF Bastien 57148cbcbd libc++: add NaCl and PNaCl support for std::random_device
Summary:
The NaCl sandbox doesn't allow opening files under /dev, but it offers an API which provides the same capabilities. This is the same random device emulation that nacl_io performs for POSIX support, but nacl_io is an optional library so libc++ can't assume that device emulation will be performed. Note that NaCl only supports /dev/urandom, not /dev/random.

This patch also cleans up some of the preprocessor #endif, and fixes the test for Win32 (it accepts any token, and would therefore never throw regardless of the token provided).

Test Plan: ninja check-libcxx

Reviewers: dschuff, mclow.lists, danalbert

Subscribers: jfb, cfe-commits

Differential Revision: http://reviews.llvm.org/D6442

llvm-svn: 223068
2014-12-01 19:19:55 +00:00
Eric Fiselier 53deb607d9 Fixes to get libc++ building on sun solaris. Patch from C Bergstrom.
llvm-svn: 222794
2014-11-25 21:57:41 +00:00
Eric Fiselier b494e5d198 [libcxx] use clang's __char16_t and __char32_t definitions on Linux in C++03 mode.
Summary: This fixes ODR violations in C++03 mode in test/localization/locale.stdcvt. The special case for linux was introduced in 2010 before clang always defined __char16_t and __char32_t.

Reviewers: mclow.lists, danalbert, jroelofs, EricWF

Reviewed By: EricWF

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D5930

llvm-svn: 220716
2014-10-27 20:29:05 +00:00
Viktor Kutuzov d3b10d9daf Define ELAST in libcxx's config header on FreeBSD
Differential Revision: http://reviews.llvm.org/D5165

llvm-svn: 217146
2014-09-04 13:25:46 +00:00
Jonathan Roelofs 3bb7b558df Detection for _LIBCPP_HAS_NO_MONOTONIC_CLOCK caused several more build breakages
Remove it for now. This flag can be set in build scripts instead.

llvm-svn: 217061
2014-09-03 18:48:28 +00:00
Alexey Volkov e46ca71f0b Allow libc++ to be built with GCC 5.0 compiler
Differential Revision: http://reviews.llvm.org/D5169

llvm-svn: 217038
2014-09-03 14:30:39 +00:00
Jonathan Roelofs 112237b476 Fix yet another aspect of the build breakage caused by r216949
llvm-svn: 217001
2014-09-03 00:29:02 +00:00
Jonathan Roelofs bb8fd4ccdb Fix build breakage introduced in r216949
The bug shows up on systems that `#define _POSIX_CLOCK_MONOTONIC 0` to indicate
that users of CLOCK_MONOTONIC must check sysconf at runtime.

See: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html
llvm-svn: 216997
2014-09-02 23:49:15 +00:00
Jonathan Roelofs 6ca513c913 Silence _LIBCPP_ELAST porting warning on __APPLE__
This fixes a warning accidentally introduced in r216943.

llvm-svn: 216977
2014-09-02 22:09:50 +00:00
Jonathan Roelofs f4bc679cad Don't #define _LIBCPP_HAS_NO_MONOTONIC_CLOCK on __APPLE__
This fixes PR20839, which was a bug in r216949.

llvm-svn: 216975
2014-09-02 21:56:01 +00:00
Jonathan Roelofs c59e585126 Partially address a FIXME in steady_clock::now()
http://reviews.llvm.org/D4045

llvm-svn: 216949
2014-09-02 21:14:38 +00:00
Jonathan Roelofs a409d59cf5 Newlib names ELAST differently than linux
llvm-svn: 216943
2014-09-02 20:34:23 +00:00
Justin Bogner d2308ea5fd Revert "Turn off extern templates for most uses."
Turning off explicit template instantiation leads to a pretty
significant build time and code size cost. We're better off dealing
with ABI incompatibility issues that come up in a less heavy handed
way.

This reverts commit r189610.

llvm-svn: 215740
2014-08-15 17:58:56 +00:00
Eric Fiselier 371aac1adb Change _LIBCXX_CONSTEXPR_AFTER_CXX11 to check for c++14 constexpr rules
llvm-svn: 213225
2014-07-17 05:16:18 +00:00
Marshall Clow b38f8f07c5 Add support for BIONIC C library (Android). Patch from Dan Albert
llvm-svn: 212724
2014-07-10 15:20:28 +00:00
Marshall Clow 157a8f91bd Patch from Albert J. Wong to make type_traits take advantage of gcc intrinsics in 4.7 and later. No functionality change when using clang.
llvm-svn: 211755
2014-06-26 01:07:56 +00:00
Marshall Clow c369914758 Since we now have a value for __cplusplus for c++14, teach libc++ about it
llvm-svn: 210380
2014-06-06 22:31:09 +00:00
Richard Smith ff0aff3caf Use __builtin_operator_new/__builtin_operator_delete when available. This
allows allocations and deallocations to be optimized out.

llvm-svn: 210211
2014-06-04 19:54:15 +00:00
Nico Weber 1d1b46cdf7 Make locales (and transitively, std::endl) work reliably with gcc.
libc++ currently relies on undefined initialization order of global
initializers when using gcc:

1. __start_std_streams in iostream.cpp calls locale:🆔:_init, which assigns
   an id to each locale::facet in an initializer

2. Every facet has a static locale::id id, whose constructor sets the facet's
   id to 0

If 2 runs after 1, it clobbers the facet's assigned consecutive id, causing
exceptions to be thrown when e.g. running code like "cout << endl".

To fix this, let _LIBCPP_CONSTEXPR evaluate to "constexpr" instead of nothing
with gcc.  locale::id's constructor is marked _LIBCPP_CONSTEXPR, which ensures
that it won't get an initializer that could potentially run after the
iostream.cpp initializer. (This remains broken when building with msvc.)

Also switch constexpr-specific code in bitset to use __SIZEOF_SIZE_T__ instead
of __SIZE_WIDTH__, because gcc doesn't define the latter.

Pair-programmed/debugged with Dana Jansens.

llvm-svn: 210188
2014-06-04 15:46:56 +00:00
Marshall Clow 5c520bd985 Add Address Sanitizer support to std::vector
llvm-svn: 208319
2014-05-08 14:14:06 +00:00
Marshall Clow 91c71ddd8d Define a new macro in libc++ named '_LIBCPP_HAS_NO_ASAN'. When this is defined,
libc++ will not call address_sanitizer to detect addressing errors in the
standard library containers. This is a negative macro to enable users to
disable the libc++ checks even if they are compiling with address sanitizer
enabled by defining this macro.

At the present time, there is no code in libc++ that looks at this macro.
That will come soon. This is just infrastructure.

llvm-svn: 206184
2014-04-14 15:44:57 +00:00
Tim Northover 4b9a505a5e Use defined(__APPLE__) rather than __APPLE__
llvm-svn: 205150
2014-03-30 14:59:12 +00:00
Tim Northover 0090e657cb ARM64: compare RTTI names as strings
ARM64 generates RTTI with hidden visibility, which means that typeinfo
must be compared char-by-char since it's not guaranteed to be uniqued
across the whole program.

llvm-svn: 205139
2014-03-30 11:34:26 +00:00
Tim Northover c3a57e91ef ARM64: use the alternate string layout on Apple platforms.
llvm-svn: 205138
2014-03-30 11:34:22 +00:00
Stephan Tolksdorf e180ecab2c [libc++] Teach is_integral, is_[un]signed and make_[un]signed about __[u]int128_t
This commit also adds tests for std::numeric_limits<__[u]int128_t>.

Reviewed in http://llvm-reviews.chandlerc.com/D2917

llvm-svn: 204849
2014-03-26 19:45:52 +00:00
Marshall Clow 31be78b27d Fix historical #ifdef. Use __cplusplus instead of __GXX_EXPERIMENTAL_CXX0X__ when compiling with clang. No functionality change. Noteto self: It is important to run the regression tests on the copy of the code that you've changed.
llvm-svn: 201938
2014-02-22 15:13:48 +00:00
Juergen Ributzka 88ec12cd76 Revert "Fix historical #ifdef. Use __cplusplus instead of __GXX_EXPERIMENTAL_CXX0X__ when compiling with clang. No functionality change."
This reverts commit r201864, because it breaks our build bots.

llvm-svn: 201892
2014-02-21 21:06:36 +00:00
Marshall Clow 0e23e04f9a Fix historical #ifdef. Use __cplusplus instead of __GXX_EXPERIMENTAL_CXX0X__ when compiling with clang. No functionality change.
llvm-svn: 201864
2014-02-21 18:07:52 +00:00
Yaron Keren 3ef24c4f9a This solves warning C4005: '_NOEXCEPT' : macro redefinition when compiling
with Visual C++ 2013 by making libcxx definition text-identical to yvals.h.

Persumably this definition is for older Visual C++ versions. 
In such cases it will still be defined so no functionality change.

Other platforms should not be affected as this is inside
#elif defined(_LIBCPP_MSVC)

Patch by G M!

llvm-svn: 201328
2014-02-13 14:02:28 +00:00
Marshall Clow a889636aa0 Removed extra trailing underscore in #ifdef (__GNUC___ --> __GNUC__ )
llvm-svn: 198618
2014-01-06 15:23:02 +00:00
Marshall Clow d41295da72 Patch by Howard. First part of fix for PR18218; add type traits needed to do the right thing. Fix the problems in PR18218 for isnan and pow - they also need to be applied to the other functions in <cmath>. Also, a drive-by fix for the test - now actually calls test_abs()
llvm-svn: 198431
2014-01-03 18:21:14 +00:00
Yaron Keren 21a697b8b1 Empty line between two unrelated #ifdefs.
llvm-svn: 197810
2013-12-20 13:19:45 +00:00
Logan Chien ca83921ddc GCC does not support strong enum in pre-C++0x mode.
GCC does not support strong enum if -std=c++0x is not used.
Without the strong enum, we will see following error:

  In file included from libcxx/include/ostream:131:0,
                   from libcxx/include/sstream:174,
                   from libcxx/include/complex:247,
                   from cpp03-headers.cpp:11:
  libcxx/include/ios:419:68: error: 'io_errc' is not a class or namespace
  libcxx/include/ios:420:66: error: 'io_errc' is not a class or namespace

To workaround this issue, this commit will define
_LIBCPP_HAS_NO_STRONG_ENUMS when we are compiling with
g++ without c++0x.

llvm-svn: 197313
2013-12-14 06:44:09 +00:00
Howard Hinnant 395485efc0 Give all members of exception types default visibility. Lack of this is causing some illegal code relocations rare and hard to reproduce cases.
llvm-svn: 196411
2013-12-04 21:03:23 +00:00
Howard Hinnant 6ef2bb02f5 Remove _LIBCPP_TRIVIAL_PAIR_COPY_CTOR=0 for __APPLE__, no longer needed.
llvm-svn: 195796
2013-11-27 00:53:02 +00:00
Yaron Keren e050d66e12 Compiling libcxx with gcc 4.6.4 (MingW) produces these errors:
type_traits:3280:31: error: expected primary-expression before 'decltype'
 type_traits:3280:29: error: expected ';' at end of member declaration

 memory:2415:49: error: function 'std::__1::default_delete<_Tp>::default_delete()'
 defaulted on its first declaration must not have an exception-specification

 memory:2435:49: error: function 'std::__1::default_delete<_Tp []>::default_delete()'
 defaulted on its first declaration must not have an exception-specification

The attached patch defines _LIBCPP_HAS_NO_ADVANCED_SFINAE and 
_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS for gcc version < 4.7, making
the library compile with gcc 4.6.4.

llvm-svn: 195431
2013-11-22 09:22:12 +00:00
Marshall Clow 028875aa7c Patch by Xing Xue to improve libc++ support for AIX
llvm-svn: 195144
2013-11-19 19:16:03 +00:00
Howard Hinnant f9fd0d6d11 This is a followup to r194536, which changed the pair copy constructor to be
trivial in C++03, thus making it trivial in both C++03 and C++11.

This patch allows one to opt-in/out of this decision with a macro.  You can
choose to have the pair copy constructor always be trivial, or always be
non-trivial.  The flag controlling this is now _LIBCPP_TRIVIAL_PAIR_COPY_CTOR.

The client can define this flag to 1, and the pair copy constructor will be
trivial (when possible of course), or to 0, and the pair copy constructor will
be nontrivial.

Default settings for this flag are set in <__config> (as usual).  With this
commit the default is _LIBCPP_TRIVIAL_PAIR_COPY_CTOR=1 for all platforms
except __APPLE__, which defaults to _LIBCPP_TRIVIAL_PAIR_COPY_CTOR=0.

llvm-svn: 194742
2013-11-14 22:52:25 +00:00
Howard Hinnant ccad8c32e0 This fixes a very subtle ABI problem concerning the copy constructor of
pair, and a couple of pair-like implementation detail types.  The
C++98/03 and 11 standards all specify that the copy constructor of
pair<int, int> is trivial. However as libc++ tracked the draft C++11
standard over the years, this copy constructor became non-trivial, and
then just recently was corrected back to trivial for C++11.

Unfortunately (for libc++1) the Itanium ABI specifies different calling
conventions for trivial and non-trivial copy constructors.  Therefore
currently the C++03 libc++ copy constructor for pair<int, int> is ABI
incompatible with the C++11 libc++ copy constructor for pair<int, int>.
This is Bad(tm).   This patch corrects the situation by making this copy
constructor trivial in C++03 mode as well.

Just in case it is needed for an incomplete C++11 compiler, libc++
retains the ability to support pair with rvalue references, but without
defaulted special members.  However the pair needs non-trivial special
members to implement this special case, (as it did when clang was in
this place a couple of years ago).

During this work a bug was also found and fixed in
is_trivially_constructible.

And there is a minor drive-by fix in <__config> regarding
__type_visibility__.

A test is updated to ensure that the copy constructor of pair<int, int>
is trivial in both C++03 and C++11.  This test will necessarily fail for
a compiler that implements rvalue references but not defaulted special
members.

llvm-svn: 194536
2013-11-13 00:39:22 +00:00