summaryrefslogtreecommitdiff
path: root/libstdc++-v3/libsupc++
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-28 09:53:39 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-28 09:53:39 +0000
commitac64c2700c1327e13d6ba142b1a7bba466a4e280 (patch)
tree928d9bf3a2c8f257cd9c7177c6402c44b98d91a6 /libstdc++-v3/libsupc++
parentb47145cf69428c1c4eb9123e4070904c6a74182a (diff)
downloadgcc-ac64c2700c1327e13d6ba142b1a7bba466a4e280.tar.gz
2015-01-28 Richard Biener <rguenther@suse.de>
PR libstdc++/64798 * libsupc++/eh_alloc.cc (struct allocated_entry): Align data member. (pool::allocate): Adjust allocation size and alignment to that change. (pool::free): Adjust pointer offsetting. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220201 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/libsupc++')
-rw-r--r--libstdc++-v3/libsupc++/eh_alloc.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/libstdc++-v3/libsupc++/eh_alloc.cc b/libstdc++-v3/libsupc++/eh_alloc.cc
index c77f53fdf02..7ddd2b746d8 100644
--- a/libstdc++-v3/libsupc++/eh_alloc.cc
+++ b/libstdc++-v3/libsupc++/eh_alloc.cc
@@ -94,7 +94,7 @@ namespace
};
struct allocated_entry {
std::size_t size;
- char data[];
+ char data[] __attribute__((aligned));
};
// A single mutex controlling emergency allocations.
@@ -133,17 +133,18 @@ namespace
void *pool::allocate (std::size_t size)
{
__gnu_cxx::__scoped_lock sentry(emergency_mutex);
- // We need an additional size_t member.
- size += sizeof (std::size_t);
+ // We need an additional size_t member plus the padding to
+ // ensure proper alignment of data.
+ size += offsetof (allocated_entry, data);
// And we need to at least hand out objects of the size of
// a freelist entry.
if (size < sizeof (free_entry))
size = sizeof (free_entry);
- // And we need to align objects we hand out to the required
- // alignment of a freelist entry (this really aligns the
+ // And we need to align objects we hand out to the maximum
+ // alignment required on the target (this really aligns the
// tail which will become a new freelist entry).
- size = ((size + __alignof__(free_entry) - 1)
- & ~(__alignof__(free_entry) - 1));
+ size = ((size + __alignof__ (allocated_entry::data) - 1)
+ & ~(__alignof__ (allocated_entry::data) - 1));
// Search for an entry of proper size on the freelist.
free_entry **e;
for (e = &first_free_entry;
@@ -185,7 +186,7 @@ namespace
{
__gnu_cxx::__scoped_lock sentry(emergency_mutex);
allocated_entry *e = reinterpret_cast <allocated_entry *>
- (reinterpret_cast <char *> (data) - sizeof (std::size_t));
+ (reinterpret_cast <char *> (data) - offsetof (allocated_entry, data));
std::size_t sz = e->size;
if (!first_free_entry)
{