This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
obstack: first object of each chunk not aligned
- To: libc-alpha at sourceware dot cygnus dot com
- Subject: obstack: first object of each chunk not aligned
- From: duret_g at epita dot fr
- Date: Mon, 23 Oct 2000 15:29:44 +0200
>Submitter-Id: net
>Originator: Alexandre Duret-Lutz
>Organization:
Alexandre Duret-Lutz
>
>Confidential: no
>Synopsis: the first object of each obstack chunk can be unaligned
>Severity: non-critical
>Priority: low
>Category: libc
>Class: sw-bug
>Release: libc-2.1.95
>Environment:
Host type: i386-pc-linux-gnu
System: Linux phobos 2.4.0-test7 #2 Sat Sep 9 14:25:27 CEST 2000 i586 unknown
Architecture: i586
Addons: linuxthreads
Build CC: gcc
Compiler version: 2.95.2 20000220 (Debian GNU/Linux)
Kernel headers: UTS_RELEASE
Symbol versioning: yes
Build static: yes
Build shared: yes
Build pic-default: no
Build profile: yes
Build omitfp: no
Build bounded: no
Build static-nss: no
Stdio: libio
>Description:
When asking an obstack to return object with a given alignment,
the resulting objects are *not always* correctly aligned. More
precisely, the first object allocated in a chunk can be
unaligned.
Here is an output of the included test (here the first object of
a chunk is sometimes aligned because by chance malloc
return a pointer which will be aligned once the two
chunk-header-values are added):
~/tmp % gcc obstest.c
~/tmp % ./a.out
malloc (4072) => 0x8049998
obstack_alloc (1000) => 0x80499a0
obstack_alloc (1000) => 0x8049da0
obstack_alloc (1000) => 0x804a1a0
malloc (4072) => 0x804a988
obstack_alloc (1000) => 0x804a990 (not aligned)
obstack_alloc (1000) => 0x804ad80
obstack_alloc (1000) => 0x804b180
obstack_alloc (1000) => 0x804b580
malloc (4072) => 0x804b978
obstack_alloc (1000) => 0x804b980
obstack_alloc (1000) => 0x804bd80
obstack_alloc (1000) => 0x804c180
malloc (4072) => 0x804c968
obstack_alloc (1000) => 0x804c970 (not aligned)
obstack_alloc (1000) => 0x804cd60
obstack_alloc (1000) => 0x804d160
obstack_alloc (1000) => 0x804d560
malloc (4072) => 0x804d958
obstack_alloc (1000) => 0x804d960
free (0x804d958)
free (0x804c968)
free (0x804b978)
free (0x804a988)
free (0x8049998)
>How-To-Repeat:
#include <stdlib.h>
#include <stdio.h>
#include <obstack.h>
#define obstack_chunk_alloc verbose_malloc
#define obstack_chunk_free verbose_free
#define ALIGN_BOUNDARY 32
#define ALIGN_MASK (ALIGN_BOUNDARY - 1)
#define OBJECT_SIZE 1000
void *
verbose_malloc (size_t size)
{
void *buf = malloc (size);
fprintf (stderr, "malloc (%u) => %p\n", size, buf);
return buf;
}
void
verbose_free (void *buf)
{
free (buf);
fprintf (stderr, "free (%p)\n", buf);
}
int main (void)
{
struct obstack obs;
int i;
obstack_init (&obs);
obstack_alignment_mask (&obs) = ALIGN_MASK;
/* finish an empty object to take alignment into account */
obstack_finish (&obs);
/* let's allocate some objects and print their addresses */
for (i = 15; i; --i) {
void *obj = obstack_alloc (&obs, OBJECT_SIZE);
fprintf (stderr, "obstack_alloc (%u) => %p \t%s\n", OBJECT_SIZE, obj,
((int)obj & ALIGN_MASK)?"(not aligned)":"");
}
/* clean up */
obstack_free (&obs, 0);
return 0;
}
>Fix:
My understanding of the obstack source is that an
alignment test is missing in `_obstack_newchunk'.