Commit 8aa33fad by Richard Biener Committed by Richard Biener

re PR libstdc++/64798 (g++.old-deja/g++.eh/badalloc1.C FAILs)

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.

From-SVN: r220201
parent de5bcff3
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.
2015-01-27 Jonathan Wakely <jwakely@redhat.com> 2015-01-27 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/64368 PR libstdc++/64368
......
...@@ -94,7 +94,7 @@ namespace ...@@ -94,7 +94,7 @@ namespace
}; };
struct allocated_entry { struct allocated_entry {
std::size_t size; std::size_t size;
char data[]; char data[] __attribute__((aligned));
}; };
// A single mutex controlling emergency allocations. // A single mutex controlling emergency allocations.
...@@ -133,17 +133,18 @@ namespace ...@@ -133,17 +133,18 @@ namespace
void *pool::allocate (std::size_t size) void *pool::allocate (std::size_t size)
{ {
__gnu_cxx::__scoped_lock sentry(emergency_mutex); __gnu_cxx::__scoped_lock sentry(emergency_mutex);
// We need an additional size_t member. // We need an additional size_t member plus the padding to
size += sizeof (std::size_t); // ensure proper alignment of data.
size += offsetof (allocated_entry, data);
// And we need to at least hand out objects of the size of // And we need to at least hand out objects of the size of
// a freelist entry. // a freelist entry.
if (size < sizeof (free_entry)) if (size < sizeof (free_entry))
size = sizeof (free_entry); size = sizeof (free_entry);
// And we need to align objects we hand out to the required // And we need to align objects we hand out to the maximum
// alignment of a freelist entry (this really aligns the // alignment required on the target (this really aligns the
// tail which will become a new freelist entry). // tail which will become a new freelist entry).
size = ((size + __alignof__(free_entry) - 1) size = ((size + __alignof__ (allocated_entry::data) - 1)
& ~(__alignof__(free_entry) - 1)); & ~(__alignof__ (allocated_entry::data) - 1));
// Search for an entry of proper size on the freelist. // Search for an entry of proper size on the freelist.
free_entry **e; free_entry **e;
for (e = &first_free_entry; for (e = &first_free_entry;
...@@ -185,7 +186,7 @@ namespace ...@@ -185,7 +186,7 @@ namespace
{ {
__gnu_cxx::__scoped_lock sentry(emergency_mutex); __gnu_cxx::__scoped_lock sentry(emergency_mutex);
allocated_entry *e = reinterpret_cast <allocated_entry *> 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; std::size_t sz = e->size;
if (!first_free_entry) if (!first_free_entry)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment