Re: [RFC PATCH v1 5/6] tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()`

From: Willy Tarreau
Date: Sun Mar 20 2022 - 12:47:12 EST


On Sun, Mar 20, 2022 at 11:36:55PM +0700, Ammar Faizi wrote:
> And this is what GCC doc says about __attribute__((__aligned__)):
> """
> The aligned attribute specifies a minimum alignment for the variable
> or structure field, measured in bytes. When specified, alignment must
> be an integer constant power of 2. Specifying no alignment argument
> implies the maximum alignment for the target, which is often, but by
> no means always, 8 or 16 bytes.
> """
>
> Link: https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes

OK then that's fine, thank you. I thought it would force the alignment
to the type itself.

> Simple experiment on Linux x86-64...

That's even easier checked like this:

$ cat > c.c <<EOF
struct blah {
char a;
char b __attribute__((__aligned__));
} blah;
EOF
$ gcc -g -c c.c
$ pahole c.o
struct blah {
char a; /* 0 1 */

/* XXX 15 bytes hole, try to pack */

char b __attribute__((__aligned__(16))); /* 16 1 */

/* size: 32, cachelines: 1, members: 2 */
/* sum members: 2, holes: 1, sum holes: 15 */
/* padding: 15 */
/* forced alignments: 1, forced holes: 1, sum forced holes: 15 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(16)));

Thank you!
Willy