This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 552

Summary: GCC address sanitizer breaks 16-byte alignment of glibc malloc
Product: Eigen Reporter: Takaki Makino <t-eigen-bugzilla>
Component: Core - generalAssignee: Nobody <eigen.nobody>
Status: RESOLVED FIXED    
Severity: Unknown CC: gael.guennebaud, jacob.benoit.1
Priority: Normal    
Version: 3.2   
Hardware: x86 - 64-bit   
OS: Linux   
Whiteboard:
Bug Depends on:    
Bug Blocks: 387    

Description Takaki Makino 2013-02-08 16:40:05 UTC
Currently Eigen assumes glibc malloc() returns 16-byte aligned address for all LP64 systems.  Now gcc 4.8 introduces address sanitizer (-fsanitize=address), which is a very powerful tool that effectively detect memory-related bugs.  Unfortunately, when this switch is turned on, the pointer returned by malloc() no longer aligned at 16-byte alignment, and breaks Eigen assumption.
For a quick fix, I propose the following patch:


--- Eigen/src/Core/util/Memory.h        2013-02-09 00:20:40.000000000 +0900
+++ Eigen/src/Core/util/Memory.h.new    2013-02-09 00:20:51.000000000 +0900
@@ -27,7 +27,7 @@
 // page 114, "[The] LP64 model [...] is used by all 64-bit UNIX ports" so it's indeed
 // quite safe, at least within the context of glibc, to equate 64-bit with LP64.
 #if defined(__GLIBC__) && ((__GLIBC__>=2 && __GLIBC_MINOR__ >= 8) || __GLIBC__>2) \
- && defined(__LP64__)
+ && defined(__LP64__) && ! defined( __SANITIZE_ADDRESS__ )
   #define EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED 1
 #else
   #define EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED 0
Comment 1 Benoit Jacob 2013-02-08 18:20:53 UTC
Good catch! In fact, I think that we should just remove EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED altogether: it doesn't buy us much as we're able to use aligned malloc functions just as well, and it's likely to cause other problems with other kinds of malloc instrumentation.
Comment 2 Gael Guennebaud 2013-02-25 19:19:47 UTC
It still looks better to simply rely on malloc when possible, so:

https://bitbucket.org/eigen/eigen/commits/fade198d789b/
changeset:   fade198d789b
user:        ggael
date:        2013-02-25 19:17:13
summary:     Fix bug 552: disable EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED when compiling with -fsanitize=address, and allow users to manually tell whether EIGEN_MALLOC_ALREADY_ALIGNED.
Comment 3 Nobody 2019-12-04 12:03:53 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/552.