Summary: | alpha does not deal with non-aligned returns from malloc() when doing byte wise access | ||
---|---|---|---|
Product: | gcc | Reporter: | Martin Husemann <martin> |
Component: | target | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED INVALID | ||
Severity: | normal | CC: | skrll |
Priority: | P3 | ||
Version: | 4.8.3 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | ||
Attachments: | generated assembler code (cc -O2 -S test.c) |
Description
Martin Husemann
2014-01-27 13:32:34 UTC
The response to C90 DR#075 said memory from malloc must be suitably aligned for all types, not just those fitting in space of the given size, and nothing relevant has changed in the malloc specification in C99/C11 so it's reasonable to assume this still applies (for standard types, that is, not types using C11 _Alignof). http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_075.html Is the alignment expected from malloc() configurable in gcc and/or different from the standard stack alignment? A small test program along the lines of if ((uintptr_t)malloc(1) & mask) printf("yes\n") else printf("no\n"); and checking what gcc -O2 optimizes away for different masks seems to show that on alpha & 7 is optimized, while & 15 is not. This sounds good for alpha. However, I get the same results for amd64 - where I would have expected the required alignement to be 16 byte. Is this a bug in our amd64 target configuration, or am I misundertanding something? (In reply to Martin Husemann from comment #2) > Is the alignment expected from malloc() configurable in gcc and/or different > from the standard stack alignment? Yes MALLOC_ABI_ALIGNMENT: @defmac MALLOC_ABI_ALIGNMENT Alignment, in bits, a C conformant malloc implementation has to provide. If not defined, the default value is @code{BITS_PER_WORD}. @end defmac > > A small test program along the lines of > > if ((uintptr_t)malloc(1) & mask) printf("yes\n") else printf("no\n"); > > and checking what gcc -O2 optimizes away for different masks seems to show > that on alpha & 7 is optimized, while & 15 is not. This sounds good for > alpha. > > However, I get the same results for amd64 - where I would have expected the > required alignement to be 16 byte. Is this a bug in our amd64 target > configuration, or am I misundertanding something? misunderstanding the default and most likely the history of this macro. The original issue is invalid (bug in netbsd). |