diff options
| author | Juergen Werner <juergen@opensourcerouting.org> | 2019-10-01 14:24:20 +0200 | 
|---|---|---|
| committer | Juergen Werner <juergen@opensourcerouting.org> | 2019-10-01 15:23:00 +0200 | 
| commit | 4d8ebeddc56f49aa0b4d7cec506cab14320e1bb4 (patch) | |
| tree | 18fd5db247f7540087ad052727d98c3daaa7e688 /lib/memory.h | |
| parent | 698603ce6d7e04af945b28141b7c77adb70c4caf (diff) | |
lib: Revert usage of asm-code in MTYPE definitions
The asm-code was interpreted inconsistently for different platforms.
In particular for AArch64 this caused UB, if multiple static MTYPEs
where defined in one file. All static MTYPE_* could point to the same
memory location (namely the first defined MTYPE) OR to their respective
(correct) locations depending on the context of their usage.
Signed-off-by: Juergen Werner <juergen@opensourcerouting.org>
Diffstat (limited to 'lib/memory.h')
| -rw-r--r-- | lib/memory.h | 16 | 
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/memory.h b/lib/memory.h index 14cd76f2f5..8de5c4c2bf 100644 --- a/lib/memory.h +++ b/lib/memory.h @@ -101,14 +101,9 @@ struct memgroup {  		*_mg_##mname.ref = _mg_##mname.next;                           \  	} - -/* the array is a trick to make the "MTYPE_FOO" name work as a pointer without - * putting a & in front of it, so we can do "XMALLOC(MTYPE_FOO, ...)" instead - * of "XMALLOC(&MTYPE_FOO, ...)". - */  #define DECLARE_MTYPE(name)                                                    \  	extern struct memtype _mt_##name;                                      \ -	extern struct memtype MTYPE_##name[1];                                 \ +	extern struct memtype *const MTYPE_##name;                             \  	/* end */  #define DEFINE_MTYPE_ATTR(group, mname, attr, desc)                            \ @@ -138,17 +133,14 @@ struct memgroup {  	}                                                                      \  	/* end */ -/* can't quite get gcc to emit the alias correctly, so asm-alias it is :/ */  #define DEFINE_MTYPE(group, name, desc)                                        \  	DEFINE_MTYPE_ATTR(group, name, , desc)                                 \ -	__asm__(".equiv MTYPE_" #name ", _mt_" #name "\n\t"                    \ -		".global MTYPE_" #name "\n");                                  \ +	struct memtype *const MTYPE_##name = &_mt_##name;                      \  	/* end */ -/* and this one's borked on clang, it drops static on aliases :/, so... asm */ +  #define DEFINE_MTYPE_STATIC(group, name, desc)                                 \  	DEFINE_MTYPE_ATTR(group, name, static, desc)                           \ -	extern struct memtype MTYPE_##name[1];                                 \ -	__asm__(".equiv MTYPE_" #name ", _mt_" #name "\n");                    \ +	static struct memtype *const MTYPE_##name = &_mt_##name;               \  	/* end */  DECLARE_MGROUP(LIB)  | 
