summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lloyd Pique <lpique@google.com> 2018-08-31 17:34:40 -0700
committer Lloyd Pique <lpique@google.com> 2018-09-05 16:42:58 -0700
commit3b74578c53647071ed22561f0f613b69d99e224c (patch)
tree19ed28f62673bcf1bfd5da49dcaa2c62727ed2de
parentdc0aaf9c3c26c8e0e5ac03caf1e4e90b0a18bd0e (diff)
Build libui and libgui with -std=c++1z
This works around an issue reported with address sanitizer involving std::shared_ptr<FenceTime> instances created by pre-C++17 compiled code, and destroyed by C++17 compiled SurfaceFlinger. The address sanitizer was complaining that there was a new/delete alignment mismatch, where the instances were allocated with default alignment, and destroyed with an 8-byte alignment requirement. Starting with C++17, new and delete now have versions that take an std::align_val_t argument that indicates the alignment of the allocation. The address sanitizer is verifying that the call to new matches the call to delete, and reports an error if it does not. The C++17 standard says that the compiler should behave in a way that is backwards compatible. In this case, FenceTime declares class-specific new and delete functions, and normally those would be used. Except that the current libc++ version of std::shared_ptr does not! It instead uses its own calls to allocate memory, and does a placement-new to actually create the FenceTime instance it shares. Unfortunately the version of new and delete called depends on whether it is compiled for C++17 or not. To make the address sanitizer happy, we can just build libui and libgui with -std=c++1z, which as a bonus allows the class-specific new to be removed. (Reproducing the failure requires a not-yet submitted CL which adds test coverage for composition calls, and another change to enable address sanitizer on the unit test) Bug: None Test: atest libsurfaceflinger_unittest Change-Id: I2321bbdbf64a8a068ba2b5ed73013ddd2fa6c32e
-rw-r--r--libs/gui/Android.bp7
-rw-r--r--libs/ui/Android.bp1
-rw-r--r--libs/ui/FenceTime.cpp12
-rw-r--r--libs/ui/include/ui/FenceTime.h5
4 files changed, 5 insertions, 20 deletions
diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp
index ef3e592c09..98264ac35f 100644
--- a/libs/gui/Android.bp
+++ b/libs/gui/Android.bp
@@ -31,6 +31,7 @@ cc_library_shared {
"-Werror",
],
cppflags: [
+ "-std=c++1z",
"-Weverything",
// The static constructors and destructors in this library have not been noted to
@@ -58,7 +59,7 @@ cc_library_shared {
"-Wno-weak-vtables",
// Allow four-character integer literals
- "-Wno-four-char-constants",
+ "-Wno-four-char-constants",
// Allow documentation warnings
"-Wno-documentation",
@@ -116,7 +117,7 @@ cc_library_shared {
"SyncFeatures.cpp",
"view/Surface.cpp",
"bufferqueue/1.0/B2HProducerListener.cpp",
- "bufferqueue/1.0/H2BGraphicBufferProducer.cpp"
+ "bufferqueue/1.0/H2BGraphicBufferProducer.cpp",
],
shared_libs: [
@@ -124,7 +125,7 @@ cc_library_shared {
"libsync",
"libbinder",
"libbufferhub",
- "libbufferhubqueue", // TODO(b/70046255): Remove this once BufferHub is integrated into libgui.
+ "libbufferhubqueue", // TODO(b/70046255): Remove this once BufferHub is integrated into libgui.
"libpdx_default_transport",
"libcutils",
"libEGL",
diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp
index e3ef2a9e1d..160505088f 100644
--- a/libs/ui/Android.bp
+++ b/libs/ui/Android.bp
@@ -26,6 +26,7 @@ cc_library_shared {
"-Werror",
],
cppflags: [
+ "-std=c++1z",
"-Weverything",
// The static constructors and destructors in this library have not been noted to
diff --git a/libs/ui/FenceTime.cpp b/libs/ui/FenceTime.cpp
index 14147663de..340231d352 100644
--- a/libs/ui/FenceTime.cpp
+++ b/libs/ui/FenceTime.cpp
@@ -33,18 +33,6 @@ namespace android {
const auto FenceTime::NO_FENCE = std::make_shared<FenceTime>(Fence::NO_FENCE);
-void* FenceTime::operator new(size_t byteCount) noexcept {
- void *p = nullptr;
- if (posix_memalign(&p, alignof(FenceTime), byteCount)) {
- return nullptr;
- }
- return p;
-}
-
-void FenceTime::operator delete(void *p) {
- free(p);
-}
-
FenceTime::FenceTime(const sp<Fence>& fence)
: mState(((fence.get() != nullptr) && fence->isValid()) ?
State::VALID : State::INVALID),
diff --git a/libs/ui/include/ui/FenceTime.h b/libs/ui/include/ui/FenceTime.h
index 871fcf2dfe..a5a1fcbde7 100644
--- a/libs/ui/include/ui/FenceTime.h
+++ b/libs/ui/include/ui/FenceTime.h
@@ -113,11 +113,6 @@ public:
void signalForTest(nsecs_t signalTime);
- // Override new and delete since this needs 8-byte alignment, which
- // is not guaranteed on x86.
- static void* operator new(size_t nbytes) noexcept;
- static void operator delete(void *p);
-
private:
// For tests only. If forceValidForTest is true, then getSignalTime will
// never return SIGNAL_TIME_INVALID and isValid will always return true.